maksaska commented on code in PR #311:
URL: https://github.com/apache/ignite-extensions/pull/311#discussion_r2247306071


##########
modules/cdc-ext/src/test/java/org/apache/ignite/cdc/postgres/CdcPostgreSqlReplicationTest.java:
##########
@@ -0,0 +1,699 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.cdc.postgres;
+
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.function.IntConsumer;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+import io.zonky.test.db.postgres.embedded.EmbeddedPostgres;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.QueryEntity;
+import org.apache.ignite.cdc.postgresql.IgniteToPostgreSqlCdcConsumer;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
+
+/** */
+@RunWith(Parameterized.class)
+public class CdcPostgreSqlReplicationTest extends 
CdcPostgreSqlReplicationAbstractTest {
+    /** */
+    private static final int BACKUP = 0;
+
+    /** */
+    private static final String CACHE_MODE = "PARTITIONED";
+
+    /** */
+    @Parameterized.Parameter()
+    public CacheAtomicityMode atomicity;
+
+    /** */
+    @Parameterized.Parameter(1)
+    public boolean createTables;
+
+    /** @return Test parameters. */
+    @Parameterized.Parameters(name = "atomicity={0}, createTables={1}")
+    public static Collection<?> parameters() {
+        List<Object[]> params = new ArrayList<>();
+
+        for (CacheAtomicityMode atomicity : EnumSet.of(ATOMIC, TRANSACTIONAL)) 
{
+            for (boolean createTables : new boolean[] {true, false})
+                params.add(new Object[] {atomicity, createTables});
+        }
+
+        return params;
+    }
+
+    /** */
+    protected IgniteEx src;
+
+    /** */
+    protected EmbeddedPostgres postgres;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        DataRegionConfiguration dataRegionConfiguration = new 
DataRegionConfiguration()
+            .setPersistenceEnabled(true)
+            .setCdcEnabled(true);
+
+        DataStorageConfiguration dataStorageConfiguration = new 
DataStorageConfiguration()
+            .setWalForceArchiveTimeout(5_000)
+            .setDefaultDataRegionConfiguration(dataRegionConfiguration);
+
+        cfg.setDataStorageConfiguration(dataStorageConfiguration);
+        cfg.setConsistentId(igniteInstanceName);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteToPostgreSqlCdcConsumer 
getCdcConsumerConfiguration() {
+        IgniteToPostgreSqlCdcConsumer cdcCfg = 
super.getCdcConsumerConfiguration();
+
+        cdcCfg.setCreateTables(createTables);
+
+        return cdcCfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        cleanPersistenceDir();
+
+        src = startGrid(0);
+
+        src.cluster().state(ClusterState.ACTIVE);
+
+        postgres = EmbeddedPostgres.builder().start();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        cleanPersistenceDir();
+
+        postgres.close();
+    }
+
+    /** */
+    @Test
+    public void testSingleColumnKeyDataReplicationWithPrimaryFirst() throws 
Exception {
+        testSingleColumnKeyDataReplication(false);
+    }
+
+    /** */
+    @Test
+    public void testSingleColumnKeyDataReplicationWithPrimaryLast() throws 
Exception {
+        testSingleColumnKeyDataReplication(true);
+    }
+
+    /** */
+    public void testSingleColumnKeyDataReplication(boolean isPrimaryLast) 
throws Exception {
+        String[] tableFields;
+
+        String insertQry = "INSERT INTO T1 VALUES(?, ?)";
+        String updateQry;
+
+        IntConsumer insert;
+        IntConsumer update;
+
+        if (isPrimaryLast) {
+            tableFields = new String[] {"NAME VARCHAR(20)", "ID BIGINT PRIMARY 
KEY"};
+
+            updateQry = "MERGE INTO T1 (NAME, ID) VALUES (?, ?)";
+
+            insert = id -> executeOnIgnite(src, insertQry, "Name" + id, id);
+            update = id -> executeOnIgnite(src, updateQry, id + "Name", id);
+        }
+        else {
+            tableFields = new String[] {"ID BIGINT PRIMARY KEY", "NAME 
VARCHAR(20)"};
+
+            updateQry = "MERGE INTO T1 (ID, NAME) VALUES (?, ?)";
+
+            insert = id -> executeOnIgnite(src, insertQry, id, "Name" + id);
+            update = id -> executeOnIgnite(src, updateQry, id, id + "Name");
+        }
+
+        createTable("T1", tableFields, null, null, null);
+
+        Supplier<Boolean> checkInsert = () -> checkSingleColumnKeyTable(id -> 
"Name" + id);
+
+        Supplier<Boolean> checkUpdate = () -> checkSingleColumnKeyTable(id -> 
id + "Name");
+
+        testDataReplication("T1", insert, checkInsert, update, checkUpdate);
+    }
+
+    /** */
+    private boolean checkSingleColumnKeyTable(Function<Long, String> idToName) 
{
+        String qry = "SELECT ID, NAME FROM T1";
+
+        try (ResultSet res = selectOnPostgreSql(postgres, qry)) {
+            long cnt = 0;
+
+            long id;
+            String curName;
+
+            while (res.next()) {
+                id = res.getLong("ID");
+                curName = res.getString("NAME");
+
+                if (!idToName.apply(id).equals(curName))

Review Comment:
   Yes, we can. Added



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to