anton-vinogradov commented on code in PR #10393:
URL: https://github.com/apache/ignite/pull/10393#discussion_r1106145648


##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transform/AbstractCacheObjectsTransformationTest.java:
##########
@@ -0,0 +1,435 @@
+/*
+ * 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.internal.processors.cache.transform;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.events.CacheObjectTransformedEvent;
+import org.apache.ignite.events.EventType;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.spi.transform.CacheObjectTransformerAdapter;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ * Leak test.
+ */
+public abstract class AbstractCacheObjectsTransformationTest extends 
GridCommonAbstractTest {
+    /** Cache name. */
+    protected static final String CACHE_NAME = "data";
+
+    /** Nodes count. */
+    protected static final int NODES = 3;
+
+    /** Key. */
+    protected int key;
+
+    /** Event queue. */
+    protected final ConcurrentLinkedDeque<CacheObjectTransformedEvent> 
evtQueue = new ConcurrentLinkedDeque<>();
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setCacheConfiguration(cacheConfiguration());
+        cfg.setIncludeEventTypes(EventType.EVT_CACHE_OBJECT_TRANSFORMED);
+
+        return cfg;
+    }
+
+    /**
+     * Gets cache configuration.
+     *
+     * @return Data cache configuration.
+     */
+    protected CacheConfiguration cacheConfiguration() {
+        CacheConfiguration cfg = defaultCacheConfiguration();
+
+        cfg.setName(CACHE_NAME);
+        cfg.setBackups(NODES);
+        cfg.setReadFromBackup(true);
+        cfg.setWriteSynchronizationMode(FULL_SYNC);
+        cfg.setAffinity(new RendezvousAffinityFunction(false, 1)); // 
Simplifies event calculation.
+
+        return cfg;
+    }
+
+    /**
+     *
+     */
+    protected Ignite prepareCluster() throws Exception {
+        Ignite ignite = startGrids(NODES);
+
+        awaitPartitionMapExchange();
+
+        ignite.events().remoteListen(
+            (uuid, evt) -> {
+                assertTrue(evt instanceof CacheObjectTransformedEvent);
+
+                evtQueue.add((CacheObjectTransformedEvent)evt);
+
+                return true;
+            },
+            null,
+            EventType.EVT_CACHE_OBJECT_TRANSFORMED);
+
+        return ignite;
+    }
+
+    /**
+     *
+     */
+    protected void putAndCheck(Object val, boolean transformableKey, boolean 
transformableVal, boolean reversed) {
+        boolean binarizableVal = !(val instanceof String || val instanceof 
Integer || val instanceof Object[] ||
+            val instanceof int[] || val instanceof Collection);
+
+        boolean binarizableColVal = (val instanceof Object[] && !(val 
instanceof String[] || val instanceof int[])) ||
+            (val instanceof Collection && !(
+                ((Iterable<?>)val).iterator().next() instanceof String ||
+                    ((Iterable<?>)val).iterator().next() instanceof Integer)
+            );
+
+        boolean binaryVal = val instanceof BinaryObject;
+        boolean binaryColVal = val instanceof BinaryObject[] ||
+            (val instanceof Collection && ((Iterable<?>)val).iterator().next() 
instanceof BinaryObject);
+
+        if (binaryVal)
+            assertTrue(binarizableVal);
+
+        if (binaryColVal)
+            assertTrue(binarizableColVal);
+
+        assertFalse(binaryVal && binaryColVal);
+        assertFalse(binarizableVal && binarizableColVal);
+
+        Ignite node = backupNode(0, CACHE_NAME); // Any key, besause of single 
partition.
+
+        IgniteCache<Object, Object> cache = node.getOrCreateCache(CACHE_NAME);
+
+        Object k = reversed ? val : ++key;
+        Object v = reversed ? ++key : val;
+
+        cache.put(k, v);
+
+        checkPut(!reversed && binarizableVal, reversed ? transformableKey : 
transformableVal);
+
+        checkGet(
+            k,
+            v,
+            !reversed && binaryVal,
+            !reversed && binaryColVal,
+            !reversed && binarizableVal,
+            !reversed && binarizableColVal,
+            reversed ? transformableKey : transformableVal);
+    }
+
+    /**
+     *
+     */
+    private void checkPut(
+        boolean binarizableVal,
+        boolean transformableVal) {
+        int transformed = transformableVal ? 1 : 0;
+        int transformCancelled = transformableVal ? 0 : 1;
+        int restored = transformableVal && binarizableVal ? NODES : 0; // 
Binary array is required (e.g. to wait for proper Metadata)
+
+        checkEvents(transformed, transformCancelled, restored, 
transformableVal);
+    }
+
+    /**
+     *
+     */
+    private void checkGet(
+        Object key,
+        Object expVal,
+        boolean binaryExpVal,
+        boolean binaryColExpVal,
+        boolean binarizableVal,
+        boolean binarizableColVal,
+        boolean transformableVal) {
+        for (Ignite node : G.allGrids()) {
+            for (boolean keepBinary : new boolean[] {true, false})
+                getWithCheck(
+                    node,
+                    key,
+                    expVal,
+                    binaryExpVal,
+                    binaryColExpVal,
+                    binarizableVal,
+                    binarizableColVal,
+                    transformableVal,
+                    keepBinary);
+        }
+    }
+
+    /**
+     *
+     */
+    private void getWithCheck(
+        Ignite node,
+        Object key,
+        Object expVal,
+        boolean binaryExpVal,
+        boolean binaryColExpVal,
+        boolean binarizableVal,
+        boolean binarizableColVal,
+        boolean transformableVal,
+        boolean keepBinary) {

Review Comment:
   CMD + SHIFT + L corrects to this form.
   Should we change codestyle scheme a IDE?



-- 
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