You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2015/10/30 11:44:32 UTC
[04/19] ignite git commit: ignite-950-new WIP
http://git-wip-us.apache.org/repos/asf/ignite/blob/35b6d61f/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridIgniteObjectMarshalerAwareTestClass.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridIgniteObjectMarshalerAwareTestClass.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridIgniteObjectMarshalerAwareTestClass.java
new file mode 100644
index 0000000..9fe4242
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridIgniteObjectMarshalerAwareTestClass.java
@@ -0,0 +1,67 @@
+/*
+ * 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.portable.mutabletest;
+
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.igniteobject.IgniteObjectException;
+import org.apache.ignite.igniteobject.IgniteObjectMarshalAware;
+import org.apache.ignite.igniteobject.IgniteObjectRawReader;
+import org.apache.ignite.igniteobject.IgniteObjectRawWriter;
+import org.apache.ignite.igniteobject.IgniteObjectReader;
+import org.apache.ignite.igniteobject.IgniteObjectWriter;
+import org.apache.ignite.testframework.GridTestUtils;
+
+/**
+ *
+ */
+public class GridIgniteObjectMarshalerAwareTestClass implements IgniteObjectMarshalAware {
+ /** */
+ public String s;
+
+ /** */
+ public String sRaw;
+
+ /** {@inheritDoc} */
+ @Override public void writePortable(IgniteObjectWriter writer) throws IgniteObjectException {
+ writer.writeString("s", s);
+
+ IgniteObjectRawWriter raw = writer.rawWriter();
+
+ raw.writeString(sRaw);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(IgniteObjectReader reader) throws IgniteObjectException {
+ s = reader.readString("s");
+
+ IgniteObjectRawReader raw = reader.rawReader();
+
+ sRaw = raw.readString();
+ }
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("FloatingPointEquality")
+ @Override public boolean equals(Object other) {
+ return this == other || GridTestUtils.deepEquals(this, other);
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(GridIgniteObjectMarshalerAwareTestClass.class, this);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/35b6d61f/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.java
deleted file mode 100644
index 3244331..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.portable.mutabletest;
-
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.portable.PortableException;
-import org.apache.ignite.portable.PortableMarshalAware;
-import org.apache.ignite.portable.PortableRawReader;
-import org.apache.ignite.portable.PortableRawWriter;
-import org.apache.ignite.portable.PortableReader;
-import org.apache.ignite.portable.PortableWriter;
-import org.apache.ignite.testframework.GridTestUtils;
-
-/**
- *
- */
-public class GridPortableMarshalerAwareTestClass implements PortableMarshalAware {
- /** */
- public String s;
-
- /** */
- public String sRaw;
-
- /** {@inheritDoc} */
- @Override public void writePortable(PortableWriter writer) throws PortableException {
- writer.writeString("s", s);
-
- PortableRawWriter raw = writer.rawWriter();
-
- raw.writeString(sRaw);
- }
-
- /** {@inheritDoc} */
- @Override public void readPortable(PortableReader reader) throws PortableException {
- s = reader.readString("s");
-
- PortableRawReader raw = reader.rawReader();
-
- sRaw = raw.readString();
- }
-
- /** {@inheritDoc} */
- @SuppressWarnings("FloatingPointEquality")
- @Override public boolean equals(Object other) {
- return this == other || GridTestUtils.deepEquals(this, other);
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(GridPortableMarshalerAwareTestClass.class, this);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/35b6d61f/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
index a2ae71f..af9be0b 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
@@ -32,7 +32,7 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.igniteobject.IgniteObject;
/**
*
@@ -106,7 +106,7 @@ public class GridPortableTestClasses {
*/
public static class TestObjectPlainPortable {
/** */
- public PortableObject plainPortable;
+ public IgniteObject plainPortable;
/**
*
@@ -118,7 +118,7 @@ public class GridPortableTestClasses {
/**
* @param plainPortable Object.
*/
- public TestObjectPlainPortable(PortableObject plainPortable) {
+ public TestObjectPlainPortable(IgniteObject plainPortable) {
this.plainPortable = plainPortable;
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/35b6d61f/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeIgniteObjectMetadataMultinodeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeIgniteObjectMetadataMultinodeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeIgniteObjectMetadataMultinodeTest.java
new file mode 100644
index 0000000..e86a160
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeIgniteObjectMetadataMultinodeTest.java
@@ -0,0 +1,295 @@
+/*
+ * 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.portable;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteObjects;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.lang.GridAbsPredicate;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.igniteobject.IgniteObjectBuilder;
+import org.apache.ignite.igniteobject.IgniteObjectMetadata;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.eclipse.jetty.util.ConcurrentHashSet;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class GridCacheClientNodeIgniteObjectMetadataMultinodeTest extends GridCommonAbstractTest {
+ /** */
+ protected static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private boolean client;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setPeerClassLoadingEnabled(false);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder).setForceServerMode(true);
+
+ cfg.setMarshaller(new PortableMarshaller());
+
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+ cfg.setCacheConfiguration(ccfg);
+
+ cfg.setClientMode(client);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClientMetadataInitialization() throws Exception {
+ startGrids(2);
+
+ final AtomicBoolean stop = new AtomicBoolean();
+
+ final ConcurrentHashSet<String> allTypes = new ConcurrentHashSet<>();
+
+ IgniteInternalFuture<?> fut;
+
+ try {
+ // Update portable metadata concurrently with client nodes start.
+ fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ IgniteObjects portables = ignite(0).portables();
+
+ IgniteCache<Object, Object> cache = ignite(0).cache(null).withKeepBinary();
+
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ for (int i = 0; i < 1000; i++) {
+ log.info("Iteration: " + i);
+
+ String type = "portable-type-" + i;
+
+ allTypes.add(type);
+
+ for (int f = 0; f < 10; f++) {
+ IgniteObjectBuilder builder = portables.builder(type);
+
+ String fieldName = "f" + f;
+
+ builder.setField(fieldName, i);
+
+ cache.put(rnd.nextInt(0, 100_000), builder.build());
+
+ if (f % 100 == 0)
+ log.info("Put iteration: " + f);
+ }
+
+ if (stop.get())
+ break;
+ }
+
+ return null;
+ }
+ }, 5, "update-thread");
+ }
+ finally {
+ stop.set(true);
+ }
+
+ client = true;
+
+ startGridsMultiThreaded(2, 5);
+
+ fut.get();
+
+ assertFalse(allTypes.isEmpty());
+
+ log.info("Expected portable types: " + allTypes.size());
+
+ assertEquals(7, ignite(0).cluster().nodes().size());
+
+ for (int i = 0; i < 7; i++) {
+ log.info("Check metadata on node: " + i);
+
+ boolean client = i > 1;
+
+ assertEquals((Object)client, ignite(i).configuration().isClientMode());
+
+ IgniteObjects portables = ignite(i).portables();
+
+ Collection<IgniteObjectMetadata> metaCol = portables.metadata();
+
+ assertEquals(allTypes.size(), metaCol.size());
+
+ Set<String> names = new HashSet<>();
+
+ for (IgniteObjectMetadata meta : metaCol) {
+ assertTrue(names.add(meta.typeName()));
+
+ assertNull(meta.affinityKeyFieldName());
+
+ assertEquals(10, meta.fields().size());
+ }
+
+ assertEquals(allTypes.size(), names.size());
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFailoverOnStart() throws Exception {
+ startGrids(4);
+
+ IgniteObjects portables = ignite(0).portables();
+
+ IgniteCache<Object, Object> cache = ignite(0).cache(null).withKeepBinary();
+
+ for (int i = 0; i < 1000; i++) {
+ IgniteObjectBuilder builder = portables.builder("type-" + i);
+
+ builder.setField("f0", i);
+
+ cache.put(i, builder.build());
+ }
+
+ client = true;
+
+ final CyclicBarrier barrier = new CyclicBarrier(6);
+
+ final AtomicInteger startIdx = new AtomicInteger(4);
+
+ IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ barrier.await();
+
+ Ignite ignite = startGrid(startIdx.getAndIncrement());
+
+ assertTrue(ignite.configuration().isClientMode());
+
+ log.info("Started node: " + ignite.name());
+
+ return null;
+ }
+ }, 5, "start-thread");
+
+ barrier.await();
+
+ U.sleep(ThreadLocalRandom.current().nextInt(10, 100));
+
+ for (int i = 0; i < 3; i++)
+ stopGrid(i);
+
+ fut.get();
+
+ assertEquals(6, ignite(3).cluster().nodes().size());
+
+ for (int i = 3; i < 7; i++) {
+ log.info("Check metadata on node: " + i);
+
+ boolean client = i > 3;
+
+ assertEquals((Object) client, ignite(i).configuration().isClientMode());
+
+ portables = ignite(i).portables();
+
+ final IgniteObjects p0 = portables;
+
+ GridTestUtils.waitForCondition(new GridAbsPredicate() {
+ @Override public boolean apply() {
+ Collection<IgniteObjectMetadata> metaCol = p0.metadata();
+
+ return metaCol.size() == 1000;
+ }
+ }, getTestTimeout());
+
+ Collection<IgniteObjectMetadata> metaCol = portables.metadata();
+
+ assertEquals(1000, metaCol.size());
+
+ Set<String> names = new HashSet<>();
+
+ for (IgniteObjectMetadata meta : metaCol) {
+ assertTrue(names.add(meta.typeName()));
+
+ assertNull(meta.affinityKeyFieldName());
+
+ assertEquals(1, meta.fields().size());
+ }
+
+ assertEquals(1000, names.size());
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClientStartsFirst() throws Exception {
+ client = true;
+
+ Ignite ignite0 = startGrid(0);
+
+ assertTrue(ignite0.configuration().isClientMode());
+
+ client = false;
+
+ Ignite ignite1 = startGrid(1);
+
+ assertFalse(ignite1.configuration().isClientMode());
+
+ IgniteObjects portables = ignite(1).portables();
+
+ IgniteCache<Object, Object> cache = ignite(1).cache(null).withKeepBinary();
+
+ for (int i = 0; i < 100; i++) {
+ IgniteObjectBuilder builder = portables.builder("type-" + i);
+
+ builder.setField("f0", i);
+
+ cache.put(i, builder.build());
+ }
+
+ assertEquals(100, ignite(0).portables().metadata().size());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/35b6d61f/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeIgniteObjectMetadataTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeIgniteObjectMetadataTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeIgniteObjectMetadataTest.java
new file mode 100644
index 0000000..addf1f8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeIgniteObjectMetadataTest.java
@@ -0,0 +1,290 @@
+/*
+ * 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.portable;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheKeyConfiguration;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.igniteobject.IgniteObjectBuilder;
+import org.apache.ignite.igniteobject.IgniteObjectMetadata;
+import org.apache.ignite.igniteobject.IgniteObject;
+import org.apache.ignite.igniteobject.IgniteObjectConfiguration;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+
+/**
+ *
+ */
+public class GridCacheClientNodeIgniteObjectMetadataTest extends GridCacheAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 4;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return CacheMode.PARTITIONED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return ATOMIC;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(TestObject1.class.getName(), TestObject2.class.getName()));
+
+ IgniteObjectConfiguration typeCfg = new IgniteObjectConfiguration();
+
+ typeCfg.setClassName(TestObject1.class.getName());
+
+ CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(TestObject1.class.getName(), "val2");
+
+ cfg.setCacheKeyCfg(keyCfg);
+
+ marsh.setTypeConfigurations(Arrays.asList(typeCfg));
+
+ if (gridName.equals(getTestGridName(gridCount() - 1)))
+ cfg.setClientMode(true);
+
+ cfg.setMarshaller(marsh);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setForceServerMode(true);
+
+ return cfg;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableMetadataOnClient() throws Exception {
+ Ignite ignite0 = ignite(gridCount() - 1);
+
+ assertTrue(ignite0.configuration().isClientMode());
+
+ Ignite ignite1 = ignite(0);
+
+ assertFalse(ignite1.configuration().isClientMode());
+
+ Affinity<Object> aff0 = ignite0.affinity(null);
+ Affinity<Object> aff1 = ignite1.affinity(null);
+
+ for (int i = 0 ; i < 100; i++) {
+ TestObject1 obj1 = new TestObject1(i, i + 1);
+
+ assertEquals(aff1.mapKeyToPrimaryAndBackups(obj1),
+ aff0.mapKeyToPrimaryAndBackups(obj1));
+
+ TestObject2 obj2 = new TestObject2(i, i + 1);
+
+ assertEquals(aff1.mapKeyToPrimaryAndBackups(obj2),
+ aff0.mapKeyToPrimaryAndBackups(obj2));
+ }
+
+ {
+ IgniteObjectBuilder builder = ignite0.portables().builder("TestObject3");
+
+ builder.setField("f1", 1);
+
+ ignite0.cache(null).put(0, builder.build());
+
+ IgniteCache<Integer, IgniteObject> cache = ignite0.cache(null).withKeepBinary();
+
+ IgniteObject obj = cache.get(0);
+
+ IgniteObjectMetadata meta = obj.metaData();
+
+ assertNotNull(meta);
+ assertEquals(1, meta.fields().size());
+
+ meta = ignite0.portables().metadata(TestObject1.class);
+
+ assertNotNull(meta);
+ assertEquals("val2", meta.affinityKeyFieldName());
+
+ meta = ignite0.portables().metadata(TestObject2.class);
+
+ assertNotNull(meta);
+ assertNull(meta.affinityKeyFieldName());
+ }
+
+ {
+ IgniteObjectBuilder builder = ignite1.portables().builder("TestObject3");
+
+ builder.setField("f2", 2);
+
+ ignite1.cache(null).put(1, builder.build());
+
+ IgniteCache<Integer, IgniteObject> cache = ignite1.cache(null).withKeepBinary();
+
+ IgniteObject obj = cache.get(0);
+
+ IgniteObjectMetadata meta = obj.metaData();
+
+ assertNotNull(meta);
+ assertEquals(2, meta.fields().size());
+
+ meta = ignite1.portables().metadata(TestObject1.class);
+
+ assertNotNull(meta);
+ assertEquals("val2", meta.affinityKeyFieldName());
+
+ meta = ignite1.portables().metadata(TestObject2.class);
+
+ assertNotNull(meta);
+ assertNull(meta.affinityKeyFieldName());
+ }
+
+ IgniteObjectMetadata meta = ignite0.portables().metadata("TestObject3");
+
+ assertNotNull(meta);
+ assertEquals(2, meta.fields().size());
+
+ IgniteCache<Integer, IgniteObject> cache = ignite0.cache(null).withKeepBinary();
+
+ IgniteObject obj = cache.get(1);
+
+ assertEquals(Integer.valueOf(2), obj.field("f2"));
+ assertNull(obj.field("f1"));
+
+ meta = obj.metaData();
+
+ assertNotNull(meta);
+ assertEquals(2, meta.fields().size());
+
+ Collection<IgniteObjectMetadata> meta1 = ignite1.portables().metadata();
+ Collection<IgniteObjectMetadata> meta2 = ignite1.portables().metadata();
+
+ assertEquals(meta1.size(), meta2.size());
+
+ for (IgniteObjectMetadata m1 : meta1) {
+ boolean found = false;
+
+ for (IgniteObjectMetadata m2 : meta1) {
+ if (m1.typeName().equals(m2.typeName())) {
+ assertEquals(m1.affinityKeyFieldName(), m2.affinityKeyFieldName());
+ assertEquals(m1.fields(), m2.fields());
+
+ found = true;
+
+ break;
+ }
+ }
+
+ assertTrue(found);
+ }
+ }
+
+ /**
+ *
+ */
+ static class TestObject1 {
+ /** */
+ private int val1;
+
+ /** */
+ private int val2;
+
+ /**
+ * @param val1 Value 1.
+ * @param val2 Value 2.
+ */
+ public TestObject1(int val1, int val2) {
+ this.val1 = val1;
+ this.val2 = val2;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestObject1 that = (TestObject1)o;
+
+ return val1 == that.val1;
+
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val1;
+ }
+ }
+
+ /**
+ *
+ */
+ static class TestObject2 {
+ /** */
+ private int val1;
+
+ /** */
+ private int val2;
+
+ /**
+ * @param val1 Value 1.
+ * @param val2 Value 2.
+ */
+ public TestObject2(int val1, int val2) {
+ this.val1 = val1;
+ this.val2 = val2;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ TestObject2 that = (TestObject2)o;
+
+ return val2 == that.val2;
+
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val2;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/35b6d61f/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataMultinodeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataMultinodeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataMultinodeTest.java
deleted file mode 100644
index 1ba3d4d..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataMultinodeTest.java
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * 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.portable;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CyclicBarrier;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgnitePortables;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.util.lang.GridAbsPredicate;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.eclipse.jetty.util.ConcurrentHashSet;
-
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-
-/**
- *
- */
-public class GridCacheClientNodePortableMetadataMultinodeTest extends GridCommonAbstractTest {
- /** */
- protected static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
-
- /** */
- private boolean client;
-
- /** {@inheritDoc} */
- @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- cfg.setPeerClassLoadingEnabled(false);
-
- ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder).setForceServerMode(true);
-
- cfg.setMarshaller(new PortableMarshaller());
-
- CacheConfiguration ccfg = new CacheConfiguration();
-
- ccfg.setWriteSynchronizationMode(FULL_SYNC);
-
- cfg.setCacheConfiguration(ccfg);
-
- cfg.setClientMode(client);
-
- return cfg;
- }
-
- /** {@inheritDoc} */
- @Override protected void afterTest() throws Exception {
- super.afterTest();
-
- stopAllGrids();
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testClientMetadataInitialization() throws Exception {
- startGrids(2);
-
- final AtomicBoolean stop = new AtomicBoolean();
-
- final ConcurrentHashSet<String> allTypes = new ConcurrentHashSet<>();
-
- IgniteInternalFuture<?> fut;
-
- try {
- // Update portable metadata concurrently with client nodes start.
- fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
- @Override public Object call() throws Exception {
- IgnitePortables portables = ignite(0).portables();
-
- IgniteCache<Object, Object> cache = ignite(0).cache(null).withKeepPortable();
-
- ThreadLocalRandom rnd = ThreadLocalRandom.current();
-
- for (int i = 0; i < 1000; i++) {
- log.info("Iteration: " + i);
-
- String type = "portable-type-" + i;
-
- allTypes.add(type);
-
- for (int f = 0; f < 10; f++) {
- PortableBuilder builder = portables.builder(type);
-
- String fieldName = "f" + f;
-
- builder.setField(fieldName, i);
-
- cache.put(rnd.nextInt(0, 100_000), builder.build());
-
- if (f % 100 == 0)
- log.info("Put iteration: " + f);
- }
-
- if (stop.get())
- break;
- }
-
- return null;
- }
- }, 5, "update-thread");
- }
- finally {
- stop.set(true);
- }
-
- client = true;
-
- startGridsMultiThreaded(2, 5);
-
- fut.get();
-
- assertFalse(allTypes.isEmpty());
-
- log.info("Expected portable types: " + allTypes.size());
-
- assertEquals(7, ignite(0).cluster().nodes().size());
-
- for (int i = 0; i < 7; i++) {
- log.info("Check metadata on node: " + i);
-
- boolean client = i > 1;
-
- assertEquals((Object)client, ignite(i).configuration().isClientMode());
-
- IgnitePortables portables = ignite(i).portables();
-
- Collection<PortableMetadata> metaCol = portables.metadata();
-
- assertEquals(allTypes.size(), metaCol.size());
-
- Set<String> names = new HashSet<>();
-
- for (PortableMetadata meta : metaCol) {
- assertTrue(names.add(meta.typeName()));
-
- assertNull(meta.affinityKeyFieldName());
-
- assertEquals(10, meta.fields().size());
- }
-
- assertEquals(allTypes.size(), names.size());
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testFailoverOnStart() throws Exception {
- startGrids(4);
-
- IgnitePortables portables = ignite(0).portables();
-
- IgniteCache<Object, Object> cache = ignite(0).cache(null).withKeepPortable();
-
- for (int i = 0; i < 1000; i++) {
- PortableBuilder builder = portables.builder("type-" + i);
-
- builder.setField("f0", i);
-
- cache.put(i, builder.build());
- }
-
- client = true;
-
- final CyclicBarrier barrier = new CyclicBarrier(6);
-
- final AtomicInteger startIdx = new AtomicInteger(4);
-
- IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
- @Override public Object call() throws Exception {
- barrier.await();
-
- Ignite ignite = startGrid(startIdx.getAndIncrement());
-
- assertTrue(ignite.configuration().isClientMode());
-
- log.info("Started node: " + ignite.name());
-
- return null;
- }
- }, 5, "start-thread");
-
- barrier.await();
-
- U.sleep(ThreadLocalRandom.current().nextInt(10, 100));
-
- for (int i = 0; i < 3; i++)
- stopGrid(i);
-
- fut.get();
-
- assertEquals(6, ignite(3).cluster().nodes().size());
-
- for (int i = 3; i < 7; i++) {
- log.info("Check metadata on node: " + i);
-
- boolean client = i > 3;
-
- assertEquals((Object) client, ignite(i).configuration().isClientMode());
-
- portables = ignite(i).portables();
-
- final IgnitePortables p0 = portables;
-
- GridTestUtils.waitForCondition(new GridAbsPredicate() {
- @Override public boolean apply() {
- Collection<PortableMetadata> metaCol = p0.metadata();
-
- return metaCol.size() == 1000;
- }
- }, getTestTimeout());
-
- Collection<PortableMetadata> metaCol = portables.metadata();
-
- assertEquals(1000, metaCol.size());
-
- Set<String> names = new HashSet<>();
-
- for (PortableMetadata meta : metaCol) {
- assertTrue(names.add(meta.typeName()));
-
- assertNull(meta.affinityKeyFieldName());
-
- assertEquals(1, meta.fields().size());
- }
-
- assertEquals(1000, names.size());
- }
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testClientStartsFirst() throws Exception {
- client = true;
-
- Ignite ignite0 = startGrid(0);
-
- assertTrue(ignite0.configuration().isClientMode());
-
- client = false;
-
- Ignite ignite1 = startGrid(1);
-
- assertFalse(ignite1.configuration().isClientMode());
-
- IgnitePortables portables = ignite(1).portables();
-
- IgniteCache<Object, Object> cache = ignite(1).cache(null).withKeepPortable();
-
- for (int i = 0; i < 100; i++) {
- PortableBuilder builder = portables.builder("type-" + i);
-
- builder.setField("f0", i);
-
- cache.put(i, builder.build());
- }
-
- assertEquals(100, ignite(0).portables().metadata().size());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/35b6d61f/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataTest.java
deleted file mode 100644
index a66d940..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataTest.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * 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.portable;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.affinity.Affinity;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
-import org.apache.ignite.marshaller.portable.PortableMarshaller;
-import org.apache.ignite.portable.PortableBuilder;
-import org.apache.ignite.portable.PortableMetadata;
-import org.apache.ignite.portable.PortableObject;
-import org.apache.ignite.portable.PortableTypeConfiguration;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-
-/**
- *
- */
-public class GridCacheClientNodePortableMetadataTest extends GridCacheAbstractSelfTest {
- /** {@inheritDoc} */
- @Override protected int gridCount() {
- return 4;
- }
-
- /** {@inheritDoc} */
- @Override protected CacheMode cacheMode() {
- return CacheMode.PARTITIONED;
- }
-
- /** {@inheritDoc} */
- @Override protected CacheAtomicityMode atomicityMode() {
- return ATOMIC;
- }
-
- /** {@inheritDoc} */
- @Override protected NearCacheConfiguration nearConfiguration() {
- return null;
- }
-
- /** {@inheritDoc} */
- @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
- IgniteConfiguration cfg = super.getConfiguration(gridName);
-
- PortableMarshaller marsh = new PortableMarshaller();
-
- marsh.setClassNames(Arrays.asList(TestObject1.class.getName(), TestObject2.class.getName()));
-
- PortableTypeConfiguration typeCfg = new PortableTypeConfiguration();
-
- typeCfg.setClassName(TestObject1.class.getName());
- typeCfg.setAffinityKeyFieldName("val2");
-
- marsh.setTypeConfigurations(Arrays.asList(typeCfg));
-
- if (gridName.equals(getTestGridName(gridCount() - 1)))
- cfg.setClientMode(true);
-
- cfg.setMarshaller(marsh);
-
- ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setForceServerMode(true);
-
- return cfg;
- }
-
- /**
- * @throws Exception If failed.
- */
- public void testPortableMetadataOnClient() throws Exception {
- Ignite ignite0 = ignite(gridCount() - 1);
-
- assertTrue(ignite0.configuration().isClientMode());
-
- Ignite ignite1 = ignite(0);
-
- assertFalse(ignite1.configuration().isClientMode());
-
- Affinity<Object> aff0 = ignite0.affinity(null);
- Affinity<Object> aff1 = ignite1.affinity(null);
-
- for (int i = 0 ; i < 100; i++) {
- TestObject1 obj1 = new TestObject1(i, i + 1);
-
- assertEquals(aff1.mapKeyToPrimaryAndBackups(obj1),
- aff0.mapKeyToPrimaryAndBackups(obj1));
-
- TestObject2 obj2 = new TestObject2(i, i + 1);
-
- assertEquals(aff1.mapKeyToPrimaryAndBackups(obj2),
- aff0.mapKeyToPrimaryAndBackups(obj2));
- }
-
- {
- PortableBuilder builder = ignite0.portables().builder("TestObject3");
-
- builder.setField("f1", 1);
-
- ignite0.cache(null).put(0, builder.build());
-
- IgniteCache<Integer, PortableObject> cache = ignite0.cache(null).withKeepPortable();
-
- PortableObject obj = cache.get(0);
-
- PortableMetadata meta = obj.metaData();
-
- assertNotNull(meta);
- assertEquals(1, meta.fields().size());
-
- meta = ignite0.portables().metadata(TestObject1.class);
-
- assertNotNull(meta);
- assertEquals("val2", meta.affinityKeyFieldName());
-
- meta = ignite0.portables().metadata(TestObject2.class);
-
- assertNotNull(meta);
- assertNull(meta.affinityKeyFieldName());
- }
-
- {
- PortableBuilder builder = ignite1.portables().builder("TestObject3");
-
- builder.setField("f2", 2);
-
- ignite1.cache(null).put(1, builder.build());
-
- IgniteCache<Integer, PortableObject> cache = ignite1.cache(null).withKeepPortable();
-
- PortableObject obj = cache.get(0);
-
- PortableMetadata meta = obj.metaData();
-
- assertNotNull(meta);
- assertEquals(2, meta.fields().size());
-
- meta = ignite1.portables().metadata(TestObject1.class);
-
- assertNotNull(meta);
- assertEquals("val2", meta.affinityKeyFieldName());
-
- meta = ignite1.portables().metadata(TestObject2.class);
-
- assertNotNull(meta);
- assertNull(meta.affinityKeyFieldName());
- }
-
- PortableMetadata meta = ignite0.portables().metadata("TestObject3");
-
- assertNotNull(meta);
- assertEquals(2, meta.fields().size());
-
- IgniteCache<Integer, PortableObject> cache = ignite0.cache(null).withKeepPortable();
-
- PortableObject obj = cache.get(1);
-
- assertEquals(Integer.valueOf(2), obj.field("f2"));
- assertNull(obj.field("f1"));
-
- meta = obj.metaData();
-
- assertNotNull(meta);
- assertEquals(2, meta.fields().size());
-
- Collection<PortableMetadata> meta1 = ignite1.portables().metadata();
- Collection<PortableMetadata> meta2 = ignite1.portables().metadata();
-
- assertEquals(meta1.size(), meta2.size());
-
- for (PortableMetadata m1 : meta1) {
- boolean found = false;
-
- for (PortableMetadata m2 : meta1) {
- if (m1.typeName().equals(m2.typeName())) {
- assertEquals(m1.affinityKeyFieldName(), m2.affinityKeyFieldName());
- assertEquals(m1.fields(), m2.fields());
-
- found = true;
-
- break;
- }
- }
-
- assertTrue(found);
- }
- }
-
- /**
- *
- */
- static class TestObject1 {
- /** */
- private int val1;
-
- /** */
- private int val2;
-
- /**
- * @param val1 Value 1.
- * @param val2 Value 2.
- */
- public TestObject1(int val1, int val2) {
- this.val1 = val1;
- this.val2 = val2;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- TestObject1 that = (TestObject1)o;
-
- return val1 == that.val1;
-
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return val1;
- }
- }
-
- /**
- *
- */
- static class TestObject2 {
- /** */
- private int val1;
-
- /** */
- private int val2;
-
- /**
- * @param val1 Value 1.
- * @param val2 Value 2.
- */
- public TestObject2(int val1, int val2) {
- this.val1 = val1;
- this.val2 = val2;
- }
-
- /** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o)
- return true;
-
- if (o == null || getClass() != o.getClass())
- return false;
-
- TestObject2 that = (TestObject2)o;
-
- return val2 == that.val2;
-
- }
-
- /** {@inheritDoc} */
- @Override public int hashCode() {
- return val2;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/35b6d61f/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheIgniteObjectsAbstractDataStreamerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheIgniteObjectsAbstractDataStreamerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheIgniteObjectsAbstractDataStreamerSelfTest.java
new file mode 100644
index 0000000..a51cbbf
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheIgniteObjectsAbstractDataStreamerSelfTest.java
@@ -0,0 +1,190 @@
+/*
+ * 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.portable;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.igniteobject.IgniteObjectException;
+import org.apache.ignite.igniteobject.IgniteObjectMarshalAware;
+import org.apache.ignite.igniteobject.IgniteObjectReader;
+import org.apache.ignite.igniteobject.IgniteObjectConfiguration;
+import org.apache.ignite.igniteobject.IgniteObjectWriter;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jsr166.LongAdder8;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public abstract class GridCacheIgniteObjectsAbstractDataStreamerSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final int THREAD_CNT = 64;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ CacheConfiguration cacheCfg = new CacheConfiguration();
+
+ cacheCfg.setCacheMode(cacheMode());
+ cacheCfg.setAtomicityMode(atomicityMode());
+ cacheCfg.setNearConfiguration(nearConfiguration());
+ cacheCfg.setWriteSynchronizationMode(writeSynchronizationMode());
+
+ cfg.setCacheConfiguration(cacheCfg);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new IgniteObjectConfiguration(TestObject.class.getName())));
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /**
+ * @return Sync mode.
+ */
+ protected CacheWriteSynchronizationMode writeSynchronizationMode() {
+ return PRIMARY_SYNC;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGridsMultiThreaded(gridCount());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * @return Cache mode.
+ */
+ protected abstract CacheMode cacheMode();
+
+ /**
+ * @return Atomicity mode.
+ */
+ protected abstract CacheAtomicityMode atomicityMode();
+
+ /**
+ * @return Near configuration.
+ */
+ protected abstract NearCacheConfiguration nearConfiguration();
+
+ /**
+ * @return Grid count.
+ */
+ protected int gridCount() {
+ return 1;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("BusyWait")
+ public void testGetPut() throws Exception {
+ final AtomicBoolean flag = new AtomicBoolean();
+
+ final LongAdder8 cnt = new LongAdder8();
+
+ try (IgniteDataStreamer<Object, Object> ldr = grid(0).dataStreamer(null)) {
+ IgniteInternalFuture<?> f = multithreadedAsync(
+ new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ while (!flag.get()) {
+ ldr.addData(rnd.nextInt(10000), new TestObject(rnd.nextInt(10000)));
+
+ cnt.add(1);
+ }
+
+ return null;
+ }
+ },
+ THREAD_CNT
+ );
+
+ for (int i = 0; i < 30 && !f.isDone(); i++)
+ Thread.sleep(1000);
+
+ flag.set(true);
+
+ f.get();
+ }
+
+ info("Operations in 30 sec: " + cnt.sum());
+ }
+
+ /**
+ */
+ private static class TestObject implements IgniteObjectMarshalAware, Serializable {
+ /** */
+ private int val;
+
+ /**
+ */
+ private TestObject() {
+ // No-op.
+ }
+
+ /**
+ * @param val Value.
+ */
+ private TestObject(int val) {
+ this.val = val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ return obj instanceof TestObject && ((TestObject)obj).val == val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writePortable(IgniteObjectWriter writer) throws IgniteObjectException {
+ writer.writeInt("val", val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(IgniteObjectReader reader) throws IgniteObjectException {
+ val = reader.readInt("val");
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/35b6d61f/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheIgniteObjectsAbstractMultiThreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheIgniteObjectsAbstractMultiThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheIgniteObjectsAbstractMultiThreadedSelfTest.java
new file mode 100644
index 0000000..5620c3c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheIgniteObjectsAbstractMultiThreadedSelfTest.java
@@ -0,0 +1,231 @@
+/*
+ * 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.portable;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.igniteobject.IgniteObjectException;
+import org.apache.ignite.igniteobject.IgniteObjectMarshalAware;
+import org.apache.ignite.igniteobject.IgniteObject;
+import org.apache.ignite.igniteobject.IgniteObjectReader;
+import org.apache.ignite.igniteobject.IgniteObjectConfiguration;
+import org.apache.ignite.igniteobject.IgniteObjectWriter;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jsr166.LongAdder8;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public abstract class GridCacheIgniteObjectsAbstractMultiThreadedSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final int THREAD_CNT = 64;
+
+ /** */
+ private static final AtomicInteger idxGen = new AtomicInteger();
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ CacheConfiguration cacheCfg = new CacheConfiguration();
+
+ cacheCfg.setCacheMode(cacheMode());
+ cacheCfg.setAtomicityMode(atomicityMode());
+ cacheCfg.setNearConfiguration(nearConfiguration());
+ cacheCfg.setWriteSynchronizationMode(writeSynchronizationMode());
+
+ cfg.setCacheConfiguration(cacheCfg);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new IgniteObjectConfiguration(TestObject.class.getName())));
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /**
+ * @return Sync mode.
+ */
+ protected CacheWriteSynchronizationMode writeSynchronizationMode() {
+ return PRIMARY_SYNC;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGridsMultiThreaded(gridCount());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * @return Cache mode.
+ */
+ protected abstract CacheMode cacheMode();
+
+ /**
+ * @return Atomicity mode.
+ */
+ protected abstract CacheAtomicityMode atomicityMode();
+
+ /**
+ * @return Distribution mode.
+ */
+ protected abstract NearCacheConfiguration nearConfiguration();
+
+ /**
+ * @return Grid count.
+ */
+ protected int gridCount() {
+ return 1;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("BusyWait") public void testGetPut() throws Exception {
+ final AtomicBoolean flag = new AtomicBoolean();
+
+ final LongAdder8 cnt = new LongAdder8();
+
+ IgniteInternalFuture<?> f = multithreadedAsync(
+ new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ int threadId = idxGen.getAndIncrement() % 2;
+
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+ while (!flag.get()) {
+ IgniteCache<Object, Object> c = jcache(rnd.nextInt(gridCount()));
+
+ switch (threadId) {
+ case 0:
+ // Put/get/remove portable -> portable.
+
+ c.put(new TestObject(rnd.nextInt(10000)), new TestObject(rnd.nextInt(10000)));
+
+ IgniteCache<Object, Object> p2 = ((IgniteCacheProxy<Object, Object>)c).keepPortable();
+
+ IgniteObject v = (IgniteObject)p2.get(new TestObject(rnd.nextInt(10000)));
+
+ if (v != null)
+ v.deserialize();
+
+ c.remove(new TestObject(rnd.nextInt(10000)));
+
+ break;
+
+ case 1:
+ // Put/get int -> portable.
+ c.put(rnd.nextInt(10000), new TestObject(rnd.nextInt(10000)));
+
+ IgniteCache<Integer, IgniteObject> p4 = ((IgniteCacheProxy<Object, Object>)c).keepPortable();
+
+ IgniteObject v1 = p4.get(rnd.nextInt(10000));
+
+ if (v1 != null)
+ v1.deserialize();
+
+ p4.remove(rnd.nextInt(10000));
+
+ break;
+
+ default:
+ assert false;
+ }
+
+ cnt.add(3);
+ }
+
+ return null;
+ }
+ },
+ THREAD_CNT
+ );
+
+ for (int i = 0; i < 30 && !f.isDone(); i++)
+ Thread.sleep(1000);
+
+ flag.set(true);
+
+ f.get();
+
+ info("Operations in 30 sec: " + cnt.sum());
+ }
+
+ /**
+ */
+ private static class TestObject implements IgniteObjectMarshalAware, Serializable {
+ /** */
+ private int val;
+
+ /**
+ */
+ private TestObject() {
+ // No-op.
+ }
+
+ /**
+ * @param val Value.
+ */
+ private TestObject(int val) {
+ this.val = val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ return obj instanceof TestObject && ((TestObject)obj).val == val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writePortable(IgniteObjectWriter writer) throws IgniteObjectException {
+ writer.writeInt("val", val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(IgniteObjectReader reader) throws IgniteObjectException {
+ val = reader.readInt("val");
+ }
+ }
+}
\ No newline at end of file