You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/09/15 08:27:25 UTC
[01/11] ignite git commit: Revert "ignite-1462: hid portable API in
1.4 release" This reverts commit 71379a8061f50f336adc31fa20cd593b659b050f.
Repository: ignite
Updated Branches:
refs/heads/ignite-1486 7955c15a9 -> e7eb2b372
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
new file mode 100644
index 0000000..27ac436
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
@@ -0,0 +1,117 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.internal.processors.cache.CacheLocalQueryMetricsSelfTest;
+import org.apache.ignite.internal.processors.cache.CachePartitionedQueryMetricsDistributedSelfTest;
+import org.apache.ignite.internal.processors.cache.CachePartitionedQueryMetricsLocalSelfTest;
+import org.apache.ignite.internal.processors.cache.CacheReplicatedQueryMetricsDistributedSelfTest;
+import org.apache.ignite.internal.processors.cache.CacheReplicatedQueryMetricsLocalSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheQueryIndexDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheQueryIndexingDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheReduceQueryMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheFieldsQueryNoDataSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheLargeResultSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapTieredMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheP2pUnmarshallingQueryErrorTest;
+import org.apache.ignite.internal.processors.cache.IgniteCachePartitionedQueryMultiThreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheQueryEvictsMultiThreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheQueryMultiThreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheQueryOffheapMultiThreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicNearEnabledSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicP2PDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryLocalAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryPartitionedOnlySelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryReplicatedAtomicSelfTest;
+import org.apache.ignite.internal.processors.query.h2.sql.BaseH2CompareQueryTest;
+import org.apache.ignite.internal.processors.query.h2.sql.GridQueryParsingTest;
+import org.apache.ignite.internal.processors.query.h2.sql.H2CompareBigQueryTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.spi.communication.tcp.GridOrderedMessageCancelSelfTest;
+import org.apache.ignite.testframework.config.GridTestProperties;
+
+/**
+ * Cache query suite with portable marshaller.
+ */
+public class IgnitePortableCacheQueryTestSuite extends TestSuite {
+ /**
+ * @return Suite.
+ * @throws Exception In case of error.
+ */
+ public static TestSuite suite() throws Exception {
+ GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, PortableMarshaller.class.getName());
+
+ TestSuite suite = new TestSuite("Grid Cache Query Test Suite using PortableMarshaller");
+
+ // Parsing
+ suite.addTestSuite(GridQueryParsingTest.class);
+
+ // Queries tests.
+ suite.addTestSuite(GridCacheQueryIndexDisabledSelfTest.class);
+ suite.addTestSuite(IgniteCachePartitionedQueryMultiThreadedSelfTest.class);
+ suite.addTestSuite(IgniteCacheLargeResultSelfTest.class);
+ suite.addTestSuite(IgniteCacheQueryMultiThreadedSelfTest.class);
+ suite.addTestSuite(IgniteCacheQueryEvictsMultiThreadedSelfTest.class);
+ suite.addTestSuite(IgniteCacheQueryOffheapMultiThreadedSelfTest.class);
+
+ suite.addTestSuite(IgniteCacheOffheapTieredMultithreadedSelfTest.class);
+ suite.addTestSuite(GridCacheReduceQueryMultithreadedSelfTest.class);
+
+
+ // Fields queries.
+ suite.addTestSuite(IgniteCacheFieldsQueryNoDataSelfTest.class);
+
+ // Continuous queries.
+ suite.addTestSuite(GridCacheContinuousQueryLocalAtomicSelfTest.class);
+ suite.addTestSuite(GridCacheContinuousQueryReplicatedAtomicSelfTest.class);
+ suite.addTestSuite(GridCacheContinuousQueryPartitionedOnlySelfTest.class);
+ suite.addTestSuite(GridCacheContinuousQueryAtomicSelfTest.class);
+ suite.addTestSuite(GridCacheContinuousQueryAtomicNearEnabledSelfTest.class);
+ suite.addTestSuite(GridCacheContinuousQueryAtomicP2PDisabledSelfTest.class);
+
+ suite.addTestSuite(GridCacheQueryIndexingDisabledSelfTest.class);
+
+ //Should be adjusted. Not ready to be used with PortableMarshaller.
+ //suite.addTestSuite(GridCachePortableSwapScanQuerySelfTest.class);
+
+ suite.addTestSuite(GridOrderedMessageCancelSelfTest.class);
+
+ // Ignite cache and H2 comparison.
+ suite.addTestSuite(BaseH2CompareQueryTest.class);
+ suite.addTestSuite(H2CompareBigQueryTest.class);
+
+ // Metrics tests
+ suite.addTestSuite(CacheLocalQueryMetricsSelfTest.class);
+ suite.addTestSuite(CachePartitionedQueryMetricsDistributedSelfTest.class);
+ suite.addTestSuite(CachePartitionedQueryMetricsLocalSelfTest.class);
+ suite.addTestSuite(CacheReplicatedQueryMetricsDistributedSelfTest.class);
+ suite.addTestSuite(CacheReplicatedQueryMetricsLocalSelfTest.class);
+
+ //Unmarshallig query test.
+ suite.addTestSuite(IgniteCacheP2pUnmarshallingQueryErrorTest.class);
+
+ suite.addTestSuite(GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.class);
+ suite.addTestSuite(GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.class);
+
+ return suite;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java b/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
index 738f910..3895506 100644
--- a/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
+++ b/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
@@ -37,7 +37,6 @@ import org.apache.ignite.internal.portable.GridPortableMarshaller;
import org.apache.ignite.internal.portable.PortableMetaDataImpl;
import org.apache.ignite.internal.portable.PortableRawReaderEx;
import org.apache.ignite.internal.portable.PortableRawWriterEx;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter;
import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilterImpl;
@@ -71,6 +70,7 @@ import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.T4;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.portable.PortableMetadata;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
@@ -373,7 +373,7 @@ public class PlatformContextImpl implements PlatformContext {
writer.writeInt(metas.size());
- for (PortableMetadata m : metas)
+ for (org.apache.ignite.portable.PortableMetadata m : metas)
writeMetadata0(writer, cacheObjProc.typeId(m.typeName()), m);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java b/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
index 9e092c5..638b4b1 100644
--- a/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
+++ b/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
@@ -33,7 +33,7 @@ import org.apache.ignite.internal.processors.platform.PlatformContext;
import org.apache.ignite.internal.util.typedef.C1;
import org.apache.ignite.lang.IgniteFuture;
import org.apache.ignite.lang.IgniteInClosure;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableObject;
import static org.apache.ignite.internal.processors.task.GridTaskThreadContextKey.TC_SUBGRID;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationClosure.java
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationClosure.java b/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationClosure.java
index ee8f9a3..d95a82b 100644
--- a/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationClosure.java
+++ b/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationClosure.java
@@ -25,7 +25,7 @@ import org.apache.ignite.internal.processors.platform.PlatformAbstractConfigurat
import org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManagerImpl;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.internal.portable.api.PortableMarshaller;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
import org.apache.ignite.platform.cpp.PlatformCppConfiguration;
import java.util.Collections;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
----------------------------------------------------------------------
diff --git a/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java b/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
index 21cd01a..6e03dfe 100644
--- a/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
+++ b/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
@@ -36,10 +36,10 @@ import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lifecycle.LifecycleBean;
import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.internal.portable.api.PortableMarshaller;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
import org.apache.ignite.platform.dotnet.PlatformDotNetLifecycleBean;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMetadata;
import java.util.ArrayList;
import java.util.Collections;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Config/Compute/compute-grid1.xml
----------------------------------------------------------------------
diff --git a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Config/Compute/compute-grid1.xml b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Config/Compute/compute-grid1.xml
index 6164ef3..183676b 100644
--- a/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Config/Compute/compute-grid1.xml
+++ b/modules/platform/src/test/dotnet/Apache.Ignite.Core.Tests/Config/Compute/compute-grid1.xml
@@ -69,16 +69,16 @@
<!-- Portable marshaller configuration -->
<property name="marshaller">
- <bean class="org.apache.ignite.internal.portable.api.PortableMarshaller">
+ <bean class="org.apache.ignite.marshaller.portable.PortableMarshaller">
<property name="typeConfigurations">
<list>
- <bean class="org.apache.ignite.internal.portable.api.PortableTypeConfiguration">
+ <bean class="org.apache.ignite.portable.PortableTypeConfiguration">
<property name="className" value="org.apache.ignite.platform.PlatformComputePortable"/>
</bean>
- <bean class="org.apache.ignite.internal.portable.api.PortableTypeConfiguration">
+ <bean class="org.apache.ignite.portable.PortableTypeConfiguration">
<property name="className" value="org.apache.ignite.platform.PlatformComputeJavaPortable"/>
</bean>
- <bean class="org.apache.ignite.internal.portable.api.PortableTypeConfiguration">
+ <bean class="org.apache.ignite.portable.PortableTypeConfiguration">
<property name="className" value="org.apache.ignite.platform.PlatformComputeEnum"/>
</bean>
</list>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/platform/src/test/java/org/apache/ignite/platform/PlatformComputePortableArgTask.java
----------------------------------------------------------------------
diff --git a/modules/platform/src/test/java/org/apache/ignite/platform/PlatformComputePortableArgTask.java b/modules/platform/src/test/java/org/apache/ignite/platform/PlatformComputePortableArgTask.java
index 9b90209..0e8b825 100644
--- a/modules/platform/src/test/java/org/apache/ignite/platform/PlatformComputePortableArgTask.java
+++ b/modules/platform/src/test/java/org/apache/ignite/platform/PlatformComputePortableArgTask.java
@@ -24,10 +24,9 @@ import org.apache.ignite.compute.ComputeJob;
import org.apache.ignite.compute.ComputeJobAdapter;
import org.apache.ignite.compute.ComputeJobResult;
import org.apache.ignite.compute.ComputeTaskAdapter;
-import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.jetbrains.annotations.Nullable;
@@ -90,8 +89,7 @@ public class PlatformComputePortableArgTask extends ComputeTaskAdapter<Object, I
@Nullable @Override public Object execute() {
PortableObject arg0 = ((PortableObject)arg);
- PortableMetadata meta = ignite instanceof IgniteEx ?
- ((IgniteEx)ignite).portables().metadata(arg0.typeId()) : null;
+ PortableMetadata meta = ignite.portables().metadata(arg0.typeId());
if (meta == null)
throw new IgniteException("Metadata doesn't exist.");
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
index 42514e3..4320df5 100644
--- a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
+++ b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java
@@ -347,6 +347,13 @@ public class IgniteSpringBean implements Ignite, DisposableBean, InitializingBea
}
/** {@inheritDoc} */
+ @Override public IgnitePortables portables() {
+ assert g != null;
+
+ return g.portables();
+ }
+
+ /** {@inheritDoc} */
@Override public void close() throws IgniteException {
g.close();
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index ba44c85..f5a29cb 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -319,6 +319,10 @@
<packages>org.apache.ignite.marshaller*</packages>
</group>
<group>
+ <title>Portable Objects API</title>
+ <packages>org.apache.ignite.portable*</packages>
+ </group>
+ <group>
<title>Visor Plugins</title>
<packages>org.apache.ignite.visor.plugin</packages>
</group>
@@ -708,6 +712,10 @@
<exclude>dev-tools/.gradle/**/*</exclude>
<exclude>dev-tools/gradle/wrapper/**/*</exclude>
<exclude>dev-tools/gradlew</exclude>
+ <exclude>src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom</exclude>
+ <exclude>src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml</exclude>
+ <exclude>src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom</exclude>
+ <exclude>src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml</exclude>
<!--shmem-->
<exclude>ipc/shmem/**/Makefile.in</exclude><!--auto generated files-->
<exclude>ipc/shmem/**/Makefile</exclude><!--auto generated files-->
@@ -737,6 +745,8 @@
<exclude>src/main/java/META-INF/services/org.apache.ignite.internal.processors.platform.PlatformBootstrapFactory</exclude>
<exclude>src/main/resources/META-INF/services/org.apache.ignite.internal.processors.platform.PlatformBootstrapFactory</exclude>
<exclude>src/test/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj</exclude>
+ <exclude>src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.jar</exclude>
+ <exclude>src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.jar</exclude>
<exclude>**/Makefile.am</exclude>
<exclude>**/configure.ac</exclude>
<exclude>**/*.pc.in</exclude>
[03/11] ignite git commit: Revert "ignite-1462: hid portable API in
1.4 release" This reverts commit 71379a8061f50f336adc31fa20cd593b659b050f.
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractDataStreamerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractDataStreamerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractDataStreamerSelfTest.java
new file mode 100644
index 0000000..9ba38d9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractDataStreamerSelfTest.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.portable.PortableException;
+import org.apache.ignite.portable.PortableMarshalAware;
+import org.apache.ignite.portable.PortableReader;
+import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.apache.ignite.portable.PortableWriter;
+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 GridCachePortableObjectsAbstractDataStreamerSelfTest 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 PortableTypeConfiguration(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 PortableMarshalAware, 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(PortableWriter writer) throws PortableException {
+ writer.writeInt("val", val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(PortableReader reader) throws PortableException {
+ val = reader.readInt("val");
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractMultiThreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractMultiThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractMultiThreadedSelfTest.java
new file mode 100644
index 0000000..67f0e52
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractMultiThreadedSelfTest.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.portable.PortableException;
+import org.apache.ignite.portable.PortableMarshalAware;
+import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.portable.PortableReader;
+import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.apache.ignite.portable.PortableWriter;
+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 GridCachePortableObjectsAbstractMultiThreadedSelfTest 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 PortableTypeConfiguration(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();
+
+ PortableObject v = (PortableObject)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, PortableObject> p4 = ((IgniteCacheProxy<Object, Object>)c).keepPortable();
+
+ PortableObject 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 PortableMarshalAware, 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(PortableWriter writer) throws PortableException {
+ writer.writeInt("val", val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(PortableReader reader) throws PortableException {
+ val = reader.readInt("val");
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractSelfTest.java
new file mode 100644
index 0000000..7ac8712
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableObjectsAbstractSelfTest.java
@@ -0,0 +1,978 @@
+/*
+ * 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.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import javax.cache.Cache;
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgnitePortables;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.portable.PortableObjectImpl;
+import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.internal.util.typedef.P2;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiInClosure;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableBuilder;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMarshalAware;
+import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.portable.PortableReader;
+import org.apache.ignite.portable.PortableWriter;
+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.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public abstract class GridCachePortableObjectsAbstractSelfTest extends GridCommonAbstractTest {
+ /** */
+ public static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private static final int ENTRY_CNT = 100;
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+ disco.setIpFinder(IP_FINDER);
+
+ cfg.setDiscoverySpi(disco);
+
+ CacheConfiguration cacheCfg = new CacheConfiguration();
+
+ cacheCfg.setCacheMode(cacheMode());
+ cacheCfg.setAtomicityMode(atomicityMode());
+ cacheCfg.setNearConfiguration(nearConfiguration());
+ cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
+ cacheCfg.setCacheStoreFactory(singletonFactory(new TestStore()));
+ cacheCfg.setReadThrough(true);
+ cacheCfg.setWriteThrough(true);
+ cacheCfg.setLoadPreviousValue(true);
+ cacheCfg.setBackups(1);
+
+ if (offheapTiered()) {
+ cacheCfg.setMemoryMode(OFFHEAP_TIERED);
+ cacheCfg.setOffHeapMaxMemory(0);
+ }
+
+ cfg.setCacheConfiguration(cacheCfg);
+
+ cfg.setMarshaller(new PortableMarshaller());
+
+ return cfg;
+ }
+
+ /**
+ * @return {@code True} if should use OFFHEAP_TIERED mode.
+ */
+ protected boolean offheapTiered() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGridsMultiThreaded(gridCount());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ for (int i = 0; i < gridCount(); i++) {
+ GridCacheAdapter<Object, Object> c = ((IgniteKernal)grid(i)).internalCache();
+
+ for (GridCacheEntryEx e : c.map().entries0()) {
+ Object key = e.key().value(c.context().cacheObjectContext(), false);
+ Object val = CU.value(e.rawGet(), c.context(), false);
+
+ if (key instanceof PortableObject)
+ assert ((PortableObjectImpl)key).detached() : val;
+
+ if (val instanceof PortableObject)
+ assert ((PortableObjectImpl)val).detached() : val;
+ }
+ }
+
+ IgniteCache<Object, Object> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.remove(i);
+
+ if (offheapTiered()) {
+ for (int k = 0; k < 100; k++)
+ c.remove(k);
+ }
+
+ assertEquals(0, c.size());
+ }
+
+ /**
+ * @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 abstract int gridCount();
+
+ /**
+ * @throws Exception If failed.
+ */
+ @SuppressWarnings("unchecked")
+ public void testCircularReference() throws Exception {
+ IgniteCache c = keepPortableCache();
+
+ TestReferenceObject obj1 = new TestReferenceObject();
+
+ obj1.obj = new TestReferenceObject(obj1);
+
+ c.put(1, obj1);
+
+ PortableObject po = (PortableObject)c.get(1);
+
+ String str = po.toString();
+
+ log.info("toString: " + str);
+
+ assertNotNull(str);
+
+ assertTrue("Unexpected toString: " + str,
+ str.startsWith("TestReferenceObject") && str.contains("obj=TestReferenceObject ["));
+
+ TestReferenceObject obj1_r = po.deserialize();
+
+ assertNotNull(obj1_r);
+
+ TestReferenceObject obj2_r = obj1_r.obj;
+
+ assertNotNull(obj2_r);
+
+ assertSame(obj1_r, obj2_r.obj);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGet() throws Exception {
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ TestObject obj = c.get(i);
+
+ assertEquals(i, obj.val);
+ }
+
+ IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ PortableObject po = kpc.get(i);
+
+ assertEquals(i, (int)po.field("val"));
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testIterator() throws Exception {
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ Map<Integer, TestObject> entries = new HashMap<>();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ TestObject val = new TestObject(i);
+
+ c.put(i, val);
+
+ entries.put(i, val);
+ }
+
+ IgniteCache<Integer, PortableObject> prj = ((IgniteCacheProxy)c).keepPortable();
+
+ Iterator<Cache.Entry<Integer, PortableObject>> it = prj.iterator();
+
+ assertTrue(it.hasNext());
+
+ while (it.hasNext()) {
+ Cache.Entry<Integer, PortableObject> entry = it.next();
+
+ assertTrue(entries.containsKey(entry.getKey()));
+
+ TestObject o = entries.get(entry.getKey());
+
+ PortableObject po = entry.getValue();
+
+ assertEquals(o.val, (int)po.field("val"));
+
+ entries.remove(entry.getKey());
+ }
+
+ assertEquals(0, entries.size());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCollection() throws Exception {
+ IgniteCache<Integer, Collection<TestObject>> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ Collection<TestObject> col = new ArrayList<>(3);
+
+ for (int j = 0; j < 3; j++)
+ col.add(new TestObject(i * 10 + j));
+
+ c.put(i, col);
+ }
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ Collection<TestObject> col = c.get(i);
+
+ assertEquals(3, col.size());
+
+ Iterator<TestObject> it = col.iterator();
+
+ for (int j = 0; j < 3; j++) {
+ assertTrue(it.hasNext());
+
+ assertEquals(i * 10 + j, it.next().val);
+ }
+ }
+
+ IgniteCache<Integer, Collection<PortableObject>> kpc = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ Collection<PortableObject> col = kpc.get(i);
+
+ assertEquals(3, col.size());
+
+ Iterator<PortableObject> it = col.iterator();
+
+ for (int j = 0; j < 3; j++) {
+ assertTrue(it.hasNext());
+
+ assertEquals(i * 10 + j, (int)it.next().field("val"));
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMap() throws Exception {
+ IgniteCache<Integer, Map<Integer, TestObject>> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ Map<Integer, TestObject> map = U.newHashMap(3);
+
+ for (int j = 0; j < 3; j++) {
+ int idx = i * 10 + j;
+
+ map.put(idx, new TestObject(idx));
+ }
+
+ c.put(i, map);
+ }
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ Map<Integer, TestObject> map = c.get(i);
+
+ assertEquals(3, map.size());
+
+ for (int j = 0; j < 3; j++) {
+ int idx = i * 10 + j;
+
+ assertEquals(idx, map.get(idx).val);
+ }
+ }
+
+ IgniteCache<Integer, Map<Integer, PortableObject>> kpc = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ Map<Integer, PortableObject> map = kpc.get(i);
+
+ assertEquals(3, map.size());
+
+ for (int j = 0; j < 3; j++) {
+ int idx = i * 10 + j;
+
+ assertEquals(idx, (int)map.get(idx).field("val"));
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAsync() throws Exception {
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ cacheAsync.get(i);
+ TestObject obj = cacheAsync.<TestObject>future().get();
+
+ assertEquals(i, obj.val);
+ }
+
+ IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
+
+ IgniteCache<Integer, PortableObject> cachePortableAsync = kpc.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ cachePortableAsync.get(i);
+
+ PortableObject po = cachePortableAsync.<PortableObject>future().get();
+
+ assertEquals(i, (int)po.field("val"));
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetTx() throws Exception {
+ if (atomicityMode() != TRANSACTIONAL)
+ return;
+
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ TestObject obj = c.get(i);
+
+ assertEquals(i, obj.val);
+
+ tx.commit();
+ }
+ }
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+ TestObject obj = c.get(i);
+
+ assertEquals(i, obj.val);
+
+ tx.commit();
+ }
+ }
+
+ IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ PortableObject po = kpc.get(i);
+
+ assertEquals(i, (int)po.field("val"));
+
+ tx.commit();
+ }
+ }
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+ PortableObject po = kpc.get(i);
+
+ assertEquals(i, (int)po.field("val"));
+
+ tx.commit();
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAsyncTx() throws Exception {
+ if (atomicityMode() != TRANSACTIONAL)
+ return;
+
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ cacheAsync.get(i);
+
+ TestObject obj = cacheAsync.<TestObject>future().get();
+
+ assertEquals(i, obj.val);
+
+ tx.commit();
+ }
+ }
+
+ IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
+ IgniteCache<Integer, PortableObject> cachePortableAsync = kpc.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; i++) {
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ cachePortableAsync.get(i);
+
+ PortableObject po = cachePortableAsync.<PortableObject>future().get();
+
+ assertEquals(i, (int)po.field("val"));
+
+ tx.commit();
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAll() throws Exception {
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ Map<Integer, TestObject> objs = c.getAll(keys);
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+ assertEquals(e.getKey().intValue(), e.getValue().val);
+ }
+
+ IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ Map<Integer, PortableObject> objs = kpc.getAll(keys);
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, PortableObject> e : objs.entrySet())
+ assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAllAsync() throws Exception {
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ cacheAsync.getAll(keys);
+
+ Map<Integer, TestObject> objs = cacheAsync.<Map<Integer, TestObject>>future().get();
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+ assertEquals(e.getKey().intValue(), e.getValue().val);
+ }
+
+ IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
+ IgniteCache<Integer, PortableObject> cachePortableAsync = kpc.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+
+ cachePortableAsync.getAll(keys);
+
+ Map<Integer, PortableObject> objs = cachePortableAsync.<Map<Integer, PortableObject>>future().get();
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, PortableObject> e : objs.entrySet())
+ assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAllTx() throws Exception {
+ if (atomicityMode() != TRANSACTIONAL)
+ return;
+
+ IgniteCache<Integer, TestObject> c = jcache(0);
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ Map<Integer, TestObject> objs = c.getAll(keys);
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+ assertEquals(e.getKey().intValue(), e.getValue().val);
+
+ tx.commit();
+ }
+
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+ Map<Integer, TestObject> objs = c.getAll(keys);
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+ assertEquals(e.getKey().intValue(), e.getValue().val);
+
+ tx.commit();
+ }
+ }
+
+ IgniteCache<Integer, PortableObject> kpc = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ Map<Integer, PortableObject> objs = kpc.getAll(keys);
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, PortableObject> e : objs.entrySet())
+ assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+
+ tx.commit();
+ }
+
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+ Map<Integer, PortableObject> objs = kpc.getAll(keys);
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, PortableObject> e : objs.entrySet())
+ assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+
+ tx.commit();
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAllAsyncTx() throws Exception {
+ if (atomicityMode() != TRANSACTIONAL)
+ return;
+
+ IgniteCache<Integer, TestObject> c = jcache(0);
+ IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
+
+ for (int i = 0; i < ENTRY_CNT; i++)
+ c.put(i, new TestObject(i));
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ cacheAsync.getAll(keys);
+
+ Map<Integer, TestObject> objs = cacheAsync.<Map<Integer, TestObject>>future().get();
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+ assertEquals(e.getKey().intValue(), e.getValue().val);
+
+ tx.commit();
+ }
+ }
+
+ IgniteCache<Integer, PortableObject> cache = keepPortableCache();
+
+ for (int i = 0; i < ENTRY_CNT; ) {
+ Set<Integer> keys = new HashSet<>();
+
+ for (int j = 0; j < 10; j++)
+ keys.add(i++);
+
+ IgniteCache<Integer, PortableObject> asyncCache = cache.withAsync();
+
+ try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+ asyncCache.getAll(keys);
+
+ Map<Integer, PortableObject> objs = asyncCache.<Map<Integer, PortableObject>>future().get();
+
+ assertEquals(10, objs.size());
+
+ for (Map.Entry<Integer, PortableObject> e : objs.entrySet())
+ assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+
+ tx.commit();
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLoadCache() throws Exception {
+ for (int i = 0; i < gridCount(); i++)
+ jcache(i).localLoadCache(null);
+
+ IgniteCache<Integer, TestObject> cache = jcache(0);
+
+ assertEquals(3, cache.size(CachePeekMode.PRIMARY));
+
+ assertEquals(1, cache.get(1).val);
+ assertEquals(2, cache.get(2).val);
+ assertEquals(3, cache.get(3).val);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLoadCacheAsync() throws Exception {
+ for (int i = 0; i < gridCount(); i++) {
+ IgniteCache<Object, Object> jcache = jcache(i).withAsync();
+
+ jcache.loadCache(null);
+
+ jcache.future().get();
+ }
+
+ IgniteCache<Integer, TestObject> cache = jcache(0);
+
+ assertEquals(3, cache.size(CachePeekMode.PRIMARY));
+
+ assertEquals(1, cache.get(1).val);
+ assertEquals(2, cache.get(2).val);
+ assertEquals(3, cache.get(3).val);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLoadCacheFilteredAsync() throws Exception {
+ for (int i = 0; i < gridCount(); i++) {
+ IgniteCache<Integer, TestObject> c = this.<Integer, TestObject>jcache(i).withAsync();
+
+ c.loadCache(new P2<Integer, TestObject>() {
+ @Override public boolean apply(Integer key, TestObject val) {
+ return val.val < 3;
+ }
+ });
+
+ c.future().get();
+ }
+
+ IgniteCache<Integer, TestObject> cache = jcache(0);
+
+ assertEquals(2, cache.size(CachePeekMode.PRIMARY));
+
+ assertEquals(1, cache.get(1).val);
+ assertEquals(2, cache.get(2).val);
+
+ assertNull(cache.get(3));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTransform() throws Exception {
+ IgniteCache<Integer, PortableObject> c = keepPortableCache();
+
+ checkTransform(primaryKey(c));
+
+ if (cacheMode() != CacheMode.LOCAL) {
+ checkTransform(backupKey(c));
+
+ if (nearConfiguration() != null)
+ checkTransform(nearKey(c));
+ }
+ }
+
+ /**
+ * @return Cache with keep portable flag.
+ */
+ private <K, V> IgniteCache<K, V> keepPortableCache() {
+ return ignite(0).cache(null).withKeepPortable();
+ }
+
+ /**
+ * @param key Key.
+ * @throws Exception If failed.
+ */
+ private void checkTransform(Integer key) throws Exception {
+ log.info("Transform: " + key);
+
+ IgniteCache<Integer, PortableObject> c = keepPortableCache();
+
+ try {
+ c.invoke(key, new EntryProcessor<Integer, PortableObject, Void>() {
+ @Override public Void process(MutableEntry<Integer, PortableObject> e, Object... args) {
+ PortableObject val = e.getValue();
+
+ assertNull("Unexpected value: " + val, val);
+
+ return null;
+ }
+ });
+
+ jcache(0).put(key, new TestObject(1));
+
+ c.invoke(key, new EntryProcessor<Integer, PortableObject, Void>() {
+ @Override public Void process(MutableEntry<Integer, PortableObject> e, Object... args) {
+ PortableObject val = e.getValue();
+
+ assertNotNull("Unexpected value: " + val, val);
+
+ assertEquals(new Integer(1), val.field("val"));
+
+ Ignite ignite = e.unwrap(Ignite.class);
+
+ IgnitePortables portables = ignite.portables();
+
+ PortableBuilder builder = portables.builder(val);
+
+ builder.setField("val", 2);
+
+ e.setValue(builder.build());
+
+ return null;
+ }
+ });
+
+ PortableObject obj = c.get(key);
+
+ assertEquals(new Integer(2), obj.field("val"));
+
+ c.invoke(key, new EntryProcessor<Integer, PortableObject, Void>() {
+ @Override public Void process(MutableEntry<Integer, PortableObject> e, Object... args) {
+ PortableObject val = e.getValue();
+
+ assertNotNull("Unexpected value: " + val, val);
+
+ assertEquals(new Integer(2), val.field("val"));
+
+ e.setValue(val);
+
+ return null;
+ }
+ });
+
+ obj = c.get(key);
+
+ assertEquals(new Integer(2), obj.field("val"));
+
+ c.invoke(key, new EntryProcessor<Integer, PortableObject, Void>() {
+ @Override public Void process(MutableEntry<Integer, PortableObject> e, Object... args) {
+ PortableObject val = e.getValue();
+
+ assertNotNull("Unexpected value: " + val, val);
+
+ assertEquals(new Integer(2), val.field("val"));
+
+ e.remove();
+
+ return null;
+ }
+ });
+
+ assertNull(c.get(key));
+ }
+ finally {
+ c.remove(key);
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestObject implements PortableMarshalAware {
+ /** */
+ private int val;
+
+ /**
+ */
+ private TestObject() {
+ // No-op.
+ }
+
+ /**
+ * @param val Value.
+ */
+ private TestObject(int val) {
+ this.val = val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writePortable(PortableWriter writer) throws PortableException {
+ writer.writeInt("val", val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(PortableReader reader) throws PortableException {
+ val = reader.readInt("val");
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestReferenceObject implements PortableMarshalAware {
+ /** */
+ private TestReferenceObject obj;
+
+ /**
+ */
+ private TestReferenceObject() {
+ // No-op.
+ }
+
+ /**
+ * @param obj Object.
+ */
+ private TestReferenceObject(TestReferenceObject obj) {
+ this.obj = obj;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writePortable(PortableWriter writer) throws PortableException {
+ writer.writeObject("obj", obj);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(PortableReader reader) throws PortableException {
+ obj = reader.readObject("obj");
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestStore extends CacheStoreAdapter<Integer, Object> {
+ /** {@inheritDoc} */
+ @Override public void loadCache(IgniteBiInClosure<Integer, Object> clo, Object... args) {
+ for (int i = 1; i <= 3; i++)
+ clo.apply(i, new TestObject(i));
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Object load(Integer key) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(Cache.Entry<? extends Integer, ?> e) {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override public void delete(Object key) {
+ // No-op.
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java
new file mode 100644
index 0000000..7c605b5
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java
@@ -0,0 +1,297 @@
+/*
+ * 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 com.google.common.collect.ImmutableSet;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.cache.Cache;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+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.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+
+/**
+ * Tests for cache store with portables.
+ */
+public abstract class GridCachePortableStoreAbstractSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private static final TestStore STORE = new TestStore();
+
+ /** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(Key.class.getName(), Value.class.getName()));
+
+ cfg.setMarshaller(marsh);
+
+ CacheConfiguration cacheCfg = new CacheConfiguration();
+
+ cacheCfg.setCacheStoreFactory(singletonFactory(STORE));
+ cacheCfg.setKeepPortableInStore(keepPortableInStore());
+ cacheCfg.setReadThrough(true);
+ cacheCfg.setWriteThrough(true);
+ cacheCfg.setLoadPreviousValue(true);
+
+ cfg.setCacheConfiguration(cacheCfg);
+
+ TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+ disco.setIpFinder(IP_FINDER);
+
+ cfg.setDiscoverySpi(disco);
+
+ return cfg;
+ }
+
+ /**
+ * @return Keep portables in store flag.
+ */
+ protected abstract boolean keepPortableInStore();
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGrid();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopGrid();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ STORE.map().clear();
+
+ jcache().clear();
+
+ assert jcache().size() == 0;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPut() throws Exception {
+ jcache().put(new Key(1), new Value(1));
+
+ checkMap(STORE.map(), 1);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPutAll() throws Exception {
+ Map<Object, Object> map = new HashMap<>();
+
+ for (int i = 1; i <= 3; i++)
+ map.put(new Key(i), new Value(i));
+
+ jcache().putAll(map);
+
+ checkMap(STORE.map(), 1, 2, 3);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLoad() throws Exception {
+ populateMap(STORE.map(), 1);
+
+ Object val = jcache().get(new Key(1));
+
+ assertTrue(String.valueOf(val), val instanceof Value);
+
+ assertEquals(1, ((Value)val).index());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLoadAll() throws Exception {
+ populateMap(STORE.map(), 1, 2, 3);
+
+ Set<Object> keys = new HashSet<>();
+
+ for (int i = 1; i <= 3; i++)
+ keys.add(new Key(i));
+
+ Map<Object, Object> res = jcache().getAll(keys);
+
+ assertEquals(3, res.size());
+
+ for (int i = 1; i <= 3; i++) {
+ Object val = res.get(new Key(i));
+
+ assertTrue(String.valueOf(val), val instanceof Value);
+
+ assertEquals(i, ((Value)val).index());
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testRemove() throws Exception {
+ for (int i = 1; i <= 3; i++)
+ jcache().put(new Key(i), new Value(i));
+
+ jcache().remove(new Key(1));
+
+ checkMap(STORE.map(), 2, 3);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testRemoveAll() throws Exception {
+ for (int i = 1; i <= 3; i++)
+ jcache().put(new Key(i), new Value(i));
+
+ jcache().removeAll(ImmutableSet.of(new Key(1), new Key(2)));
+
+ checkMap(STORE.map(), 3);
+ }
+
+ /**
+ * @param map Map.
+ * @param idxs Indexes.
+ */
+ protected abstract void populateMap(Map<Object, Object> map, int... idxs);
+
+ /**
+ * @param map Map.
+ * @param idxs Indexes.
+ */
+ protected abstract void checkMap(Map<Object, Object> map, int... idxs);
+
+ /**
+ */
+ protected static class Key {
+ /** */
+ private int idx;
+
+ /**
+ * @param idx Index.
+ */
+ public Key(int idx) {
+ this.idx = idx;
+ }
+
+ /**
+ * @return Index.
+ */
+ int index() {
+ return idx;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ Key key = (Key)o;
+
+ return idx == key.idx;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return idx;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "Key [idx=" + idx + ']';
+ }
+ }
+
+ /**
+ */
+ protected static class Value {
+ /** */
+ private int idx;
+
+ /**
+ * @param idx Index.
+ */
+ public Value(int idx) {
+ this.idx = idx;
+ }
+
+ /**
+ * @return Index.
+ */
+ int index() {
+ return idx;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "Value [idx=" + idx + ']';
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestStore extends CacheStoreAdapter<Object, Object> {
+ /** */
+ private final Map<Object, Object> map = new ConcurrentHashMap8<>();
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Object load(Object key) {
+ return map.get(key);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(Cache.Entry<?, ?> e) {
+ map.put(e.getKey(), e.getValue());
+ }
+
+ /** {@inheritDoc} */
+ @Override public void delete(Object key) {
+ map.remove(key);
+ }
+
+ /**
+ * @return Map.
+ */
+ Map<Object, Object> map() {
+ return map;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java
new file mode 100644
index 0000000..1c1c99e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.Map;
+
+/**
+ * Tests for cache store with portables.
+ */
+public class GridCachePortableStoreObjectsSelfTest extends GridCachePortableStoreAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean keepPortableInStore() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void populateMap(Map<Object, Object> map, int... idxs) {
+ assert map != null;
+ assert idxs != null;
+
+ for (int idx : idxs)
+ map.put(new Key(idx), new Value(idx));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void checkMap(Map<Object, Object> map, int... idxs) {
+ assert map != null;
+ assert idxs != null;
+
+ assertEquals(idxs.length, map.size());
+
+ for (int idx : idxs) {
+ Object val = map.get(new Key(idx));
+
+ assertTrue(String.valueOf(val), val instanceof Value);
+
+ assertEquals(idx, ((Value)val).index());
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java
new file mode 100644
index 0000000..5c0fc8e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.Map;
+import org.apache.ignite.portable.PortableObject;
+
+/**
+ * Tests for cache store with portables.
+ */
+public class GridCachePortableStorePortablesSelfTest extends GridCachePortableStoreAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean keepPortableInStore() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void populateMap(Map<Object, Object> map, int... idxs) {
+ assert map != null;
+ assert idxs != null;
+
+ for (int idx : idxs)
+ map.put(portable(new Key(idx)), portable(new Value(idx)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void checkMap(Map<Object, Object> map, int... idxs) {
+ assert map != null;
+ assert idxs != null;
+
+ assertEquals(idxs.length, map.size());
+
+ for (int idx : idxs) {
+ Object val = map.get(portable(new Key(idx)));
+
+ assertTrue(String.valueOf(val), val instanceof PortableObject);
+
+ PortableObject po = (PortableObject)val;
+
+ assertEquals("Value", po.metaData().typeName());
+ assertEquals(new Integer(idx), po.field("idx"));
+ }
+ }
+
+ /**
+ * @param obj Object.
+ * @return Portable object.
+ */
+ private Object portable(Object obj) {
+ return grid().portables().toPortable(obj);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java
new file mode 100644
index 0000000..0db650e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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 org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.portable.PortableContext;
+import org.apache.ignite.internal.portable.PortableMetaDataHandler;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryMemorySizeSelfTest;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMetadata;
+
+/**
+ *
+ */
+public class GridPortableCacheEntryMemorySizeSelfTest extends GridCacheEntryMemorySizeSelfTest {
+ /** {@inheritDoc} */
+ @Override protected Marshaller createMarshaller() throws IgniteCheckedException {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setContext(new MarshallerContextTestImpl(null));
+
+ PortableContext pCtx = new PortableContext(new PortableMetaDataHandler() {
+ @Override public void addMeta(int typeId, PortableMetadata meta) throws PortableException {
+ // No-op
+ }
+
+ @Override public PortableMetadata metadata(int typeId) throws PortableException {
+ return null;
+ }
+ }, null);
+
+ IgniteUtils.invoke(PortableMarshaller.class, marsh, "setPortableContext", pCtx);
+
+ return marsh;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
new file mode 100644
index 0000000..a1a623b
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
@@ -0,0 +1,158 @@
+/*
+ * 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.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheTypeMetadata;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableObject;
+
+/**
+ * Tests that portable object is the same in cache entry and in index.
+ */
+public abstract class GridPortableDuplicateIndexObjectsAbstractSelfTest extends GridCacheAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 1;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Collections.singletonList(TestPortable.class.getName()));
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
+ CacheConfiguration ccfg = super.cacheConfiguration(gridName);
+
+ ccfg.setCopyOnRead(false);
+
+ CacheTypeMetadata meta = new CacheTypeMetadata();
+
+ meta.setKeyType(Integer.class);
+ meta.setValueType(TestPortable.class.getName());
+
+ Map<String, Class<?>> idx = new HashMap<>();
+
+ idx.put("fieldOne", String.class);
+ idx.put("fieldTwo", Integer.class);
+
+ meta.setAscendingFields(idx);
+
+ ccfg.setTypeMetadata(Collections.singletonList(meta));
+
+ return ccfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override public abstract CacheAtomicityMode atomicityMode();
+
+ /** {@inheritDoc} */
+ @Override public abstract CacheMode cacheMode();
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testIndexReferences() throws Exception {
+ IgniteCache<Integer, TestPortable> cache = grid(0).cache(null);
+
+ String fieldOneVal = "123";
+ int fieldTwoVal = 123;
+ int key = 0;
+
+ cache.put(key, new TestPortable(fieldOneVal, fieldTwoVal));
+
+ IgniteCache<Integer, PortableObject> prj = grid(0).cache(null).withKeepPortable();
+
+ PortableObject cacheVal = prj.get(key);
+
+ assertEquals(fieldOneVal, cacheVal.field("fieldOne"));
+ assertEquals(new Integer(fieldTwoVal), cacheVal.field("fieldTwo"));
+
+ List<?> row = F.first(prj.query(new SqlFieldsQuery("select _val from " +
+ "TestPortable where _key = ?").setArgs(key)).getAll());
+
+ assertEquals(1, row.size());
+
+ PortableObject qryVal = (PortableObject)row.get(0);
+
+ assertEquals(fieldOneVal, qryVal.field("fieldOne"));
+ assertEquals(new Integer(fieldTwoVal), qryVal.field("fieldTwo"));
+ assertSame(cacheVal, qryVal);
+ }
+
+ /**
+ * Test portable object.
+ */
+ private static class TestPortable {
+ /** */
+ private String fieldOne;
+
+ /** */
+ private int fieldTwo;
+
+ /**
+ *
+ */
+ private TestPortable() {
+ // No-op.
+ }
+
+ /**
+ * @param fieldOne Field one.
+ * @param fieldTwo Field two.
+ */
+ private TestPortable(String fieldOne, int fieldTwo) {
+ this.fieldOne = fieldOne;
+ this.fieldTwo = fieldTwo;
+ }
+
+ /**
+ * @return Field one.
+ */
+ public String fieldOne() {
+ return fieldOne;
+ }
+
+ /**
+ * @return Field two.
+ */
+ public int fieldTwo() {
+ return fieldTwo;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java
new file mode 100644
index 0000000..836440a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.datastreaming;
+
+import java.util.Collection;
+import java.util.Map;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.stream.StreamReceiver;
+
+/**
+ *
+ */
+public class DataStreamProcessorPortableSelfTest extends DataStreamProcessorSelfTest {
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected StreamReceiver<String, TestObject> getStreamReceiver() {
+ return new TestDataReceiver();
+ }
+
+ /**
+ *
+ */
+ private static class TestDataReceiver implements StreamReceiver<String, TestObject> {
+ /** {@inheritDoc} */
+ @Override public void receive(IgniteCache<String, TestObject> cache,
+ Collection<Map.Entry<String, TestObject>> entries) {
+ for (Map.Entry<String, TestObject> e : entries) {
+ assertTrue(e.getKey() instanceof String);
+ assertTrue(e.getValue() instanceof PortableObject);
+
+ TestObject obj = ((PortableObject)e.getValue()).deserialize();
+
+ cache.put(e.getKey(), new TestObject(obj.val + 1));
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java
new file mode 100644
index 0000000..2f7bdb0
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java
@@ -0,0 +1,345 @@
+/*
+ * 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.datastreaming;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Random;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMarshalAware;
+import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.portable.PortableReader;
+import org.apache.ignite.portable.PortableWriter;
+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.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ * Tests for {@code IgniteDataStreamerImpl}.
+ */
+public class GridDataStreamerImplSelfTest extends GridCommonAbstractTest {
+ /** IP finder. */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** Number of keys to load via data streamer. */
+ private static final int KEYS_COUNT = 1000;
+
+ /** Flag indicating should be cache configured with portables or not. */
+ private static boolean portables;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+ discoSpi.setIpFinder(IP_FINDER);
+
+ cfg.setDiscoverySpi(discoSpi);
+
+ if (portables) {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ cfg.setMarshaller(marsh);
+ }
+
+ cfg.setCacheConfiguration(cacheConfiguration());
+
+ return cfg;
+ }
+
+ /**
+ * Gets cache configuration.
+ *
+ * @return Cache configuration.
+ */
+ private CacheConfiguration cacheConfiguration() {
+ CacheConfiguration cacheCfg = defaultCacheConfiguration();
+
+ cacheCfg.setCacheMode(PARTITIONED);
+ cacheCfg.setNearConfiguration(null);
+ cacheCfg.setBackups(0);
+ cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
+
+ return cacheCfg;
+ }
+
+ /**
+ * Data streamer should correctly load entries from HashMap in case of grids with more than one node
+ * and with GridOptimizedMarshaller that requires serializable.
+ *
+ * @throws Exception If failed.
+ */
+ public void testAddDataFromMap() throws Exception {
+ try {
+ portables = false;
+
+ startGrids(2);
+
+ awaitPartitionMapExchange();
+
+ Ignite g0 = grid(0);
+
+ IgniteDataStreamer<Integer, String> dataLdr = g0.dataStreamer(null);
+
+ Map<Integer, String> map = U.newHashMap(KEYS_COUNT);
+
+ for (int i = 0; i < KEYS_COUNT; i ++)
+ map.put(i, String.valueOf(i));
+
+ dataLdr.addData(map);
+
+ dataLdr.close();
+
+ checkDistribution(grid(0));
+
+ checkDistribution(grid(1));
+
+ // Check several random keys in cache.
+ Random rnd = new Random();
+
+ IgniteCache<Integer, String> c0 = g0.cache(null);
+
+ for (int i = 0; i < 100; i ++) {
+ Integer k = rnd.nextInt(KEYS_COUNT);
+
+ String v = c0.get(k);
+
+ assertEquals(k.toString(), v);
+ }
+ }
+ finally {
+ G.stopAll(true);
+ }
+ }
+
+ /**
+ * Data streamer should add portable object that weren't registered explicitly.
+ *
+ * @throws Exception If failed.
+ */
+ public void testAddMissingPortable() throws Exception {
+ try {
+ portables = true;
+
+ startGrids(2);
+
+ awaitPartitionMapExchange();
+
+ Ignite g0 = grid(0);
+
+ IgniteDataStreamer<Integer, TestObject2> dataLdr = g0.dataStreamer(null);
+
+ dataLdr.perNodeBufferSize(1);
+ dataLdr.autoFlushFrequency(1L);
+
+ Map<Integer, TestObject2> map = U.newHashMap(KEYS_COUNT);
+
+ for (int i = 0; i < KEYS_COUNT; i ++)
+ map.put(i, new TestObject2(i));
+
+ dataLdr.addData(map).get();
+
+ dataLdr.close();
+ }
+ finally {
+ G.stopAll(true);
+ }
+ }
+
+ /**
+ * Data streamer should correctly load portable entries from HashMap in case of grids with more than one node
+ * and with GridOptimizedMarshaller that requires serializable.
+ *
+ * @throws Exception If failed.
+ */
+ public void testAddPortableDataFromMap() throws Exception {
+ try {
+ portables = true;
+
+ startGrids(2);
+
+ awaitPartitionMapExchange();
+
+ Ignite g0 = grid(0);
+
+ IgniteDataStreamer<Integer, TestObject> dataLdr = g0.dataStreamer(null);
+
+ Map<Integer, TestObject> map = U.newHashMap(KEYS_COUNT);
+
+ for (int i = 0; i < KEYS_COUNT; i ++)
+ map.put(i, new TestObject(i));
+
+ dataLdr.addData(map);
+
+ dataLdr.close(false);
+
+ checkDistribution(grid(0));
+
+ checkDistribution(grid(1));
+
+ // Read random keys. Take values as TestObject.
+ Random rnd = new Random();
+
+ IgniteCache<Integer, TestObject> c = g0.cache(null);
+
+ for (int i = 0; i < 100; i ++) {
+ Integer k = rnd.nextInt(KEYS_COUNT);
+
+ TestObject v = c.get(k);
+
+ assertEquals(k, v.val());
+ }
+
+ // Read random keys. Take values as PortableObject.
+ IgniteCache<Integer, PortableObject> c2 = ((IgniteCacheProxy)c).keepPortable();
+
+ for (int i = 0; i < 100; i ++) {
+ Integer k = rnd.nextInt(KEYS_COUNT);
+
+ PortableObject v = c2.get(k);
+
+ assertEquals(k, v.field("val"));
+ }
+ }
+ finally {
+ G.stopAll(true);
+ }
+ }
+
+ /**
+ * Check that keys correctly destributed by nodes after data streamer.
+ *
+ * @param g Grid to check.
+ */
+ private void checkDistribution(Ignite g) {
+ ClusterNode n = g.cluster().localNode();
+ IgniteCache c = g.cache(null);
+
+ // Check that data streamer correctly split data by nodes.
+ for (int i = 0; i < KEYS_COUNT; i ++) {
+ if (g.affinity(null).isPrimary(n, i))
+ assertNotNull(c.localPeek(i, CachePeekMode.ONHEAP));
+ else
+ assertNull(c.localPeek(i, CachePeekMode.ONHEAP));
+ }
+ }
+
+ /**
+ */
+ private static class TestObject implements PortableMarshalAware, Serializable {
+ /** */
+ private int val;
+
+ /**
+ *
+ */
+ private TestObject() {
+ // No-op.
+ }
+
+ /**
+ * @param val Value.
+ */
+ private TestObject(int val) {
+ this.val = val;
+ }
+
+ public Integer val() {
+ return 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(PortableWriter writer) throws PortableException {
+ writer.writeInt("val", val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(PortableReader reader) throws PortableException {
+ val = reader.readInt("val");
+ }
+ }
+
+ /**
+ */
+ private static class TestObject2 implements PortableMarshalAware, Serializable {
+ /** */
+ private int val;
+
+ /**
+ */
+ private TestObject2() {
+ // No-op.
+ }
+
+ /**
+ * @param val Value.
+ */
+ private TestObject2(int val) {
+ this.val = val;
+ }
+
+ public Integer val() {
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object obj) {
+ return obj instanceof TestObject2 && ((TestObject2)obj).val == val;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writePortable(PortableWriter writer) throws PortableException {
+ writer.writeInt("val", val);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(PortableReader reader) throws PortableException {
+ val = reader.readInt("val");
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
new file mode 100644
index 0000000..155ba48
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.distributed.dht;
+
+import java.util.Collections;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheAffinityRoutingSelfTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableTypeConfiguration;
+
+/**
+ *
+ */
+public class GridCacheAffinityRoutingPortableSelfTest extends GridCacheAffinityRoutingSelfTest {
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableTypeConfiguration typeCfg = new PortableTypeConfiguration();
+
+ typeCfg.setClassName(AffinityTestKey.class.getName());
+ typeCfg.setAffinityKeyFieldName("affKey");
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Collections.singleton(typeCfg));
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java
new file mode 100644
index 0000000..b3b988e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest extends
+ GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest {
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 4;
+ }
+}
\ No newline at end of file
[05/11] ignite git commit: Revert "ignite-1462: hid portable API in
1.4 release" This reverts commit 71379a8061f50f336adc31fa20cd593b659b050f.
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
new file mode 100644
index 0000000..21fc81c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
@@ -0,0 +1,3807 @@
+/*
+ * 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;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.InetSocketAddress;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentSkipListSet;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.portable.builder.PortableBuilderImpl;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.lang.GridMapEntry;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableBuilder;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableIdMapper;
+import org.apache.ignite.portable.PortableInvalidClassException;
+import org.apache.ignite.portable.PortableMarshalAware;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.portable.PortableRawReader;
+import org.apache.ignite.portable.PortableRawWriter;
+import org.apache.ignite.portable.PortableReader;
+import org.apache.ignite.portable.PortableSerializer;
+import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.apache.ignite.portable.PortableWriter;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jsr166.ConcurrentHashMap8;
+import sun.misc.Unsafe;
+
+import static org.apache.ignite.internal.portable.PortableThreadLocalMemoryAllocator.THREAD_LOCAL_ALLOC;
+import static org.junit.Assert.assertArrayEquals;
+
+/**
+ * Portable marshaller tests.
+ */
+@SuppressWarnings({"OverlyStrongTypeCast", "ArrayHashCode", "ConstantConditions"})
+public class GridPortableMarshallerSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+ /** */
+ protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+ /** */
+ protected static final PortableMetaDataHandler META_HND = new PortableMetaDataHandler() {
+ @Override public void addMeta(int typeId, PortableMetadata meta) {
+ // No-op.
+ }
+
+ @Override public PortableMetadata metadata(int typeId) {
+ return null;
+ }
+ };
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testNull() throws Exception {
+ assertNull(marshalUnmarshal(null));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testByte() throws Exception {
+ assertEquals((byte)100, marshalUnmarshal((byte)100).byteValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testShort() throws Exception {
+ assertEquals((short)100, marshalUnmarshal((short)100).shortValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testInt() throws Exception {
+ assertEquals(100, marshalUnmarshal(100).intValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLong() throws Exception {
+ assertEquals(100L, marshalUnmarshal(100L).longValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFloat() throws Exception {
+ assertEquals(100.001f, marshalUnmarshal(100.001f).floatValue(), 0);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDouble() throws Exception {
+ assertEquals(100.001d, marshalUnmarshal(100.001d).doubleValue(), 0);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testChar() throws Exception {
+ assertEquals((char)100, marshalUnmarshal((char)100).charValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBoolean() throws Exception {
+ assertEquals(true, marshalUnmarshal(true).booleanValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDecimal() throws Exception {
+ BigDecimal val;
+
+ assertEquals((val = BigDecimal.ZERO), marshalUnmarshal(val));
+ assertEquals((val = BigDecimal.valueOf(Long.MAX_VALUE, 0)), marshalUnmarshal(val));
+ assertEquals((val = BigDecimal.valueOf(Long.MIN_VALUE, 0)), marshalUnmarshal(val));
+ assertEquals((val = BigDecimal.valueOf(Long.MAX_VALUE, 8)), marshalUnmarshal(val));
+ assertEquals((val = BigDecimal.valueOf(Long.MIN_VALUE, 8)), marshalUnmarshal(val));
+
+ assertEquals((val = new BigDecimal(new BigInteger("-79228162514264337593543950336"))), marshalUnmarshal(val));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testString() throws Exception {
+ assertEquals("str", marshalUnmarshal("str"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testUuid() throws Exception {
+ UUID uuid = UUID.randomUUID();
+
+ assertEquals(uuid, marshalUnmarshal(uuid));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDate() throws Exception {
+ Date date = new Date();
+
+ Date val = marshalUnmarshal(date);
+
+ assertEquals(date, val);
+ assertEquals(Timestamp.class, val.getClass()); // With default configuration should unmarshal as Timestamp.
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setUseTimestamp(false);
+
+ val = marshalUnmarshal(date, marsh);
+
+ assertEquals(date, val);
+ assertEquals(Date.class, val.getClass());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTimestamp() throws Exception {
+ Timestamp ts = new Timestamp(System.currentTimeMillis());
+
+ ts.setNanos(999999999);
+
+ assertEquals(ts, marshalUnmarshal(ts));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testByteArray() throws Exception {
+ byte[] arr = new byte[] {10, 20, 30};
+
+ assertArrayEquals(arr, marshalUnmarshal(arr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testShortArray() throws Exception {
+ short[] arr = new short[] {10, 20, 30};
+
+ assertArrayEquals(arr, marshalUnmarshal(arr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testIntArray() throws Exception {
+ int[] arr = new int[] {10, 20, 30};
+
+ assertArrayEquals(arr, marshalUnmarshal(arr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLongArray() throws Exception {
+ long[] arr = new long[] {10, 20, 30};
+
+ assertArrayEquals(arr, marshalUnmarshal(arr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFloatArray() throws Exception {
+ float[] arr = new float[] {10.1f, 20.1f, 30.1f};
+
+ assertArrayEquals(arr, marshalUnmarshal(arr), 0);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDoubleArray() throws Exception {
+ double[] arr = new double[] {10.1d, 20.1d, 30.1d};
+
+ assertArrayEquals(arr, marshalUnmarshal(arr), 0);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCharArray() throws Exception {
+ char[] arr = new char[] {10, 20, 30};
+
+ assertArrayEquals(arr, marshalUnmarshal(arr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBooleanArray() throws Exception {
+ boolean[] arr = new boolean[] {true, false, true};
+
+ assertBooleanArrayEquals(arr, marshalUnmarshal(arr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDecimalArray() throws Exception {
+ BigDecimal[] arr = new BigDecimal[] { BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN } ;
+
+ assertArrayEquals(arr, marshalUnmarshal(arr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testStringArray() throws Exception {
+ String[] arr = new String[] {"str1", "str2", "str3"};
+
+ assertArrayEquals(arr, marshalUnmarshal(arr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testUuidArray() throws Exception {
+ UUID[] arr = new UUID[] {UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()};
+
+ assertArrayEquals(arr, marshalUnmarshal(arr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDateArray() throws Exception {
+ Date[] arr = new Date[] {new Date(11111), new Date(22222), new Date(33333)};
+
+ assertArrayEquals(arr, marshalUnmarshal(arr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testObjectArray() throws Exception {
+ Object[] arr = new Object[] {1, 2, 3};
+
+ assertArrayEquals(arr, marshalUnmarshal(arr));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCollection() throws Exception {
+ testCollection(new ArrayList<Integer>(3));
+ testCollection(new LinkedHashSet<Integer>());
+ testCollection(new HashSet<Integer>());
+ testCollection(new TreeSet<Integer>());
+ testCollection(new ConcurrentSkipListSet<Integer>());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ private void testCollection(Collection<Integer> col) throws Exception {
+ col.add(1);
+ col.add(2);
+ col.add(3);
+
+ assertEquals(col, marshalUnmarshal(col));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMap() throws Exception {
+ testMap(new HashMap<Integer, String>());
+ testMap(new LinkedHashMap());
+ testMap(new TreeMap<Integer, String>());
+ testMap(new ConcurrentHashMap8<Integer, String>());
+ testMap(new ConcurrentHashMap<Integer, String>());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ private void testMap(Map<Integer, String> map) throws Exception {
+ map.put(1, "str1");
+ map.put(2, "str2");
+ map.put(3, "str3");
+
+ assertEquals(map, marshalUnmarshal(map));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMapEntry() throws Exception {
+ Map.Entry<Integer, String> e = new GridMapEntry<>(1, "str1");
+
+ assertEquals(e, marshalUnmarshal(e));
+
+ Map<Integer, String> map = new HashMap<>(1);
+
+ map.put(2, "str2");
+
+ e = F.firstEntry(map);
+
+ Map.Entry<Integer, String> e0 = marshalUnmarshal(e);
+
+ assertEquals(2, e0.getKey().intValue());
+ assertEquals("str2", e0.getValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableObject() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(new PortableTypeConfiguration(SimpleObject.class.getName())));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ PortableObject po0 = marshalUnmarshal(po, marsh);
+
+ assertTrue(po.hasField("b"));
+ assertTrue(po.hasField("s"));
+ assertTrue(po.hasField("i"));
+ assertTrue(po.hasField("l"));
+ assertTrue(po.hasField("f"));
+ assertTrue(po.hasField("d"));
+ assertTrue(po.hasField("c"));
+ assertTrue(po.hasField("bool"));
+
+ assertFalse(po.hasField("no_such_field"));
+
+ assertEquals(obj, po.deserialize());
+ assertEquals(obj, po0.deserialize());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testEnum() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(TestEnum.class.getName()));
+
+ assertEquals(TestEnum.B, marshalUnmarshal(TestEnum.B, marsh));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testUseTimestampFlag() throws Exception {
+ PortableTypeConfiguration cfg1 = new PortableTypeConfiguration(DateClass1.class.getName());
+
+ PortableTypeConfiguration cfg2 = new PortableTypeConfiguration(DateClass2.class.getName());
+
+ cfg2.setUseTimestamp(false);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(cfg1, cfg2));
+
+ Date date = new Date();
+ Timestamp ts = new Timestamp(System.currentTimeMillis());
+
+ DateClass1 obj1 = new DateClass1();
+ obj1.date = date;
+ obj1.ts = ts;
+
+ DateClass2 obj2 = new DateClass2();
+ obj2.date = date;
+ obj2.ts = ts;
+
+ PortableObject po1 = marshal(obj1, marsh);
+
+ assertEquals(date, po1.field("date"));
+ assertEquals(Timestamp.class, po1.field("date").getClass());
+ assertEquals(ts, po1.field("ts"));
+
+ PortableObject po2 = marshal(obj2, marsh);
+
+ assertEquals(date, po2.field("date"));
+ assertEquals(Date.class, po2.field("date").getClass());
+ assertEquals(new Date(ts.getTime()), po2.field("ts"));
+ assertEquals(Date.class, po2.field("ts").getClass());
+
+ obj1 = po1.deserialize();
+ assertEquals(date, obj1.date);
+ assertEquals(Date.class, obj1.date.getClass());
+ assertEquals(ts, obj1.ts);
+
+ obj2 = po2.deserialize();
+ assertEquals(date, obj2.date);
+ assertEquals(Date.class, obj2.date.getClass());
+ assertEquals(ts, obj2.ts);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testSimpleObject() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ assertEquals(obj.hashCode(), po.hashCode());
+
+ assertEquals(obj, po.deserialize());
+
+ assertEquals(obj.b, (byte)po.field("b"));
+ assertEquals(obj.s, (short)po.field("s"));
+ assertEquals(obj.i, (int)po.field("i"));
+ assertEquals(obj.l, (long)po.field("l"));
+ assertEquals(obj.f, (float)po.field("f"), 0);
+ assertEquals(obj.d, (double)po.field("d"), 0);
+ assertEquals(obj.c, (char)po.field("c"));
+ assertEquals(obj.bool, (boolean)po.field("bool"));
+ assertEquals(obj.str, po.field("str"));
+ assertEquals(obj.uuid, po.field("uuid"));
+ assertEquals(obj.date, po.field("date"));
+ assertEquals(Date.class, obj.date.getClass());
+ assertEquals(obj.ts, po.field("ts"));
+ assertArrayEquals(obj.bArr, (byte[])po.field("bArr"));
+ assertArrayEquals(obj.sArr, (short[])po.field("sArr"));
+ assertArrayEquals(obj.iArr, (int[])po.field("iArr"));
+ assertArrayEquals(obj.lArr, (long[])po.field("lArr"));
+ assertArrayEquals(obj.fArr, (float[])po.field("fArr"), 0);
+ assertArrayEquals(obj.dArr, (double[])po.field("dArr"), 0);
+ assertArrayEquals(obj.cArr, (char[])po.field("cArr"));
+ assertBooleanArrayEquals(obj.boolArr, (boolean[])po.field("boolArr"));
+ assertArrayEquals(obj.strArr, (String[])po.field("strArr"));
+ assertArrayEquals(obj.uuidArr, (UUID[])po.field("uuidArr"));
+ assertArrayEquals(obj.dateArr, (Date[])po.field("dateArr"));
+ assertArrayEquals(obj.objArr, (Object[])po.field("objArr"));
+ assertEquals(obj.col, po.field("col"));
+ assertEquals(obj.map, po.field("map"));
+ assertEquals(new Integer(obj.enumVal.ordinal()), new Integer(((Enum<?>)po.field("enumVal")).ordinal()));
+ assertArrayEquals(ordinals(obj.enumArr), ordinals((Enum<?>[])po.field("enumArr")));
+ assertNull(po.field("unknown"));
+
+ PortableObject innerPo = po.field("inner");
+
+ assertEquals(obj.inner, innerPo.deserialize());
+
+ assertEquals(obj.inner.b, (byte)innerPo.field("b"));
+ assertEquals(obj.inner.s, (short)innerPo.field("s"));
+ assertEquals(obj.inner.i, (int)innerPo.field("i"));
+ assertEquals(obj.inner.l, (long)innerPo.field("l"));
+ assertEquals(obj.inner.f, (float)innerPo.field("f"), 0);
+ assertEquals(obj.inner.d, (double)innerPo.field("d"), 0);
+ assertEquals(obj.inner.c, (char)innerPo.field("c"));
+ assertEquals(obj.inner.bool, (boolean)innerPo.field("bool"));
+ assertEquals(obj.inner.str, innerPo.field("str"));
+ assertEquals(obj.inner.uuid, innerPo.field("uuid"));
+ assertEquals(obj.inner.date, innerPo.field("date"));
+ assertEquals(Date.class, obj.inner.date.getClass());
+ assertEquals(obj.inner.ts, innerPo.field("ts"));
+ assertArrayEquals(obj.inner.bArr, (byte[])innerPo.field("bArr"));
+ assertArrayEquals(obj.inner.sArr, (short[])innerPo.field("sArr"));
+ assertArrayEquals(obj.inner.iArr, (int[])innerPo.field("iArr"));
+ assertArrayEquals(obj.inner.lArr, (long[])innerPo.field("lArr"));
+ assertArrayEquals(obj.inner.fArr, (float[])innerPo.field("fArr"), 0);
+ assertArrayEquals(obj.inner.dArr, (double[])innerPo.field("dArr"), 0);
+ assertArrayEquals(obj.inner.cArr, (char[])innerPo.field("cArr"));
+ assertBooleanArrayEquals(obj.inner.boolArr, (boolean[])innerPo.field("boolArr"));
+ assertArrayEquals(obj.inner.strArr, (String[])innerPo.field("strArr"));
+ assertArrayEquals(obj.inner.uuidArr, (UUID[])innerPo.field("uuidArr"));
+ assertArrayEquals(obj.inner.dateArr, (Date[])innerPo.field("dateArr"));
+ assertArrayEquals(obj.inner.objArr, (Object[])innerPo.field("objArr"));
+ assertEquals(obj.inner.col, innerPo.field("col"));
+ assertEquals(obj.inner.map, innerPo.field("map"));
+ assertEquals(new Integer(obj.inner.enumVal.ordinal()),
+ new Integer(((Enum<?>)innerPo.field("enumVal")).ordinal()));
+ assertArrayEquals(ordinals(obj.inner.enumArr), ordinals((Enum<?>[])innerPo.field("enumArr")));
+ assertNull(innerPo.field("inner"));
+ assertNull(innerPo.field("unknown"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortable() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName()),
+ new PortableTypeConfiguration(TestPortableObject.class.getName())
+ ));
+
+ TestPortableObject obj = portableObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ assertEquals(obj.hashCode(), po.hashCode());
+
+ assertEquals(obj, po.deserialize());
+
+ assertEquals(obj.b, (byte)po.field("_b"));
+ assertEquals(obj.s, (short)po.field("_s"));
+ assertEquals(obj.i, (int)po.field("_i"));
+ assertEquals(obj.l, (long)po.field("_l"));
+ assertEquals(obj.f, (float)po.field("_f"), 0);
+ assertEquals(obj.d, (double)po.field("_d"), 0);
+ assertEquals(obj.c, (char)po.field("_c"));
+ assertEquals(obj.bool, (boolean)po.field("_bool"));
+ assertEquals(obj.str, po.field("_str"));
+ assertEquals(obj.uuid, po.field("_uuid"));
+ assertEquals(obj.date, po.field("_date"));
+ assertEquals(obj.ts, po.field("_ts"));
+ assertArrayEquals(obj.bArr, (byte[])po.field("_bArr"));
+ assertArrayEquals(obj.sArr, (short[])po.field("_sArr"));
+ assertArrayEquals(obj.iArr, (int[])po.field("_iArr"));
+ assertArrayEquals(obj.lArr, (long[])po.field("_lArr"));
+ assertArrayEquals(obj.fArr, (float[])po.field("_fArr"), 0);
+ assertArrayEquals(obj.dArr, (double[])po.field("_dArr"), 0);
+ assertArrayEquals(obj.cArr, (char[])po.field("_cArr"));
+ assertBooleanArrayEquals(obj.boolArr, (boolean[])po.field("_boolArr"));
+ assertArrayEquals(obj.strArr, (String[])po.field("_strArr"));
+ assertArrayEquals(obj.uuidArr, (UUID[])po.field("_uuidArr"));
+ assertArrayEquals(obj.dateArr, (Date[])po.field("_dateArr"));
+ assertArrayEquals(obj.objArr, (Object[])po.field("_objArr"));
+ assertEquals(obj.col, po.field("_col"));
+ assertEquals(obj.map, po.field("_map"));
+ assertEquals(new Integer(obj.enumVal.ordinal()), new Integer(((Enum<?>)po.field("_enumVal")).ordinal()));
+ assertArrayEquals(ordinals(obj.enumArr), ordinals((Enum<?>[])po.field("_enumArr")));
+ assertNull(po.field("unknown"));
+
+ PortableObject simplePo = po.field("_simple");
+
+ assertEquals(obj.simple, simplePo.deserialize());
+
+ assertEquals(obj.simple.b, (byte)simplePo.field("b"));
+ assertEquals(obj.simple.s, (short)simplePo.field("s"));
+ assertEquals(obj.simple.i, (int)simplePo.field("i"));
+ assertEquals(obj.simple.l, (long)simplePo.field("l"));
+ assertEquals(obj.simple.f, (float)simplePo.field("f"), 0);
+ assertEquals(obj.simple.d, (double)simplePo.field("d"), 0);
+ assertEquals(obj.simple.c, (char)simplePo.field("c"));
+ assertEquals(obj.simple.bool, (boolean)simplePo.field("bool"));
+ assertEquals(obj.simple.str, simplePo.field("str"));
+ assertEquals(obj.simple.uuid, simplePo.field("uuid"));
+ assertEquals(obj.simple.date, simplePo.field("date"));
+ assertEquals(Date.class, obj.simple.date.getClass());
+ assertEquals(obj.simple.ts, simplePo.field("ts"));
+ assertArrayEquals(obj.simple.bArr, (byte[])simplePo.field("bArr"));
+ assertArrayEquals(obj.simple.sArr, (short[])simplePo.field("sArr"));
+ assertArrayEquals(obj.simple.iArr, (int[])simplePo.field("iArr"));
+ assertArrayEquals(obj.simple.lArr, (long[])simplePo.field("lArr"));
+ assertArrayEquals(obj.simple.fArr, (float[])simplePo.field("fArr"), 0);
+ assertArrayEquals(obj.simple.dArr, (double[])simplePo.field("dArr"), 0);
+ assertArrayEquals(obj.simple.cArr, (char[])simplePo.field("cArr"));
+ assertBooleanArrayEquals(obj.simple.boolArr, (boolean[])simplePo.field("boolArr"));
+ assertArrayEquals(obj.simple.strArr, (String[])simplePo.field("strArr"));
+ assertArrayEquals(obj.simple.uuidArr, (UUID[])simplePo.field("uuidArr"));
+ assertArrayEquals(obj.simple.dateArr, (Date[])simplePo.field("dateArr"));
+ assertArrayEquals(obj.simple.objArr, (Object[])simplePo.field("objArr"));
+ assertEquals(obj.simple.col, simplePo.field("col"));
+ assertEquals(obj.simple.map, simplePo.field("map"));
+ assertEquals(new Integer(obj.simple.enumVal.ordinal()),
+ new Integer(((Enum<?>)simplePo.field("enumVal")).ordinal()));
+ assertArrayEquals(ordinals(obj.simple.enumArr), ordinals((Enum<?>[])simplePo.field("enumArr")));
+ assertNull(simplePo.field("simple"));
+ assertNull(simplePo.field("portable"));
+ assertNull(simplePo.field("unknown"));
+
+ PortableObject portablePo = po.field("_portable");
+
+ assertEquals(obj.portable, portablePo.deserialize());
+
+ assertEquals(obj.portable.b, (byte)portablePo.field("_b"));
+ assertEquals(obj.portable.s, (short)portablePo.field("_s"));
+ assertEquals(obj.portable.i, (int)portablePo.field("_i"));
+ assertEquals(obj.portable.l, (long)portablePo.field("_l"));
+ assertEquals(obj.portable.f, (float)portablePo.field("_f"), 0);
+ assertEquals(obj.portable.d, (double)portablePo.field("_d"), 0);
+ assertEquals(obj.portable.c, (char)portablePo.field("_c"));
+ assertEquals(obj.portable.bool, (boolean)portablePo.field("_bool"));
+ assertEquals(obj.portable.str, portablePo.field("_str"));
+ assertEquals(obj.portable.uuid, portablePo.field("_uuid"));
+ assertEquals(obj.portable.date, portablePo.field("_date"));
+ assertEquals(obj.portable.ts, portablePo.field("_ts"));
+ assertArrayEquals(obj.portable.bArr, (byte[])portablePo.field("_bArr"));
+ assertArrayEquals(obj.portable.sArr, (short[])portablePo.field("_sArr"));
+ assertArrayEquals(obj.portable.iArr, (int[])portablePo.field("_iArr"));
+ assertArrayEquals(obj.portable.lArr, (long[])portablePo.field("_lArr"));
+ assertArrayEquals(obj.portable.fArr, (float[])portablePo.field("_fArr"), 0);
+ assertArrayEquals(obj.portable.dArr, (double[])portablePo.field("_dArr"), 0);
+ assertArrayEquals(obj.portable.cArr, (char[])portablePo.field("_cArr"));
+ assertBooleanArrayEquals(obj.portable.boolArr, (boolean[])portablePo.field("_boolArr"));
+ assertArrayEquals(obj.portable.strArr, (String[])portablePo.field("_strArr"));
+ assertArrayEquals(obj.portable.uuidArr, (UUID[])portablePo.field("_uuidArr"));
+ assertArrayEquals(obj.portable.dateArr, (Date[])portablePo.field("_dateArr"));
+ assertArrayEquals(obj.portable.objArr, (Object[])portablePo.field("_objArr"));
+ assertEquals(obj.portable.col, portablePo.field("_col"));
+ assertEquals(obj.portable.map, portablePo.field("_map"));
+ assertEquals(new Integer(obj.portable.enumVal.ordinal()),
+ new Integer(((Enum<?>)portablePo.field("_enumVal")).ordinal()));
+ assertArrayEquals(ordinals(obj.portable.enumArr), ordinals((Enum<?>[])portablePo.field("_enumArr")));
+ assertNull(portablePo.field("_simple"));
+ assertNull(portablePo.field("_portable"));
+ assertNull(portablePo.field("unknown"));
+ }
+
+ /**
+ * @param obj Simple object.
+ * @param po Portable object.
+ */
+ private void checkSimpleObjectData(SimpleObject obj, PortableObject po) {
+ assertEquals(obj.b, (byte)po.field("b"));
+ assertEquals(obj.s, (short)po.field("s"));
+ assertEquals(obj.i, (int)po.field("i"));
+ assertEquals(obj.l, (long)po.field("l"));
+ assertEquals(obj.f, (float)po.field("f"), 0);
+ assertEquals(obj.d, (double)po.field("d"), 0);
+ assertEquals(obj.c, (char)po.field("c"));
+ assertEquals(obj.bool, (boolean)po.field("bool"));
+ assertEquals(obj.str, po.field("str"));
+ assertEquals(obj.uuid, po.field("uuid"));
+ assertEquals(obj.date, po.field("date"));
+ assertEquals(Date.class, obj.date.getClass());
+ assertEquals(obj.ts, po.field("ts"));
+ assertArrayEquals(obj.bArr, (byte[])po.field("bArr"));
+ assertArrayEquals(obj.sArr, (short[])po.field("sArr"));
+ assertArrayEquals(obj.iArr, (int[])po.field("iArr"));
+ assertArrayEquals(obj.lArr, (long[])po.field("lArr"));
+ assertArrayEquals(obj.fArr, (float[])po.field("fArr"), 0);
+ assertArrayEquals(obj.dArr, (double[])po.field("dArr"), 0);
+ assertArrayEquals(obj.cArr, (char[])po.field("cArr"));
+ assertBooleanArrayEquals(obj.boolArr, (boolean[])po.field("boolArr"));
+ assertArrayEquals(obj.strArr, (String[])po.field("strArr"));
+ assertArrayEquals(obj.uuidArr, (UUID[])po.field("uuidArr"));
+ assertArrayEquals(obj.dateArr, (Date[])po.field("dateArr"));
+ assertArrayEquals(obj.objArr, (Object[])po.field("objArr"));
+ assertEquals(obj.col, po.field("col"));
+ assertEquals(obj.map, po.field("map"));
+ assertEquals(new Integer(obj.enumVal.ordinal()), new Integer(((Enum<?>)po.field("enumVal")).ordinal()));
+ assertArrayEquals(ordinals(obj.enumArr), ordinals((Enum<?>[])po.field("enumArr")));
+ assertNull(po.field("unknown"));
+
+ assertEquals(obj, po.deserialize());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testInvalidClass() throws Exception {
+ byte[] arr = new byte[20];
+
+ arr[0] = 103;
+
+ U.intToBytes(Integer.reverseBytes(11111), arr, 2);
+
+ final PortableObject po = new PortableObjectImpl(initPortableContext(new PortableMarshaller()), arr, 0);
+
+ GridTestUtils.assertThrows(log, new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ po.deserialize();
+
+ return null;
+ }
+ }, PortableInvalidClassException.class, "Unknown type ID: 11111"
+ );
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClassWithoutPublicConstructor() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(NoPublicConstructor.class.getName()),
+ new PortableTypeConfiguration(NoPublicDefaultConstructor.class.getName()),
+ new PortableTypeConfiguration(ProtectedConstructor.class.getName()))
+ );
+
+ initPortableContext(marsh);
+
+ NoPublicConstructor npc = new NoPublicConstructor();
+ PortableObject npc2 = marshal(npc, marsh);
+
+ assertEquals("test", npc2.<NoPublicConstructor>deserialize().val);
+
+ NoPublicDefaultConstructor npdc = new NoPublicDefaultConstructor(239);
+ PortableObject npdc2 = marshal(npdc, marsh);
+
+ assertEquals(239, npdc2.<NoPublicDefaultConstructor>deserialize().val);
+
+ ProtectedConstructor pc = new ProtectedConstructor();
+ PortableObject pc2 = marshal(pc, marsh);
+
+ assertEquals(ProtectedConstructor.class, pc2.<ProtectedConstructor>deserialize().getClass());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCustomSerializer() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ PortableTypeConfiguration type =
+ new PortableTypeConfiguration(CustomSerializedObject1.class.getName());
+
+ type.setSerializer(new CustomSerializer1());
+
+ marsh.setTypeConfigurations(Arrays.asList(type));
+
+ CustomSerializedObject1 obj1 = new CustomSerializedObject1(10);
+
+ PortableObject po1 = marshal(obj1, marsh);
+
+ assertEquals(20, po1.<CustomSerializedObject1>deserialize().val);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCustomSerializerWithGlobal() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setSerializer(new CustomSerializer1());
+
+ PortableTypeConfiguration type1 =
+ new PortableTypeConfiguration(CustomSerializedObject1.class.getName());
+ PortableTypeConfiguration type2 =
+ new PortableTypeConfiguration(CustomSerializedObject2.class.getName());
+
+ type2.setSerializer(new CustomSerializer2());
+
+ marsh.setTypeConfigurations(Arrays.asList(type1, type2));
+
+ CustomSerializedObject1 obj1 = new CustomSerializedObject1(10);
+
+ PortableObject po1 = marshal(obj1, marsh);
+
+ assertEquals(20, po1.<CustomSerializedObject1>deserialize().val);
+
+ CustomSerializedObject2 obj2 = new CustomSerializedObject2(10);
+
+ PortableObject po2 = marshal(obj2, marsh);
+
+ assertEquals(30, po2.<CustomSerializedObject2>deserialize().val);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCustomIdMapper() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ PortableTypeConfiguration type =
+ new PortableTypeConfiguration(CustomMappedObject1.class.getName());
+
+ type.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 11111;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ assert typeId == 11111;
+
+ if ("val1".equals(fieldName))
+ return 22222;
+ else if ("val2".equals(fieldName))
+ return 33333;
+
+ assert false : "Unknown field: " + fieldName;
+
+ return 0;
+ }
+ });
+
+ marsh.setTypeConfigurations(Arrays.asList(type));
+
+ CustomMappedObject1 obj1 = new CustomMappedObject1(10, "str");
+
+ PortableObject po1 = marshal(obj1, marsh);
+
+ assertEquals(11111, po1.typeId());
+ assertEquals(22222, intFromPortable(po1, 18));
+ assertEquals(33333, intFromPortable(po1, 31));
+
+ assertEquals(10, po1.<CustomMappedObject1>deserialize().val1);
+ assertEquals("str", po1.<CustomMappedObject1>deserialize().val2);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCustomIdMapperWithGlobal() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 11111;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ assert typeId == 11111;
+
+ if ("val1".equals(fieldName)) return 22222;
+ else if ("val2".equals(fieldName)) return 33333;
+
+ assert false : "Unknown field: " + fieldName;
+
+ return 0;
+ }
+ });
+
+ PortableTypeConfiguration type1 =
+ new PortableTypeConfiguration(CustomMappedObject1.class.getName());
+ PortableTypeConfiguration type2 =
+ new PortableTypeConfiguration(CustomMappedObject2.class.getName());
+
+ type2.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 44444;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ assert typeId == 44444;
+
+ if ("val1".equals(fieldName)) return 55555;
+ else if ("val2".equals(fieldName)) return 66666;
+
+ assert false : "Unknown field: " + fieldName;
+
+ return 0;
+ }
+ });
+
+ marsh.setTypeConfigurations(Arrays.asList(type1, type2));
+
+ CustomMappedObject1 obj1 = new CustomMappedObject1(10, "str1");
+
+ PortableObject po1 = marshal(obj1, marsh);
+
+ assertEquals(11111, po1.typeId());
+ assertEquals(22222, intFromPortable(po1, 18));
+ assertEquals(33333, intFromPortable(po1, 31));
+
+ assertEquals(10, po1.<CustomMappedObject1>deserialize().val1);
+ assertEquals("str1", po1.<CustomMappedObject1>deserialize().val2);
+
+ CustomMappedObject2 obj2 = new CustomMappedObject2(20, "str2");
+
+ PortableObject po2 = marshal(obj2, marsh);
+
+ assertEquals(44444, po2.typeId());
+ assertEquals(55555, intFromPortable(po2, 18));
+ assertEquals(66666, intFromPortable(po2, 31));
+
+ assertEquals(20, po2.<CustomMappedObject2>deserialize().val1);
+ assertEquals("str2", po2.<CustomMappedObject2>deserialize().val2);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDynamicObject() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(DynamicObject.class.getName())
+ ));
+
+ PortableObject po1 = marshal(new DynamicObject(0, 10, 20, 30), marsh);
+
+ assertEquals(new Integer(10), po1.field("val1"));
+ assertEquals(null, po1.field("val2"));
+ assertEquals(null, po1.field("val3"));
+
+ DynamicObject do1 = po1.deserialize();
+
+ assertEquals(10, do1.val1);
+ assertEquals(0, do1.val2);
+ assertEquals(0, do1.val3);
+
+ PortableObject po2 = marshal(new DynamicObject(1, 10, 20, 30), marsh);
+
+ assertEquals(new Integer(10), po2.field("val1"));
+ assertEquals(new Integer(20), po2.field("val2"));
+ assertEquals(null, po2.field("val3"));
+
+ DynamicObject do2 = po2.deserialize();
+
+ assertEquals(10, do2.val1);
+ assertEquals(20, do2.val2);
+ assertEquals(0, do2.val3);
+
+ PortableObject po3 = marshal(new DynamicObject(2, 10, 20, 30), marsh);
+
+ assertEquals(new Integer(10), po3.field("val1"));
+ assertEquals(new Integer(20), po3.field("val2"));
+ assertEquals(new Integer(30), po3.field("val3"));
+
+ DynamicObject do3 = po3.deserialize();
+
+ assertEquals(10, do3.val1);
+ assertEquals(20, do3.val2);
+ assertEquals(30, do3.val3);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCycleLink() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(CycleLinkObject.class.getName())
+ ));
+
+ CycleLinkObject obj = new CycleLinkObject();
+
+ obj.self = obj;
+
+ PortableObject po = marshal(obj, marsh);
+
+ CycleLinkObject obj0 = po.deserialize();
+
+ assert obj0.self == obj0;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDetached() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(DetachedTestObject.class.getName()),
+ new PortableTypeConfiguration(DetachedInnerTestObject.class.getName())
+ ));
+
+ UUID id = UUID.randomUUID();
+
+ DetachedTestObject obj = marshal(new DetachedTestObject(
+ new DetachedInnerTestObject(null, id)), marsh).deserialize();
+
+ assertEquals(id, obj.inner1.id);
+ assertEquals(id, obj.inner4.id);
+
+ assert obj.inner1 == obj.inner4;
+
+ PortableObjectImpl innerPo = (PortableObjectImpl)obj.inner2;
+
+ assert innerPo.detached();
+
+ DetachedInnerTestObject inner = innerPo.deserialize();
+
+ assertEquals(id, inner.id);
+
+ PortableObjectImpl detachedPo = (PortableObjectImpl)innerPo.detach();
+
+ assert detachedPo.detached();
+
+ inner = detachedPo.deserialize();
+
+ assertEquals(id, inner.id);
+
+ innerPo = (PortableObjectImpl)obj.inner3;
+
+ assert innerPo.detached();
+
+ inner = innerPo.deserialize();
+
+ assertEquals(id, inner.id);
+ assertNotNull(inner.inner);
+
+ detachedPo = (PortableObjectImpl)innerPo.detach();
+
+ assert detachedPo.detached();
+
+ inner = innerPo.deserialize();
+
+ assertEquals(id, inner.id);
+ assertNotNull(inner.inner);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCollectionFields() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(CollectionFieldsObject.class.getName()),
+ new PortableTypeConfiguration(Key.class.getName()),
+ new PortableTypeConfiguration(Value.class.getName())
+ ));
+
+ Object[] arr = new Object[] {new Value(1), new Value(2), new Value(3)};
+ Collection<Value> col = Arrays.asList(new Value(4), new Value(5), new Value(6));
+ Map<Key, Value> map = F.asMap(new Key(10), new Value(10), new Key(20), new Value(20), new Key(30), new Value(30));
+
+ CollectionFieldsObject obj = new CollectionFieldsObject(arr, col, map);
+
+ PortableObject po = marshal(obj, marsh);
+
+ Object[] arr0 = po.field("arr");
+
+ assertEquals(3, arr0.length);
+
+ int i = 1;
+
+ for (Object valPo : arr0)
+ assertEquals(i++, ((PortableObject)valPo).<Value>deserialize().val);
+
+ Collection<PortableObject> col0 = po.field("col");
+
+ i = 4;
+
+ for (PortableObject valPo : col0)
+ assertEquals(i++, valPo.<Value>deserialize().val);
+
+ Map<PortableObject, PortableObject> map0 = po.field("map");
+
+ for (Map.Entry<PortableObject, PortableObject> e : map0.entrySet())
+ assertEquals(e.getKey().<Key>deserialize().key, e.getValue().<Value>deserialize().val);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDefaultMapping() throws Exception {
+ PortableMarshaller marsh1 = new PortableMarshaller();
+
+ PortableTypeConfiguration customMappingType =
+ new PortableTypeConfiguration(TestPortableObject.class.getName());
+
+ customMappingType.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ String typeName;
+
+ try {
+ Method mtd = PortableContext.class.getDeclaredMethod("typeName", String.class);
+
+ mtd.setAccessible(true);
+
+ typeName = (String)mtd.invoke(null, clsName);
+ }
+ catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+
+ return typeName.toLowerCase().hashCode();
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return fieldName.toLowerCase().hashCode();
+ }
+ });
+
+ marsh1.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName()),
+ customMappingType
+ ));
+
+ TestPortableObject obj = portableObject();
+
+ PortableObjectImpl po = marshal(obj, marsh1);
+
+ PortableMarshaller marsh2 = new PortableMarshaller();
+
+ marsh2.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName()),
+ new PortableTypeConfiguration(TestPortableObject.class.getName())
+ ));
+
+ PortableContext ctx = initPortableContext(marsh2);
+
+ po.context(ctx);
+
+ assertEquals(obj, po.deserialize());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTypeNames() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ PortableTypeConfiguration customType1 = new PortableTypeConfiguration(Value.class.getName());
+
+ customType1.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 300;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ PortableTypeConfiguration customType2 = new PortableTypeConfiguration("org.gridgain.NonExistentClass1");
+
+ customType2.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 400;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ PortableTypeConfiguration customType3 = new PortableTypeConfiguration("NonExistentClass2");
+
+ customType3.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 500;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ PortableTypeConfiguration customType4 = new PortableTypeConfiguration("NonExistentClass5");
+
+ customType4.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 0;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(Key.class.getName()),
+ new PortableTypeConfiguration("org.gridgain.NonExistentClass3"),
+ new PortableTypeConfiguration("NonExistentClass4"),
+ customType1,
+ customType2,
+ customType3,
+ customType4
+ ));
+
+ PortableContext ctx = initPortableContext(marsh);
+
+ assertEquals("notconfiguredclass".hashCode(), ctx.typeId("NotConfiguredClass"));
+ assertEquals("key".hashCode(), ctx.typeId("Key"));
+ assertEquals("nonexistentclass3".hashCode(), ctx.typeId("NonExistentClass3"));
+ assertEquals("nonexistentclass4".hashCode(), ctx.typeId("NonExistentClass4"));
+ assertEquals(300, ctx.typeId(getClass().getSimpleName() + "$Value"));
+ assertEquals(400, ctx.typeId("NonExistentClass1"));
+ assertEquals(500, ctx.typeId("NonExistentClass2"));
+ assertEquals("nonexistentclass5".hashCode(), ctx.typeId("NonExistentClass5"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFieldIdMapping() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ PortableTypeConfiguration customType1 = new PortableTypeConfiguration(Value.class.getName());
+
+ customType1.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 300;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ switch (fieldName) {
+ case "val1":
+ return 301;
+
+ case "val2":
+ return 302;
+
+ default:
+ return 0;
+ }
+ }
+ });
+
+ PortableTypeConfiguration customType2 = new PortableTypeConfiguration("NonExistentClass1");
+
+ customType2.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 400;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ switch (fieldName) {
+ case "val1":
+ return 401;
+
+ case "val2":
+ return 402;
+
+ default:
+ return 0;
+ }
+ }
+ });
+
+ marsh.setTypeConfigurations(Arrays.asList(new PortableTypeConfiguration(Key.class.getName()),
+ new PortableTypeConfiguration("NonExistentClass2"),
+ customType1,
+ customType2));
+
+ PortableContext ctx = initPortableContext(marsh);
+
+ assertEquals("val".hashCode(), ctx.fieldId("key".hashCode(), "val"));
+ assertEquals("val".hashCode(), ctx.fieldId("nonexistentclass2".hashCode(), "val"));
+ assertEquals("val".hashCode(), ctx.fieldId("notconfiguredclass".hashCode(), "val"));
+ assertEquals(301, ctx.fieldId(300, "val1"));
+ assertEquals(302, ctx.fieldId(300, "val2"));
+ assertEquals("val3".hashCode(), ctx.fieldId(300, "val3"));
+ assertEquals(401, ctx.fieldId(400, "val1"));
+ assertEquals(402, ctx.fieldId(400, "val2"));
+ assertEquals("val3".hashCode(), ctx.fieldId(400, "val3"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDuplicateTypeId() throws Exception {
+ final PortableMarshaller marsh = new PortableMarshaller();
+
+ PortableTypeConfiguration customType1 = new PortableTypeConfiguration("org.gridgain.Class1");
+
+ customType1.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 100;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ PortableTypeConfiguration customType2 = new PortableTypeConfiguration("org.gridgain.Class2");
+
+ customType2.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 100;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ marsh.setTypeConfigurations(Arrays.asList(customType1, customType2));
+
+ try {
+ initPortableContext(marsh);
+ }
+ catch (IgniteCheckedException e) {
+ assertEquals("Duplicate type ID [clsName=org.gridgain.Class1, id=100]",
+ e.getCause().getCause().getMessage());
+
+ return;
+ }
+
+ assert false;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopy() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ final PortableObject po = marshal(obj, marsh);
+
+ PortableObject copy = copy(po, null);
+
+ assertEquals(obj, copy.deserialize());
+
+ copy = copy(po, new HashMap<String, Object>());
+
+ assertEquals(obj, copy.deserialize());
+
+ Map<String, Object> map = new HashMap<>(1, 1.0f);
+
+ map.put("i", 3);
+
+ copy = copy(po, map);
+
+ assertEquals((byte)2, copy.<Byte>field("b").byteValue());
+ assertEquals((short)2, copy.<Short>field("s").shortValue());
+ assertEquals(3, copy.<Integer>field("i").intValue());
+ assertEquals(2L, copy.<Long>field("l").longValue());
+ assertEquals(2.2f, copy.<Float>field("f").floatValue(), 0);
+ assertEquals(2.2d, copy.<Double>field("d").doubleValue(), 0);
+ assertEquals((char)2, copy.<Character>field("c").charValue());
+ assertEquals(false, copy.<Boolean>field("bool").booleanValue());
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertEquals((byte)2, obj0.b);
+ assertEquals((short)2, obj0.s);
+ assertEquals(3, obj0.i);
+ assertEquals(2L, obj0.l);
+ assertEquals(2.2f, obj0.f, 0);
+ assertEquals(2.2d, obj0.d, 0);
+ assertEquals((char)2, obj0.c);
+ assertEquals(false, obj0.bool);
+
+ map = new HashMap<>(3, 1.0f);
+
+ map.put("b", (byte)3);
+ map.put("l", 3L);
+ map.put("bool", true);
+
+ copy = copy(po, map);
+
+ assertEquals((byte)3, copy.<Byte>field("b").byteValue());
+ assertEquals((short)2, copy.<Short>field("s").shortValue());
+ assertEquals(2, copy.<Integer>field("i").intValue());
+ assertEquals(3L, copy.<Long>field("l").longValue());
+ assertEquals(2.2f, copy.<Float>field("f").floatValue(), 0);
+ assertEquals(2.2d, copy.<Double>field("d").doubleValue(), 0);
+ assertEquals((char)2, copy.<Character>field("c").charValue());
+ assertEquals(true, copy.<Boolean>field("bool").booleanValue());
+
+ obj0 = copy.deserialize();
+
+ assertEquals((byte)3, obj0.b);
+ assertEquals((short)2, obj0.s);
+ assertEquals(2, obj0.i);
+ assertEquals(3L, obj0.l);
+ assertEquals(2.2f, obj0.f, 0);
+ assertEquals(2.2d, obj0.d, 0);
+ assertEquals((char)2, obj0.c);
+ assertEquals(true, obj0.bool);
+
+ map = new HashMap<>(8, 1.0f);
+
+ map.put("b", (byte)3);
+ map.put("s", (short)3);
+ map.put("i", 3);
+ map.put("l", 3L);
+ map.put("f", 3.3f);
+ map.put("d", 3.3d);
+ map.put("c", (char)3);
+ map.put("bool", true);
+
+ copy = copy(po, map);
+
+ assertEquals((byte)3, copy.<Byte>field("b").byteValue());
+ assertEquals((short)3, copy.<Short>field("s").shortValue());
+ assertEquals(3, copy.<Integer>field("i").intValue());
+ assertEquals(3L, copy.<Long>field("l").longValue());
+ assertEquals(3.3f, copy.<Float>field("f").floatValue(), 0);
+ assertEquals(3.3d, copy.<Double>field("d").doubleValue(), 0);
+ assertEquals((char)3, copy.<Character>field("c").charValue());
+ assertEquals(true, copy.<Boolean>field("bool").booleanValue());
+
+ obj0 = copy.deserialize();
+
+ assertEquals((byte)3, obj0.b);
+ assertEquals((short)3, obj0.s);
+ assertEquals(3, obj0.i);
+ assertEquals(3L, obj0.l);
+ assertEquals(3.3f, obj0.f, 0);
+ assertEquals(3.3d, obj0.d, 0);
+ assertEquals((char)3, obj0.c);
+ assertEquals(true, obj0.bool);
+
+// GridTestUtils.assertThrows(
+// log,
+// new Callable<Object>() {
+// @Override public Object call() throws Exception {
+// po.copy(F.<String, Object>asMap("i", false));
+//
+// return null;
+// }
+// },
+// PortableException.class,
+// "Invalid value type for field: i"
+// );
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyString() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ PortableObject copy = copy(po, F.<String, Object>asMap("str", "str3"));
+
+ assertEquals("str3", copy.<String>field("str"));
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertEquals("str3", obj0.str);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyUuid() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ UUID uuid = UUID.randomUUID();
+
+ PortableObject copy = copy(po, F.<String, Object>asMap("uuid", uuid));
+
+ assertEquals(uuid, copy.<UUID>field("uuid"));
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertEquals(uuid, obj0.uuid);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyByteArray() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ PortableObject copy = copy(po, F.<String, Object>asMap("bArr", new byte[]{1, 2, 3}));
+
+ assertArrayEquals(new byte[] {1, 2, 3}, copy.<byte[]>field("bArr"));
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertArrayEquals(new byte[] {1, 2, 3}, obj0.bArr);
+ }
+
+ /**
+ * @param po Portable object.
+ * @param fields Fields.
+ * @return Copy.
+ */
+ private PortableObject copy(PortableObject po, Map<String, Object> fields) {
+ PortableBuilder builder = PortableBuilderImpl.wrap(po);
+
+ if (fields != null) {
+ for (Map.Entry<String, Object> e : fields.entrySet())
+ builder.setField(e.getKey(), e.getValue());
+ }
+
+ return builder.build();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyShortArray() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ PortableObject copy = copy(po, F.<String, Object>asMap("sArr", new short[]{1, 2, 3}));
+
+ assertArrayEquals(new short[] {1, 2, 3}, copy.<short[]>field("sArr"));
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertArrayEquals(new short[] {1, 2, 3}, obj0.sArr);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyIntArray() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ PortableObject copy = copy(po, F.<String, Object>asMap("iArr", new int[]{1, 2, 3}));
+
+ assertArrayEquals(new int[] {1, 2, 3}, copy.<int[]>field("iArr"));
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertArrayEquals(new int[] {1, 2, 3}, obj0.iArr);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyLongArray() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ PortableObject copy = copy(po, F.<String, Object>asMap("lArr", new long[]{1, 2, 3}));
+
+ assertArrayEquals(new long[] {1, 2, 3}, copy.<long[]>field("lArr"));
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertArrayEquals(new long[] {1, 2, 3}, obj0.lArr);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyFloatArray() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ PortableObject copy = copy(po, F.<String, Object>asMap("fArr", new float[]{1, 2, 3}));
+
+ assertArrayEquals(new float[] {1, 2, 3}, copy.<float[]>field("fArr"), 0);
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertArrayEquals(new float[] {1, 2, 3}, obj0.fArr, 0);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyDoubleArray() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ PortableObject copy = copy(po, F.<String, Object>asMap("dArr", new double[]{1, 2, 3}));
+
+ assertArrayEquals(new double[] {1, 2, 3}, copy.<double[]>field("dArr"), 0);
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertArrayEquals(new double[] {1, 2, 3}, obj0.dArr, 0);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyCharArray() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ PortableObject copy = copy(po, F.<String, Object>asMap("cArr", new char[]{1, 2, 3}));
+
+ assertArrayEquals(new char[]{1, 2, 3}, copy.<char[]>field("cArr"));
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertArrayEquals(new char[]{1, 2, 3}, obj0.cArr);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyStringArray() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ PortableObject copy = copy(po, F.<String, Object>asMap("strArr", new String[]{"str1", "str2"}));
+
+ assertArrayEquals(new String[]{"str1", "str2"}, copy.<String[]>field("strArr"));
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertArrayEquals(new String[]{"str1", "str2"}, obj0.strArr);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyObject() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ SimpleObject newObj = new SimpleObject();
+
+ newObj.i = 12345;
+ newObj.fArr = new float[] {5, 8, 0};
+ newObj.str = "newStr";
+
+ PortableObject copy = copy(po, F.<String, Object>asMap("inner", newObj));
+
+ assertEquals(newObj, copy.<PortableObject>field("inner").deserialize());
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertEquals(newObj, obj0.inner);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyNonPrimitives() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())
+ ));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ Map<String, Object> map = new HashMap<>(3, 1.0f);
+
+ SimpleObject newObj = new SimpleObject();
+
+ newObj.i = 12345;
+ newObj.fArr = new float[] {5, 8, 0};
+ newObj.str = "newStr";
+
+ map.put("str", "str555");
+ map.put("inner", newObj);
+ map.put("bArr", new byte[]{6, 7, 9});
+
+ PortableObject copy = copy(po, map);
+
+ assertEquals("str555", copy.<String>field("str"));
+ assertEquals(newObj, copy.<PortableObject>field("inner").deserialize());
+ assertArrayEquals(new byte[]{6, 7, 9}, copy.<byte[]>field("bArr"));
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertEquals("str555", obj0.str);
+ assertEquals(newObj, obj0.inner);
+ assertArrayEquals(new byte[] {6, 7, 9}, obj0.bArr);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableCopyMixed() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(new PortableTypeConfiguration(SimpleObject.class.getName())));
+
+ SimpleObject obj = simpleObject();
+
+ PortableObject po = marshal(obj, marsh);
+
+ Map<String, Object> map = new HashMap<>(3, 1.0f);
+
+ SimpleObject newObj = new SimpleObject();
+
+ newObj.i = 12345;
+ newObj.fArr = new float[] {5, 8, 0};
+ newObj.str = "newStr";
+
+ map.put("i", 1234);
+ map.put("str", "str555");
+ map.put("inner", newObj);
+ map.put("s", (short)2323);
+ map.put("bArr", new byte[]{6, 7, 9});
+ map.put("b", (byte)111);
+
+ PortableObject copy = copy(po, map);
+
+ assertEquals(1234, copy.<Integer>field("i").intValue());
+ assertEquals("str555", copy.<String>field("str"));
+ assertEquals(newObj, copy.<PortableObject>field("inner").deserialize());
+ assertEquals((short)2323, copy.<Short>field("s").shortValue());
+ assertArrayEquals(new byte[] {6, 7, 9}, copy.<byte[]>field("bArr"));
+ assertEquals((byte)111, copy.<Byte>field("b").byteValue());
+
+ SimpleObject obj0 = copy.deserialize();
+
+ assertEquals(1234, obj0.i);
+ assertEquals("str555", obj0.str);
+ assertEquals(newObj, obj0.inner);
+ assertEquals((short)2323, obj0.s);
+ assertArrayEquals(new byte[] {6, 7, 9}, obj0.bArr);
+ assertEquals((byte)111, obj0.b);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testKeepDeserialized() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(SimpleObject.class.getName()));
+ marsh.setKeepDeserialized(true);
+
+ PortableObject po = marshal(simpleObject(), marsh);
+
+ assert po.deserialize() == po.deserialize();
+
+ marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(SimpleObject.class.getName()));
+ marsh.setKeepDeserialized(false);
+
+ po = marshal(simpleObject(), marsh);
+
+ assert po.deserialize() != po.deserialize();
+
+ marsh = new PortableMarshaller();
+
+ marsh.setKeepDeserialized(true);
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())));
+
+ po = marshal(simpleObject(), marsh);
+
+ assert po.deserialize() == po.deserialize();
+
+ marsh = new PortableMarshaller();
+
+ marsh.setKeepDeserialized(false);
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(SimpleObject.class.getName())));
+
+ po = marshal(simpleObject(), marsh);
+
+ assert po.deserialize() != po.deserialize();
+
+ marsh = new PortableMarshaller();
+
+ marsh.setKeepDeserialized(true);
+
+ PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(SimpleObject.class.getName());
+
+ typeCfg.setKeepDeserialized(false);
+
+ marsh.setTypeConfigurations(Arrays.asList(typeCfg));
+
+ po = marshal(simpleObject(), marsh);
+
+ assert po.deserialize() != po.deserialize();
+
+ marsh = new PortableMarshaller();
+
+ marsh.setKeepDeserialized(false);
+
+ typeCfg = new PortableTypeConfiguration(SimpleObject.class.getName());
+
+ typeCfg.setKeepDeserialized(true);
+
+ marsh.setTypeConfigurations(Arrays.asList(typeCfg));
+
+ po = marshal(simpleObject(), marsh);
+
+ assert po.deserialize() == po.deserialize();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testOffheapPortable() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(new PortableTypeConfiguration(SimpleObject.class.getName())));
+
+ PortableContext ctx = initPortableContext(marsh);
+
+ SimpleObject simpleObj = simpleObject();
+
+ PortableObjectImpl obj = marshal(simpleObj, marsh);
+
+ long ptr = 0;
+
+ long ptr1 = 0;
+
+ long ptr2 = 0;
+
+ try {
+ ptr = copyOffheap(obj);
+
+ PortableObjectOffheapImpl offheapObj = new PortableObjectOffheapImpl(ctx,
+ ptr,
+ 0,
+ obj.array().length);
+
+ assertTrue(offheapObj.equals(offheapObj));
+ assertFalse(offheapObj.equals(null));
+ assertFalse(offheapObj.equals("str"));
+ assertTrue(offheapObj.equals(obj));
+ assertTrue(obj.equals(offheapObj));
+
+ ptr1 = copyOffheap(obj);
+
+ PortableObjectOffheapImpl offheapObj1 = new PortableObjectOffheapImpl(ctx,
+ ptr1,
+ 0,
+ obj.array().length);
+
+ assertTrue(offheapObj.equals(offheapObj1));
+ assertTrue(offheapObj1.equals(offheapObj));
+
+ assertEquals(obj.typeId(), offheapObj.typeId());
+ assertEquals(obj.hashCode(), offheapObj.hashCode());
+
+ checkSimpleObjectData(simpleObj, offheapObj);
+
+ PortableObjectOffheapImpl innerOffheapObj = offheapObj.field("inner");
+
+ assertNotNull(innerOffheapObj);
+
+ checkSimpleObjectData(simpleObj.inner, innerOffheapObj);
+
+ obj = (PortableObjectImpl)offheapObj.heapCopy();
+
+ assertEquals(obj.typeId(), offheapObj.typeId());
+ assertEquals(obj.hashCode(), offheapObj.hashCode());
+
+ checkSimpleObjectData(simpleObj, obj);
+
+ PortableObjectImpl innerObj = obj.field("inner");
+
+ assertNotNull(innerObj);
+
+ checkSimpleObjectData(simpleObj.inner, innerObj);
+
+ simpleObj.d = 0;
+
+ obj = marshal(simpleObj, marsh);
+
+ assertFalse(offheapObj.equals(obj));
+ assertFalse(obj.equals(offheapObj));
+
+ ptr2 = copyOffheap(obj);
+
+ PortableObjectOffheapImpl offheapObj2 = new PortableObjectOffheapImpl(ctx,
+ ptr2,
+ 0,
+ obj.array().length);
+
+ assertFalse(offheapObj.equals(offheapObj2));
+ assertFalse(offheapObj2.equals(offheapObj));
+ }
+ finally {
+ UNSAFE.freeMemory(ptr);
+
+ if (ptr1 > 0)
+ UNSAFE.freeMemory(ptr1);
+
+ if (ptr2 > 0)
+ UNSAFE.freeMemory(ptr2);
+ }
+ }
+
+ /**
+ *
+ */
+ public void testReadResolve() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(
+ Arrays.asList(MySingleton.class.getName(), SingletonMarker.class.getName()));
+
+ PortableObjectImpl portableObj = marshal(MySingleton.INSTANCE, marsh);
+
+ assertTrue(portableObj.array().length <= 1024); // Check that big string was not serialized.
+
+ MySingleton singleton = portableObj.deserialize();
+
+ assertSame(MySingleton.INSTANCE, singleton);
+ }
+
+ /**
+ *
+ */
+ public void testReadResolveOnPortableAware() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Collections.singletonList(MyTestClass.class.getName()));
+
+ PortableObjectImpl portableObj = marshal(new MyTestClass(), marsh);
+
+ MyTestClass obj = portableObj.deserialize();
+
+ assertEquals("readResolve", obj.s);
+ }
+
+ /**
+ * @throws Exception If ecxeption thrown.
+ */
+ public void testDeclareReadResolveInParent() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(ChildPortable.class.getName()));
+
+ PortableObjectImpl portableObj = marshal(new ChildPortable(), marsh);
+
+ ChildPortable singleton = portableObj.deserialize();
+
+ assertNotNull(singleton.s);
+ }
+
+ /**
+ *
+ */
+ public void testDecimalFields() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ Collection<String> clsNames = new ArrayList<>();
+
+ clsNames.add(DecimalReflective.class.getName());
+ clsNames.add(DecimalMarshalAware.class.getName());
+
+ marsh.setClassNames(clsNames);
+
+ // 1. Test reflective stuff.
+ DecimalReflective obj1 = new DecimalReflective();
+
+ obj1.val = BigDecimal.ZERO;
+ obj1.valArr = new BigDecimal[] { BigDecimal.ONE, BigDecimal.TEN };
+
+ PortableObjectImpl portObj = marshal(obj1, marsh);
+
+ assertEquals(obj1.val, portObj.field("val"));
+ assertArrayEquals(obj1.valArr, portObj.<BigDecimal[]>field("valArr"));
+
+ assertEquals(obj1.val, portObj.<DecimalReflective>deserialize().val);
+ assertArrayEquals(obj1.valArr, portObj.<DecimalReflective>deserialize().valArr);
+
+ // 2. Test marshal aware stuff.
+ DecimalMarshalAware obj2 = new DecimalMarshalAware();
+
+ obj2.val = BigDecimal.ZERO;
+ obj2.valArr = new BigDecimal[] { BigDecimal.ONE, BigDecimal.TEN.negate() };
+ obj2.rawVal = BigDecimal.TEN;
+ obj2.rawValArr = new BigDecimal[] { BigDecimal.ZERO, BigDecimal.ONE };
+
+ portObj = marshal(obj2, marsh);
+
+ assertEquals(obj2.val, portObj.field("val"));
+ assertArrayEquals(obj2.valArr, portObj.<BigDecimal[]>field("valArr"));
+
+ assertEquals(obj2.val, portObj.<DecimalMarshalAware>deserialize().val);
+ assertArrayEquals(obj2.valArr, portObj.<DecimalMarshalAware>deserialize().valArr);
+ assertEquals(obj2.rawVal, portObj.<DecimalMarshalAware>deserialize().rawVal);
+ assertArrayEquals(obj2.rawValArr, portObj.<DecimalMarshalAware>deserialize().rawValArr);
+ }
+
+ /**
+ * @throws IgniteCheckedException If failed.
+ */
+ public void testFinalField() throws IgniteCheckedException {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ SimpleObjectWithFinal obj = new SimpleObjectWithFinal();
+
+ SimpleObjectWithFinal po0 = marshalUnmarshal(obj, marsh);
+
+ assertEquals(obj.time, po0.time);
+ }
+
+ /**
+ * @throws IgniteCheckedException If failed.
+ */
+ public void testThreadLocalArrayReleased() throws IgniteCheckedException {
+ // Checking the writer directly.
+ assertEquals(false, THREAD_LOCAL_ALLOC.isThreadLocalArrayAcquired());
+
+ try (PortableWriterExImpl writer = new PortableWriterExImpl(initPortableContext(new PortableMarshaller()), 0)) {
+ assertEquals(true, THREAD_LOCAL_ALLOC.isThreadLocalArrayAcquired());
+
+ writer.writeString("Thread local test");
+
+ writer.array();
+
+ assertEquals(true, THREAD_LOCAL_ALLOC.isThreadLocalArrayAcquired());
+ }
+
+ // Checking the portable marshaller.
+ assertEquals(false, THREAD_LOCAL_ALLOC.isThreadLocalArrayAcquired());
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ initPortableContext(marsh);
+
+ marsh.marshal(new SimpleObject());
+
+ assertEquals(false, THREAD_LOCAL_ALLOC.isThreadLocalArrayAcquired());
+
+ // Checking the builder.
+ PortableBuilder builder = new PortableBuilderImpl(initPortableContext(new PortableMarshaller()),
+ "org.gridgain.foo.bar.TestClass");
+
+ builder.setField("a", "1");
+
+ PortableObject portableObj = builder.build();
+
+ assertEquals(false, THREAD_LOCAL_ALLOC.isThreadLocalArrayAcquired());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDuplicateName() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ initPortableContext(marsh);
+
+ Test1.Job job1 = new Test1().new Job();
+ Test2.Job job2 = new Test2().new Job();
+
+ marsh.marshal(job1);
+
+ try {
+ marsh.marshal(job2);
+ } catch (PortableException e) {
+ assertEquals(true, e.getMessage().contains("Failed to register class"));
+ return;
+ }
+
+ assert false;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClassFieldsMarshalling() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ initPortableContext(marsh);
+
+ ObjectWithClassFields obj = new ObjectWithClassFields();
+ obj.cls1 = GridPortableMarshallerSelfTest.class;
+
+ byte[] marshal = marsh.marshal(obj);
+
+ ObjectWithClassFields obj2 = marsh.unmarshal(marshal, null);
+
+ assertEquals(obj.cls1, obj2.cls1);
+ assertNull(obj2.cls2);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMarshallingThroughJdk() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ initPortableContext(marsh);
+
+ InetSocketAddress addr = new InetSocketAddress("192.168.0.2", 4545);
+
+ byte[] arr = marsh.marshal(addr);
+
+ InetSocketAddress addr2 = marsh.unmarshal(arr, null);
+
+ assertEquals(addr.getHostString(), addr2.getHostString());
+ assertEquals(addr.getPort(), addr2.getPort());
+
+ TestAddress testAddr = new TestAddress();
+ testAddr.addr = addr;
+ testAddr.str1 = "Hello World";
+
+ SimpleObject simpleObj = new SimpleObject();
+ simpleObj.c = 'g';
+ simpleObj.date = new Date();
+
+ testAddr.obj = simpleObj;
+
+ arr = marsh.marshal(testAddr);
+
+ TestAddress testAddr2 = marsh.unmarshal(arr, null);
+
+ assertEquals(testAddr.addr.getHostString(), testAddr2.addr.getHostString());
+ assertEquals(testAddr.addr.getPort(), testAddr2.addr.getPort());
+ assertEquals(testAddr.str1, testAddr2.str1);
+ assertEquals(testAddr.obj.c, testAddr2.obj.c);
+ assertEquals(testAddr.obj.date, testAddr2.obj.date);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPredefinedTypeIds() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ PortableContext pCtx = initPortableContext(marsh);
+
+ Field field = pCtx.getClass().getDeclaredField("predefinedTypeNames");
+
+ field.setAccessible(true);
+
+ Map<String, Integer> map = (Map<String, Integer>)field.get(pCtx);
+
+ assertTrue(map.size() > 0);
+
+ for (Map.Entry<String, Integer> entry : map.entrySet()) {
+ int id = entry.getValue();
+
+ if (id == GridPortableMarshaller.UNREGISTERED_TYPE_ID)
+ continue;
+
+ PortableClassDescriptor desc = pCtx.descriptorForTypeId(false, entry.getValue(), null);
+
+ assertEquals(desc.typeId(), pCtx.typeId(desc.describedClass().getName()));
+ assertEquals(desc.typeId(), pCtx.typeId(pCtx.typeName(desc.describedClass().getName())));
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCyclicReferencesMarshalling() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ SimpleObject obj = simpleObject();
+
+ obj.bArr = obj.inner.bArr;
+ obj.cArr = obj.inner.cArr;
+ obj.boolArr = obj.inner.boolArr;
+ obj.sArr = obj.inner.sArr;
+ obj.strArr = obj.inner.strArr;
+ obj.iArr = obj.inner.iArr;
+ obj.lArr = obj.inner.lArr;
+ obj.fArr = obj.inner.fArr;
+ obj.dArr = obj.inner.dArr;
+ obj.dateArr = obj.inner.dateArr;
+ obj.uuidArr = obj.inner.uuidArr;
+ obj.objArr = obj.inner.objArr;
+ obj.bdArr = obj.inner.bdArr;
+ obj.map = obj.inner.map;
+ obj.col = obj.inner.col;
+ obj.mEntry = obj.inner.mEntry;
+
+ SimpleObject res = (SimpleObject)marshalUnmarshal(obj, marsh);
+
+ assertEquals(obj, res);
+
+ assertTrue(res.bArr == res.inner.bArr);
+ assertTrue(res.cArr == res.inner.cArr);
+ assertTrue(res.boolArr == res.inner.boolArr);
+ assertTrue(res.sArr == res.inner.sArr);
+ assertTrue(res.strArr == res.inner.strArr);
+ assertTrue(res.iArr == res.inner.iArr);
+ assertTrue(res.lArr == res.inner.lArr);
+ assertTrue(res.fArr == res.inner.fArr);
+ assertTrue(res.dArr == res.inner.dArr);
+ assertTrue(res.dateArr == res.inner.dateArr);
+ assertTrue(res.uuidArr == res.inner.uuidArr);
+ assertTrue(res.objArr == res.inner.objArr);
+ assertTrue(res.bdArr == res.inner.bdArr);
+ assertTrue(res.map == res.inner.map);
+ assertTrue(res.col == res.inner.col);
+ assertTrue(res.mEntry == res.inner.mEntry);
+ }
+
+ /**
+ *
+ */
+ private static class ObjectWithClassFields {
+ private Class<?> cls1;
+
+ private Class<?> cls2;
+ }
+
+ /**
+ *
+ */
+ private static class TestAddress {
+ /** */
+ private SimpleObject obj;
+
+ /** */
+ private InetSocketAddress addr;
+
+ /** */
+ private String str1;
+ }
+
+ /**
+ *
+ */
+ private static class Test1 {
+ /**
+ *
+ */
+ private class Job {
+
+ }
+ }
+
+ /**
+ *
+ */
+ private static class Test2 {
+ /**
+ *
+ */
+ private class Job {
+
+ }
+ }
+
+ /**
+ * @param obj Object.
+ * @return Offheap address.
+ */
+ private long copyOffheap(PortableObjectImpl obj) {
+ byte[] arr = obj.array();
+
+ long ptr = UNSAFE.allocateMemory(arr.length);
+
+ UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
+
+ return ptr;
+ }
+
+ /**
+ * @param enumArr Enum array.
+ * @return Ordinals.
+ */
+ private <T extends Enum<?>> Integer[] ordinals(T[] enumArr) {
+ Integer[] ords = new Integer[enumArr.length];
+
+ for (int i = 0; i < enumArr.length; i++)
+ ords[i] = enumArr[i].ordinal();
+
+ return ords;
+ }
+
+ /**
+ * @param po Portable object.
+ * @param off Offset.
+ * @return Value.
+ */
+ private int intFromPortable(PortableObject po, int off) {
+ byte[] arr = U.field(po, "arr");
+
+ return Integer.reverseBytes(U.bytesToInt(arr, off));
+ }
+
+ /**
+ * @param obj Original object.
+ * @return Result object.
+ */
+ private <T> T marshalUnmarshal(T obj) throws IgniteCheckedException {
+ return marshalUnmarshal(obj, new PortableMarshaller());
+ }
+
+ /**
+ * @param obj Original object.
+ * @param marsh Marshaller.
+ * @return Result object.
+ */
+ private <T> T marshalUnmarshal(Object obj, PortableMarshaller marsh) throws IgniteCheckedException {
+ initPortableContext(marsh);
+
+ byte[] bytes = marsh.marshal(obj);
+
+ return marsh.unmarshal(bytes, null);
+ }
+
+ /**
+ * @param obj Object.
+ * @param marsh Marshaller.
+ * @return Portable object.
+ */
+ private <T> PortableObjectImpl marshal(T obj, PortableMarshaller marsh) throws IgniteCheckedException {
+ initPortableContext(marsh);
+
+ byte[] bytes = marsh.marshal(obj);
+
+ return new PortableObjectImpl(U.<GridPortableMarshaller>field(marsh, "impl").context(),
+ bytes, 0);
+ }
+
+ /**
+ * @return Portable context.
+ */
+ protected PortableContext initPortableContext(PortableMarshaller marsh) throws IgniteCheckedException {
+ PortableContext ctx = new PortableContext(META_HND, null);
+
+ marsh.setContext(new MarshallerContextTestImpl(null));
+
+ IgniteUtils.invoke(PortableMarshaller.class, marsh, "setPortableContext", ctx);
+
+ return ctx;
+ }
+
+ /**
+ * @param exp Expected.
+ * @param act Actual.
+ */
+ private void assertBooleanArrayEquals(boolean[] exp, boolean[] act) {
+ assertEquals(exp.length, act.length);
+
+ for (int i = 0; i < act.length; i++)
+ assertEquals(exp[i], act[i]);
+ }
+
+ /**
+ *
+ */
+ private static class SimpleObjectWithFinal {
+ /** */
+ private final long time = System.currentTimeMillis();
+ }
+
+ /**
+ * @return Simple object.
+ */
+ private SimpleObject simpleObject() {
+ SimpleObject inner = new SimpleObject();
+
+ inner.b = 1;
+ inner.s = 1;
+ inner.i = 1;
+ inner.l = 1;
+ inner.f = 1.1f;
+ inner.d = 1.1d;
+ inner.c = 1;
+ inner.bool = true;
+ inner.str = "str1";
+ inner.uuid = UUID.randomUUID();
+ inner.date = new Date();
+ inner.ts = new Timestamp(System.currentTimeMillis());
+ inner.bArr = new byte[] {1, 2, 3};
+ inner.sArr = new short[] {1, 2, 3};
+ inner.iArr = new int[] {1, 2, 3};
+ inner.lArr = new long[] {1, 2, 3};
+ inner.fArr = new float[] {1.1f, 2.2f, 3.3f};
+ inner.dArr = new double[] {1.1d, 2.2d, 3.3d};
+ inner.cArr = new char[] {1, 2, 3};
+ inner.boolArr = new boolean[] {true, false, true};
+ inner.strArr = new String[] {"str1", "str2", "str3"};
+ inner.uuidArr = new UUID[] {UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()};
+ inner.dateArr = new Date[] {new Date(11111), new Date(22222), new Date(33333)};
+ inner.objArr = new Object[] {UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()};
+ inner.col = new ArrayList<>();
+ inner.map = new HashMap<>();
+ inner.enumVal = TestEnum.A;
+ inner.enumArr = new TestEnum[] {TestEnum.A, TestEnum.B};
+ inner.bdArr = new BigDecimal[] {new BigDecimal(1000), BigDecimal.ONE};
+
+ inner.col.add("str1");
+ inner.col.add("str2");
+ inner.col.add("str3");
+
+ inner.map.put(1, "str1");
+ inner.map.put(2, "str2");
+ inner.map.put(3, "str3");
+
+ inner.mEntry = inner.map.entrySet().iterator().next();
+
+ SimpleObject outer = new SimpleObject();
+
+ outer.b = 2;
+ outer.s = 2;
+ outer.i = 2;
+ outer.l = 2;
+ outer.f = 2.2f;
+ outer.d = 2.2d;
+ outer.c = 2;
+ outer.bool = false;
+ outer.str = "str2";
+ outer.uuid = UUID.randomUUID();
+ outer.date = new Date();
+ outer.ts = new Timestamp(System.currentTimeMillis());
+ outer.bArr = new byte[] {10, 20, 30};
+ outer.sArr = new short[] {10, 20, 30};
+ outer.iArr = new int[] {10, 20, 30};
+ outer.lArr = new long[] {10, 20, 30};
+ outer.fArr = new float[] {10.01f, 20.02f, 30.03f};
+ outer.dArr = new double[] {10.01d, 20.02d, 30.03d};
+ outer.cArr = new char[] {10, 20, 30};
+ outer.boolArr = new boolean[] {false, true, false};
+ outer.strArr = new String[] {"str10", "str20", "str30"};
+ outer.uuidArr = new UUID[] {UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()};
+ outer.dateArr = new Date[] {new Date(44444), new Date(55555), new Date(66666)};
+ outer.objArr = new Object[] {UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()};
+ outer.col = new ArrayList<>();
+ outer.map = new HashMap<>();
+ outer.enumVal = TestEnum.B;
+ outer.enumArr = new TestEnum[] {TestEnum.B, TestEnum.C};
+ outer.inner = inner;
+ outer.bdArr = new BigDecimal[] {new BigDecimal(5000), BigDecimal.TEN};
+
+
+ outer.col.add("str4");
+ outer.col.add("str5");
+ outer.col.add("str6");
+
+ outer.map.put(4, "str4");
+ outer
<TRUNCATED>
[04/11] ignite git commit: Revert "ignite-1462: hid portable API in
1.4 release" This reverts commit 71379a8061f50f336adc31fa20cd593b659b050f.
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataDisabledSelfTest.java
new file mode 100644
index 0000000..05df23b
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataDisabledSelfTest.java
@@ -0,0 +1,238 @@
+/*
+ * 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;
+
+import java.util.Arrays;
+import org.apache.ignite.IgnitePortables;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableBuilder;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMarshalAware;
+import org.apache.ignite.portable.PortableReader;
+import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.apache.ignite.portable.PortableWriter;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Test for disabled meta data.
+ */
+public class GridPortableMetaDataDisabledSelfTest extends GridCommonAbstractTest {
+ /** */
+ private PortableMarshaller marsh;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /**
+ * @return Portables.
+ */
+ private IgnitePortables portables() {
+ return grid().portables();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDisableGlobal() throws Exception {
+ marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(
+ TestObject1.class.getName(),
+ TestObject2.class.getName()
+ ));
+
+ marsh.setMetaDataEnabled(false);
+
+ try {
+ startGrid();
+
+ portables().toPortable(new TestObject1());
+ portables().toPortable(new TestObject2());
+ portables().toPortable(new TestObject3());
+
+ assertEquals(0, portables().metadata(TestObject1.class).fields().size());
+ assertEquals(0, portables().metadata(TestObject2.class).fields().size());
+
+ PortableBuilder bldr = portables().builder("FakeType");
+
+ bldr.setField("field1", 0).setField("field2", "value").build();
+
+ assertNull(portables().metadata("FakeType"));
+ assertNull(portables().metadata(TestObject3.class));
+ }
+ finally {
+ stopGrid();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDisableGlobalSimpleClass() throws Exception {
+ marsh = new PortableMarshaller();
+
+ PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(TestObject2.class.getName());
+
+ typeCfg.setMetaDataEnabled(true);
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(TestObject1.class.getName()),
+ typeCfg
+ ));
+
+ marsh.setMetaDataEnabled(false);
+
+ try {
+ startGrid();
+
+ portables().toPortable(new TestObject1());
+ portables().toPortable(new TestObject2());
+
+ assertEquals(0, portables().metadata(TestObject1.class).fields().size());
+ assertEquals(1, portables().metadata(TestObject2.class).fields().size());
+ }
+ finally {
+ stopGrid();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDisableGlobalMarshalAwareClass() throws Exception {
+ marsh = new PortableMarshaller();
+
+ PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(TestObject1.class.getName());
+
+ typeCfg.setMetaDataEnabled(true);
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(TestObject2.class.getName()),
+ typeCfg
+ ));
+
+ marsh.setMetaDataEnabled(false);
+
+ try {
+ startGrid();
+
+ portables().toPortable(new TestObject1());
+ portables().toPortable(new TestObject2());
+
+ assertEquals(1, portables().metadata(TestObject1.class).fields().size());
+ assertEquals(0, portables().metadata(TestObject2.class).fields().size());
+ }
+ finally {
+ stopGrid();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDisableSimpleClass() throws Exception {
+ marsh = new PortableMarshaller();
+
+ PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(TestObject1.class.getName());
+
+ typeCfg.setMetaDataEnabled(false);
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(TestObject2.class.getName()),
+ typeCfg
+ ));
+
+ try {
+ startGrid();
+
+ portables().toPortable(new TestObject1());
+ portables().toPortable(new TestObject2());
+
+ assertEquals(0, portables().metadata(TestObject1.class).fields().size());
+ assertEquals(1, portables().metadata(TestObject2.class).fields().size());
+ }
+ finally {
+ stopGrid();
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDisableMarshalAwareClass() throws Exception {
+ marsh = new PortableMarshaller();
+
+ PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(TestObject2.class.getName());
+
+ typeCfg.setMetaDataEnabled(false);
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration(TestObject1.class.getName()),
+ typeCfg
+ ));
+
+ try {
+ startGrid();
+
+ portables().toPortable(new TestObject1());
+ portables().toPortable(new TestObject2());
+
+ assertEquals(1, portables().metadata(TestObject1.class).fields().size());
+ assertEquals(0, portables().metadata(TestObject2.class).fields().size());
+ }
+ finally {
+ stopGrid();
+ }
+ }
+
+ /**
+ */
+ @SuppressWarnings("UnusedDeclaration")
+ private static class TestObject1 {
+ /** */
+ private int field;
+ }
+
+ /**
+ */
+ private static class TestObject2 implements PortableMarshalAware {
+ /** {@inheritDoc} */
+ @Override public void writePortable(PortableWriter writer) throws PortableException {
+ writer.writeInt("field", 1);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(PortableReader reader) throws PortableException {
+ // No-op.
+ }
+ }
+
+ /**
+ */
+ @SuppressWarnings("UnusedDeclaration")
+ private static class TestObject3 {
+ /** */
+ private int field;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java
new file mode 100644
index 0000000..fa3c9a7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java
@@ -0,0 +1,371 @@
+/*
+ * 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;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import org.apache.ignite.IgnitePortables;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMarshalAware;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.portable.PortableRawWriter;
+import org.apache.ignite.portable.PortableReader;
+import org.apache.ignite.portable.PortableWriter;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Portable meta data test.
+ */
+public class GridPortableMetaDataSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static int idx;
+
+ /** {@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()));
+
+ cfg.setMarshaller(marsh);
+
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ cfg.setCacheConfiguration(ccfg);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ idx = 0;
+
+ startGrid();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopGrid();
+ }
+
+ /**
+ * @return Portables API.
+ */
+ protected IgnitePortables portables() {
+ return grid().portables();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testGetAll() throws Exception {
+ portables().toPortable(new TestObject2());
+
+ Collection<PortableMetadata> metas = portables().metadata();
+
+ assertEquals(2, metas.size());
+
+ for (PortableMetadata meta : metas) {
+ Collection<String> fields;
+
+ switch (meta.typeName()) {
+ case "TestObject1":
+ fields = meta.fields();
+
+ assertEquals(7, fields.size());
+
+ assertTrue(fields.contains("intVal"));
+ assertTrue(fields.contains("strVal"));
+ assertTrue(fields.contains("arrVal"));
+ assertTrue(fields.contains("obj1Val"));
+ assertTrue(fields.contains("obj2Val"));
+ assertTrue(fields.contains("decVal"));
+ assertTrue(fields.contains("decArrVal"));
+
+ assertEquals("int", meta.fieldTypeName("intVal"));
+ assertEquals("String", meta.fieldTypeName("strVal"));
+ assertEquals("byte[]", meta.fieldTypeName("arrVal"));
+ assertEquals("Object", meta.fieldTypeName("obj1Val"));
+ assertEquals("Object", meta.fieldTypeName("obj2Val"));
+ assertEquals("decimal", meta.fieldTypeName("decVal"));
+ assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+
+ break;
+
+ case "TestObject2":
+ fields = meta.fields();
+
+ assertEquals(7, fields.size());
+
+ assertTrue(fields.contains("boolVal"));
+ assertTrue(fields.contains("dateVal"));
+ assertTrue(fields.contains("uuidArrVal"));
+ assertTrue(fields.contains("objVal"));
+ assertTrue(fields.contains("mapVal"));
+ assertTrue(fields.contains("decVal"));
+ assertTrue(fields.contains("decArrVal"));
+
+ assertEquals("boolean", meta.fieldTypeName("boolVal"));
+ assertEquals("Date", meta.fieldTypeName("dateVal"));
+ assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
+ assertEquals("Object", meta.fieldTypeName("objVal"));
+ assertEquals("Map", meta.fieldTypeName("mapVal"));
+ assertEquals("decimal", meta.fieldTypeName("decVal"));
+ assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+
+ break;
+
+ default:
+ assert false : meta.typeName();
+ }
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testNoConfiguration() throws Exception {
+ fail("https://issues.apache.org/jira/browse/IGNITE-1377");
+
+ portables().toPortable(new TestObject3());
+
+ assertNotNull(portables().metadata(TestObject3.class));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testReflection() throws Exception {
+ PortableMetadata meta = portables().metadata(TestObject1.class);
+
+ assertNotNull(meta);
+
+ assertEquals("TestObject1", meta.typeName());
+
+ Collection<String> fields = meta.fields();
+
+ assertEquals(7, fields.size());
+
+ assertTrue(fields.contains("intVal"));
+ assertTrue(fields.contains("strVal"));
+ assertTrue(fields.contains("arrVal"));
+ assertTrue(fields.contains("obj1Val"));
+ assertTrue(fields.contains("obj2Val"));
+ assertTrue(fields.contains("decVal"));
+ assertTrue(fields.contains("decArrVal"));
+
+ assertEquals("int", meta.fieldTypeName("intVal"));
+ assertEquals("String", meta.fieldTypeName("strVal"));
+ assertEquals("byte[]", meta.fieldTypeName("arrVal"));
+ assertEquals("Object", meta.fieldTypeName("obj1Val"));
+ assertEquals("Object", meta.fieldTypeName("obj2Val"));
+ assertEquals("decimal", meta.fieldTypeName("decVal"));
+ assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableMarshalAware() throws Exception {
+ portables().toPortable(new TestObject2());
+
+ PortableMetadata meta = portables().metadata(TestObject2.class);
+
+ assertNotNull(meta);
+
+ assertEquals("TestObject2", meta.typeName());
+
+ Collection<String> fields = meta.fields();
+
+ assertEquals(7, fields.size());
+
+ assertTrue(fields.contains("boolVal"));
+ assertTrue(fields.contains("dateVal"));
+ assertTrue(fields.contains("uuidArrVal"));
+ assertTrue(fields.contains("objVal"));
+ assertTrue(fields.contains("mapVal"));
+ assertTrue(fields.contains("decVal"));
+ assertTrue(fields.contains("decArrVal"));
+
+ assertEquals("boolean", meta.fieldTypeName("boolVal"));
+ assertEquals("Date", meta.fieldTypeName("dateVal"));
+ assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
+ assertEquals("Object", meta.fieldTypeName("objVal"));
+ assertEquals("Map", meta.fieldTypeName("mapVal"));
+ assertEquals("decimal", meta.fieldTypeName("decVal"));
+ assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMerge() throws Exception {
+ portables().toPortable(new TestObject2());
+
+ idx = 1;
+
+ portables().toPortable(new TestObject2());
+
+ PortableMetadata meta = portables().metadata(TestObject2.class);
+
+ assertNotNull(meta);
+
+ assertEquals("TestObject2", meta.typeName());
+
+ Collection<String> fields = meta.fields();
+
+ assertEquals(9, fields.size());
+
+ assertTrue(fields.contains("boolVal"));
+ assertTrue(fields.contains("dateVal"));
+ assertTrue(fields.contains("uuidArrVal"));
+ assertTrue(fields.contains("objVal"));
+ assertTrue(fields.contains("mapVal"));
+ assertTrue(fields.contains("charVal"));
+ assertTrue(fields.contains("colVal"));
+ assertTrue(fields.contains("decVal"));
+ assertTrue(fields.contains("decArrVal"));
+
+ assertEquals("boolean", meta.fieldTypeName("boolVal"));
+ assertEquals("Date", meta.fieldTypeName("dateVal"));
+ assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
+ assertEquals("Object", meta.fieldTypeName("objVal"));
+ assertEquals("Map", meta.fieldTypeName("mapVal"));
+ assertEquals("char", meta.fieldTypeName("charVal"));
+ assertEquals("Collection", meta.fieldTypeName("colVal"));
+ assertEquals("decimal", meta.fieldTypeName("decVal"));
+ assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testSerializedObject() throws Exception {
+ TestObject1 obj = new TestObject1();
+
+ obj.intVal = 10;
+ obj.strVal = "str";
+ obj.arrVal = new byte[] {2, 4, 6};
+ obj.obj1Val = null;
+ obj.obj2Val = new TestObject2();
+ obj.decVal = BigDecimal.ZERO;
+ obj.decArrVal = new BigDecimal[] { BigDecimal.ONE };
+
+ PortableObject po = portables().toPortable(obj);
+
+ info(po.toString());
+
+ PortableMetadata meta = po.metaData();
+
+ assertNotNull(meta);
+
+ assertEquals("TestObject1", meta.typeName());
+
+ Collection<String> fields = meta.fields();
+
+ assertEquals(7, fields.size());
+
+ assertTrue(fields.contains("intVal"));
+ assertTrue(fields.contains("strVal"));
+ assertTrue(fields.contains("arrVal"));
+ assertTrue(fields.contains("obj1Val"));
+ assertTrue(fields.contains("obj2Val"));
+ assertTrue(fields.contains("decVal"));
+ assertTrue(fields.contains("decArrVal"));
+
+ assertEquals("int", meta.fieldTypeName("intVal"));
+ assertEquals("String", meta.fieldTypeName("strVal"));
+ assertEquals("byte[]", meta.fieldTypeName("arrVal"));
+ assertEquals("Object", meta.fieldTypeName("obj1Val"));
+ assertEquals("Object", meta.fieldTypeName("obj2Val"));
+ assertEquals("decimal", meta.fieldTypeName("decVal"));
+ assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+ }
+
+ /**
+ */
+ @SuppressWarnings("UnusedDeclaration")
+ private static class TestObject1 {
+ /** */
+ private int intVal;
+
+ /** */
+ private String strVal;
+
+ /** */
+ private byte[] arrVal;
+
+ /** */
+ private TestObject1 obj1Val;
+
+ /** */
+ private TestObject2 obj2Val;
+
+ /** */
+ private BigDecimal decVal;
+
+ /** */
+ private BigDecimal[] decArrVal;
+ }
+
+ /**
+ */
+ private static class TestObject2 implements PortableMarshalAware {
+ /** {@inheritDoc} */
+ @Override public void writePortable(PortableWriter writer) throws PortableException {
+ writer.writeBoolean("boolVal", false);
+ writer.writeDate("dateVal", new Date());
+ writer.writeUuidArray("uuidArrVal", null);
+ writer.writeObject("objVal", null);
+ writer.writeMap("mapVal", new HashMap<>());
+ writer.writeDecimal("decVal", BigDecimal.ZERO);
+ writer.writeDecimalArray("decArrVal", new BigDecimal[] { BigDecimal.ONE });
+
+ if (idx == 1) {
+ writer.writeChar("charVal", (char)0);
+ writer.writeCollection("colVal", null);
+ }
+
+ PortableRawWriter raw = writer.rawWriter();
+
+ raw.writeChar((char)0);
+ raw.writeCollection(null);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(PortableReader reader) throws PortableException {
+ // No-op.
+ }
+ }
+
+ /**
+ */
+ @SuppressWarnings("UnusedDeclaration")
+ private static class TestObject3 {
+ /** */
+ private int intVal;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
new file mode 100644
index 0000000..349f152
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
@@ -0,0 +1,482 @@
+/*
+ * 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;
+
+import java.util.Arrays;
+import java.util.Map;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableIdMapper;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Wildcards test.
+ */
+public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final PortableMetaDataHandler META_HND = new PortableMetaDataHandler() {
+ @Override public void addMeta(int typeId, PortableMetadata meta) {
+ // No-op.
+ }
+
+ @Override public PortableMetadata metadata(int typeId) {
+ return null;
+ }
+ };
+
+ /**
+ * @return Portable context.
+ */
+ private PortableContext portableContext() {
+ return new PortableContext(META_HND, null);
+ }
+
+ /**
+ * @return Portable marshaller.
+ */
+ private PortableMarshaller portableMarshaller() {
+ PortableMarshaller marsh = new PortableMarshaller();
+ marsh.setContext(new MarshallerContextTestImpl(null));
+
+ return marsh;
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClassNames() throws Exception {
+ PortableContext ctx = portableContext();
+
+ PortableMarshaller marsh = portableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(
+ "org.apache.ignite.internal.portable.test.*",
+ "unknown.*"
+ ));
+
+ ctx.configure(marsh);
+
+ Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+ assertEquals(3, typeIds.size());
+
+ assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+ assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
+ assertTrue(typeIds.containsKey("innerclass".hashCode()));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClassNamesWithMapper() throws Exception {
+ PortableContext ctx = portableContext();
+
+ PortableMarshaller marsh = portableMarshaller();
+
+ marsh.setIdMapper(new PortableIdMapper() {
+ @SuppressWarnings("IfMayBeConditional")
+ @Override public int typeId(String clsName) {
+ if (clsName.endsWith("1"))
+ return 300;
+ else if (clsName.endsWith("2"))
+ return 400;
+ else if (clsName.endsWith("InnerClass"))
+ return 500;
+ else
+ return -500;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ marsh.setClassNames(Arrays.asList(
+ "org.apache.ignite.internal.portable.test.*",
+ "unknown.*"
+ ));
+
+ ctx.configure(marsh);
+
+ Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+ assertEquals(3, typeMappers.size());
+
+ assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+ assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+ assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTypeConfigurations() throws Exception {
+ PortableContext ctx = portableContext();
+
+ PortableMarshaller marsh = portableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
+ new PortableTypeConfiguration("unknown.*")
+ ));
+
+ ctx.configure(marsh);
+
+ Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+ assertEquals(3, typeIds.size());
+
+ assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+ assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
+ assertTrue(typeIds.containsKey("innerclass".hashCode()));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTypeConfigurationsWithGlobalMapper() throws Exception {
+ PortableContext ctx = portableContext();
+
+ PortableMarshaller marsh = portableMarshaller();
+
+ marsh.setIdMapper(new PortableIdMapper() {
+ @SuppressWarnings("IfMayBeConditional")
+ @Override public int typeId(String clsName) {
+ if (clsName.endsWith("1"))
+ return 300;
+ else if (clsName.endsWith("2"))
+ return 400;
+ else if (clsName.endsWith("InnerClass"))
+ return 500;
+ else
+ return -500;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
+ new PortableTypeConfiguration("unknown.*")
+ ));
+
+ ctx.configure(marsh);
+
+ Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+ assertEquals(3, typeMappers.size());
+
+ assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+ assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+ assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTypeConfigurationsWithNonGlobalMapper() throws Exception {
+ PortableContext ctx = portableContext();
+
+ PortableMarshaller marsh = portableMarshaller();
+
+ marsh.setIdMapper(new PortableIdMapper() {
+ @SuppressWarnings("IfMayBeConditional")
+ @Override public int typeId(String clsName) {
+ if (clsName.endsWith("1"))
+ return 300;
+ else if (clsName.endsWith("2"))
+ return 400;
+ else if (clsName.endsWith("InnerClass"))
+ return 500;
+ else
+ return -500;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
+ new PortableTypeConfiguration("unknown.*")
+ ));
+
+ ctx.configure(marsh);
+
+ Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+ assertEquals(3, typeMappers.size());
+
+ assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+ assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+ assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testOverride() throws Exception {
+ PortableContext ctx = portableContext();
+
+ PortableMarshaller marsh = portableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(
+ "org.apache.ignite.internal.portable.test.*"
+ ));
+
+ PortableTypeConfiguration typeCfg = new PortableTypeConfiguration();
+
+ typeCfg.setClassName("org.apache.ignite.internal.portable.test.GridPortableTestClass2");
+ typeCfg.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 100;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ marsh.setTypeConfigurations(Arrays.asList(typeCfg));
+
+ ctx.configure(marsh);
+
+ Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+ assertEquals(3, typeIds.size());
+
+ assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+ assertTrue(typeIds.containsKey("innerclass".hashCode()));
+ assertFalse(typeIds.containsKey("gridportabletestclass2".hashCode()));
+
+ Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+ assertEquals(100, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClassNamesJar() throws Exception {
+ PortableContext ctx = portableContext();
+
+ PortableMarshaller marsh = portableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(
+ "org.apache.ignite.portable.testjar.*",
+ "unknown.*"
+ ));
+
+ ctx.configure(marsh);
+
+ Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+ assertEquals(3, typeIds.size());
+
+ assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+ assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testClassNamesWithMapperJar() throws Exception {
+ PortableContext ctx = portableContext();
+
+ PortableMarshaller marsh = portableMarshaller();
+
+ marsh.setIdMapper(new PortableIdMapper() {
+ @SuppressWarnings("IfMayBeConditional")
+ @Override public int typeId(String clsName) {
+ if (clsName.endsWith("1"))
+ return 300;
+ else if (clsName.endsWith("2"))
+ return 400;
+ else
+ return -500;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ marsh.setClassNames(Arrays.asList(
+ "org.apache.ignite.portable.testjar.*",
+ "unknown.*"
+ ));
+
+ ctx.configure(marsh);
+
+ Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+ assertEquals(3, typeMappers.size());
+
+ assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+ assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTypeConfigurationsJar() throws Exception {
+ PortableContext ctx = portableContext();
+
+ PortableMarshaller marsh = portableMarshaller();
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration("org.apache.ignite.portable.testjar.*"),
+ new PortableTypeConfiguration("unknown.*")
+ ));
+
+ ctx.configure(marsh);
+
+ Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+ assertEquals(3, typeIds.size());
+
+ assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+ assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTypeConfigurationsWithGlobalMapperJar() throws Exception {
+ PortableContext ctx = portableContext();
+
+ PortableMarshaller marsh = portableMarshaller();
+
+ marsh.setIdMapper(new PortableIdMapper() {
+ @SuppressWarnings("IfMayBeConditional")
+ @Override public int typeId(String clsName) {
+ if (clsName.endsWith("1"))
+ return 300;
+ else if (clsName.endsWith("2"))
+ return 400;
+ else
+ return -500;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration("org.apache.ignite.portable.testjar.*"),
+ new PortableTypeConfiguration("unknown.*")
+ ));
+
+ ctx.configure(marsh);
+
+ Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+ assertEquals(3, typeMappers.size());
+
+ assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+ assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testTypeConfigurationsWithNonGlobalMapperJar() throws Exception {
+ PortableContext ctx = portableContext();
+
+ PortableMarshaller marsh = portableMarshaller();
+
+ marsh.setIdMapper(new PortableIdMapper() {
+ @SuppressWarnings("IfMayBeConditional")
+ @Override public int typeId(String clsName) {
+ if (clsName.endsWith("1"))
+ return 300;
+ else if (clsName.endsWith("2"))
+ return 400;
+ else
+ return -500;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ marsh.setTypeConfigurations(Arrays.asList(
+ new PortableTypeConfiguration("org.apache.ignite.portable.testjar.*"),
+ new PortableTypeConfiguration("unknown.*")
+ ));
+
+ ctx.configure(marsh);
+
+ Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+ assertEquals(3, typeMappers.size());
+
+ assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+ assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testOverrideJar() throws Exception {
+ PortableContext ctx = portableContext();
+
+ PortableMarshaller marsh = portableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(
+ "org.apache.ignite.portable.testjar.*"
+ ));
+
+ PortableTypeConfiguration typeCfg = new PortableTypeConfiguration(
+ "org.apache.ignite.portable.testjar.GridPortableTestClass2");
+
+ typeCfg.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return 100;
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return 0;
+ }
+ });
+
+ marsh.setTypeConfigurations(Arrays.asList(typeCfg));
+
+ ctx.configure(marsh);
+
+ Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+ assertEquals(3, typeIds.size());
+
+ assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+
+ Map<String, PortableIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+ assertEquals(3, typeMappers.size());
+
+ assertEquals(100, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/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
new file mode 100644
index 0000000..3244331
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.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.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/e7eb2b37/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
new file mode 100644
index 0000000..e49514b
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
@@ -0,0 +1,434 @@
+/*
+ * 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 com.google.common.base.Throwables;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+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;
+
+/**
+ *
+ */
+@SuppressWarnings({"PublicInnerClass", "PublicField"})
+public class GridPortableTestClasses {
+ /**
+ *
+ */
+ public static class TestObjectContainer {
+ /** */
+ public Object foo;
+
+ /**
+ *
+ */
+ public TestObjectContainer() {
+ // No-op.
+ }
+
+ /**
+ * @param foo Object.
+ */
+ public TestObjectContainer(Object foo) {
+ this.foo = foo;
+ }
+ }
+
+ /**
+ *
+ */
+ public static class TestObjectOuter {
+ /** */
+ public TestObjectInner inner;
+
+ /** */
+ public String foo;
+
+ /**
+ *
+ */
+ public TestObjectOuter() {
+
+ }
+
+ /**
+ * @param inner Inner object.
+ */
+ public TestObjectOuter(TestObjectInner inner) {
+ this.inner = inner;
+ }
+ }
+
+ /** */
+ public static class TestObjectInner {
+ /** */
+ public Object foo;
+
+ /** */
+ public TestObjectOuter outer;
+ }
+
+ /** */
+ public static class TestObjectArrayList {
+ /** */
+ public List<String> list = new ArrayList<>();
+ }
+
+ /**
+ *
+ */
+ public static class TestObjectPlainPortable {
+ /** */
+ public PortableObject plainPortable;
+
+ /**
+ *
+ */
+ public TestObjectPlainPortable() {
+ // No-op.
+ }
+
+ /**
+ * @param plainPortable Object.
+ */
+ public TestObjectPlainPortable(PortableObject plainPortable) {
+ this.plainPortable = plainPortable;
+ }
+ }
+
+ /**
+ *
+ */
+ public static class TestObjectAllTypes implements Serializable {
+ /** */
+ public Byte b_;
+
+ /** */
+ public Short s_;
+
+ /** */
+ public Integer i_;
+
+ /** */
+ public Long l_;
+
+ /** */
+ public Float f_;
+
+ /** */
+ public Double d_;
+
+ /** */
+ public Character c_;
+
+ /** */
+ public Boolean z_;
+
+ /** */
+ public byte b;
+
+ /** */
+ public short s;
+
+ /** */
+ public int i;
+
+ /** */
+ public long l;
+
+ /** */
+ public float f;
+
+ /** */
+ public double d;
+
+ /** */
+ public char c;
+
+ /** */
+ public boolean z;
+
+ /** */
+ public String str;
+
+ /** */
+ public UUID uuid;
+
+ /** */
+ public Date date;
+
+ /** */
+ public byte[] bArr;
+
+ /** */
+ public short[] sArr;
+
+ /** */
+ public int[] iArr;
+
+ /** */
+ public long[] lArr;
+
+ /** */
+ public float[] fArr;
+
+ /** */
+ public double[] dArr;
+
+ /** */
+ public char[] cArr;
+
+ /** */
+ public boolean[] zArr;
+
+ /** */
+ public BigDecimal[] bdArr;
+
+ /** */
+ public String[] strArr;
+
+ /** */
+ public UUID[] uuidArr;
+
+ /** */
+ public Date[] dateArr;
+
+ /** */
+ public TestObjectEnum anEnum;
+
+ /** */
+ public TestObjectEnum[] enumArr;
+
+ /** */
+ public Map.Entry entry;
+
+ /**
+ * @return Array.
+ */
+ private byte[] serialize() {
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+
+ try {
+ ObjectOutput out = new ObjectOutputStream(byteOut);
+
+ out.writeObject(this);
+
+ out.close();
+ }
+ catch (IOException e) {
+ Throwables.propagate(e);
+ }
+
+ return byteOut.toByteArray();
+ }
+
+ /**
+ *
+ */
+ public void setDefaultData() {
+ b_ = 11;
+ s_ = 22;
+ i_ = 33;
+ l_ = 44L;
+ f_ = 55f;
+ d_ = 66d;
+ c_ = 'e';
+ z_ = true;
+
+ b = 1;
+ s = 2;
+ i = 3;
+ l = 4;
+ f = 5;
+ d = 6;
+ c = 7;
+ z = true;
+
+ str = "abc";
+ uuid = new UUID(1, 1);
+ date = new Date(1000000);
+
+ bArr = new byte[] {1, 2, 3};
+ sArr = new short[] {1, 2, 3};
+ iArr = new int[] {1, 2, 3};
+ lArr = new long[] {1, 2, 3};
+ fArr = new float[] {1, 2, 3};
+ dArr = new double[] {1, 2, 3};
+ cArr = new char[] {1, 2, 3};
+ zArr = new boolean[] {true, false};
+
+ strArr = new String[] {"abc", "ab", "a"};
+ uuidArr = new UUID[] {new UUID(1, 1), new UUID(2, 2)};
+ bdArr = new BigDecimal[] {new BigDecimal(1000), BigDecimal.TEN};
+ dateArr = new Date[] {new Date(1000000), new Date(200000)};
+
+ anEnum = TestObjectEnum.A;
+
+ enumArr = new TestObjectEnum[] {TestObjectEnum.B};
+
+ entry = new GridMapEntry<>(1, "a");
+ }
+ }
+
+ /**
+ *
+ */
+ public enum TestObjectEnum {
+ A, B, C
+ }
+
+ /**
+ *
+ */
+ public static class Address {
+ /** City. */
+ public String city;
+
+ /** Street. */
+ public String street;
+
+ /** Street number. */
+ public int streetNumber;
+
+ /** Flat number. */
+ public int flatNumber;
+
+ /**
+ * Default constructor.
+ */
+ public Address() {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param city City.
+ * @param street Street.
+ * @param streetNumber Street number.
+ * @param flatNumber Flat number.
+ */
+ public Address(String city, String street, int streetNumber, int flatNumber) {
+ this.city = city;
+ this.street = street;
+ this.streetNumber = streetNumber;
+ this.flatNumber = flatNumber;
+ }
+ }
+
+ /**
+ *
+ */
+ public static class Company {
+ /** ID. */
+ public int id;
+
+ /** Name. */
+ public String name;
+
+ /** Size. */
+ public int size;
+
+ /** Address. */
+ public Address address;
+
+ /** Occupation. */
+ public String occupation;
+
+ /**
+ * Default constructor.
+ */
+ public Company() {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param id ID.
+ * @param name Name.
+ * @param size Size.
+ * @param address Address.
+ * @param occupation Occupation.
+ */
+ public Company(int id, String name, int size, Address address, String occupation) {
+ this.id = id;
+ this.name = name;
+ this.size = size;
+ this.address = address;
+ this.occupation = occupation;
+ }
+ }
+
+ /**
+ *
+ */
+ public static class AddressBook {
+ /** */
+ private Map<String, List<Company>> companyByStreet = new TreeMap<>();
+
+ /**
+ * @param street Street.
+ * @return Company.
+ */
+ public List<Company> findCompany(String street) {
+ return companyByStreet.get(street);
+ }
+
+ /**
+ * @param company Company.
+ */
+ public void addCompany(Company company) {
+ List<Company> list = companyByStreet.get(company.address.street);
+
+ if (list == null) {
+ list = new ArrayList<>();
+
+ companyByStreet.put(company.address.street, list);
+ }
+
+ list.add(company);
+ }
+
+ /**
+ * @return map
+ */
+ public Map<String, List<Company>> getCompanyByStreet() {
+ return companyByStreet;
+ }
+
+ /**
+ * @param companyByStreet map
+ */
+ public void setCompanyByStreet(Map<String, List<Company>> companyByStreet) {
+ this.companyByStreet = companyByStreet;
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/package-info.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/package-info.java
new file mode 100644
index 0000000..daa13d5
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains internal tests or test related classes and interfaces.
+ */
+package org.apache.ignite.internal.portable.mutabletest;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/package-info.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/package-info.java
new file mode 100644
index 0000000..26897e6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains internal tests or test related classes and interfaces.
+ */
+package org.apache.ignite.internal.portable;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass1.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass1.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass1.java
new file mode 100644
index 0000000..05a8c33
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass1.java
@@ -0,0 +1,28 @@
+/*
+ * 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.test;
+
+/**
+ */
+public class GridPortableTestClass1 {
+ /**
+ */
+ private static class InnerClass {
+ // No-op.
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass2.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass2.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass2.java
new file mode 100644
index 0000000..ba69991
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass2.java
@@ -0,0 +1,24 @@
+/*
+ * 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.test;
+
+/**
+ */
+public class GridPortableTestClass2 {
+ // No-op.
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/test/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/package-info.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/package-info.java
new file mode 100644
index 0000000..e63b814
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains internal tests or test related classes and interfaces.
+ */
+package org.apache.ignite.internal.portable.test;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/GridPortableTestClass3.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/GridPortableTestClass3.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/GridPortableTestClass3.java
new file mode 100644
index 0000000..cf3aa2d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/GridPortableTestClass3.java
@@ -0,0 +1,24 @@
+/*
+ * 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.test.subpackage;
+
+/**
+ */
+public class GridPortableTestClass3 {
+ // No-op.
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/package-info.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/package-info.java
new file mode 100644
index 0000000..ae8ee73
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains internal tests or test related classes and interfaces.
+ */
+package org.apache.ignite.internal.portable.test.subpackage;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/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
new file mode 100644
index 0000000..1ba3d4d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataMultinodeTest.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.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/e7eb2b37/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
new file mode 100644
index 0000000..a66d940
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodePortableMetadataTest.java
@@ -0,0 +1,286 @@
+/*
+ * 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
[11/11] ignite git commit: Revert "ignite-1462: hid portable API in
1.4 release" This reverts commit 71379a8061f50f336adc31fa20cd593b659b050f.
Posted by sb...@apache.org.
Revert "ignite-1462: hid portable API in 1.4 release"
This reverts commit 71379a8061f50f336adc31fa20cd593b659b050f.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e7eb2b37
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e7eb2b37
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e7eb2b37
Branch: refs/heads/ignite-1486
Commit: e7eb2b372dfc62228c308ad5a68ac04d97ff6737
Parents: 7955c15
Author: Denis Magda <dm...@gridgain.com>
Authored: Tue Sep 15 09:26:58 2015 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Tue Sep 15 09:26:59 2015 +0300
----------------------------------------------------------------------
examples/config/example-default.xml | 76 +
examples/config/example-ignite.xml | 56 +-
.../config/portable/example-ignite-portable.xml | 44 +
.../ignite/examples/portable/Address.java | 72 +
.../ignite/examples/portable/Employee.java | 93 +
.../ignite/examples/portable/EmployeeKey.java | 90 +
.../portable/ExamplePortableNodeStartup.java | 36 +
.../ignite/examples/portable/Organization.java | 93 +
.../examples/portable/OrganizationType.java | 32 +
...mputeClientPortableTaskExecutionExample.java | 154 +
.../portable/computegrid/ComputeClientTask.java | 116 +
.../portable/computegrid/package-info.java | 21 +
.../CacheClientPortablePutGetExample.java | 230 ++
.../CacheClientPortableQueryExample.java | 325 ++
.../portable/datagrid/package-info.java | 21 +
.../ignite/examples/portable/package-info.java | 21 +
.../CacheClientPortableExampleTest.java | 46 +
.../ComputeClientPortableExampleTest.java | 37 +
.../testsuites/IgniteExamplesSelfTestSuite.java | 6 +
modules/core/pom.xml | 21 +
.../src/main/java/org/apache/ignite/Ignite.java | 7 +
.../java/org/apache/ignite/IgniteCache.java | 44 +-
.../java/org/apache/ignite/IgnitePortables.java | 370 ++
.../configuration/CacheConfiguration.java | 70 +-
.../org/apache/ignite/internal/IgniteEx.java | 9 -
.../apache/ignite/internal/IgniteKernal.java | 8 +-
.../ignite/internal/IgniteNodeAttributes.java | 5 +-
.../discovery/GridDiscoveryManager.java | 10 +
.../portable/GridPortableMarshaller.java | 2 +-
.../portable/PortableClassDescriptor.java | 10 +-
.../internal/portable/PortableContext.java | 14 +-
.../portable/PortableMetaDataCollector.java | 6 +-
.../portable/PortableMetaDataHandler.java | 4 +-
.../internal/portable/PortableMetaDataImpl.java | 14 +-
.../internal/portable/PortableObjectEx.java | 6 +-
.../internal/portable/PortableObjectImpl.java | 6 +-
.../portable/PortableObjectOffheapImpl.java | 6 +-
.../internal/portable/PortableRawReaderEx.java | 4 +-
.../internal/portable/PortableRawWriterEx.java | 4 +-
.../portable/PortableReaderContext.java | 2 +-
.../internal/portable/PortableReaderExImpl.java | 10 +-
.../ignite/internal/portable/PortableUtils.java | 2 +-
.../internal/portable/PortableWriterExImpl.java | 11 +-
.../internal/portable/api/IgnitePortables.java | 362 --
.../internal/portable/api/PortableBuilder.java | 136 -
.../portable/api/PortableException.java | 57 -
.../internal/portable/api/PortableIdMapper.java | 54 -
.../api/PortableInvalidClassException.java | 58 -
.../portable/api/PortableMarshalAware.java | 48 -
.../portable/api/PortableMarshaller.java | 358 --
.../internal/portable/api/PortableMetadata.java | 60 -
.../internal/portable/api/PortableObject.java | 152 -
.../portable/api/PortableProtocolVersion.java | 41 -
.../portable/api/PortableRawReader.java | 234 --
.../portable/api/PortableRawWriter.java | 219 -
.../internal/portable/api/PortableReader.java | 284 --
.../portable/api/PortableSerializer.java | 47 -
.../portable/api/PortableTypeConfiguration.java | 195 -
.../internal/portable/api/PortableWriter.java | 266 --
.../portable/builder/PortableBuilderEnum.java | 2 +-
.../portable/builder/PortableBuilderImpl.java | 14 +-
.../portable/builder/PortableBuilderReader.java | 2 +-
.../builder/PortableBuilderSerializer.java | 2 +-
.../builder/PortableEnumArrayLazyValue.java | 4 +-
.../builder/PortableObjectArrayLazyValue.java | 2 +-
.../builder/PortablePlainPortableObject.java | 2 +-
.../streams/PortableAbstractInputStream.java | 2 +-
.../processors/cache/GridCacheProcessor.java | 8 +-
.../processors/cache/IgniteCacheProxy.java | 5 +
.../CacheDefaultPortableAffinityKeyMapper.java | 2 +-
.../portable/CacheObjectPortableContext.java | 2 +-
.../portable/CacheObjectPortableProcessor.java | 8 +-
.../CacheObjectPortableProcessorImpl.java | 12 +-
.../cache/portable/IgnitePortablesImpl.java | 10 +-
.../cache/store/CacheOsStoreManager.java | 4 +-
.../dotnet/PlatformDotNetConfiguration.java | 12 +-
.../PlatformDotNetPortableConfiguration.java | 12 +-
...PlatformDotNetPortableTypeConfiguration.java | 12 +-
.../marshaller/portable/PortableMarshaller.java | 358 ++
.../marshaller/portable/package-info.java | 22 +
.../apache/ignite/portable/PortableBuilder.java | 137 +
.../ignite/portable/PortableException.java | 57 +
.../ignite/portable/PortableIdMapper.java | 56 +
.../portable/PortableInvalidClassException.java | 58 +
.../ignite/portable/PortableMarshalAware.java | 48 +
.../ignite/portable/PortableMetadata.java | 61 +
.../apache/ignite/portable/PortableObject.java | 154 +
.../portable/PortableProtocolVersion.java | 41 +
.../ignite/portable/PortableRawReader.java | 234 ++
.../ignite/portable/PortableRawWriter.java | 219 +
.../apache/ignite/portable/PortableReader.java | 284 ++
.../ignite/portable/PortableSerializer.java | 49 +
.../portable/PortableTypeConfiguration.java | 196 +
.../apache/ignite/portable/PortableWriter.java | 266 ++
.../apache/ignite/portable/package-info.java | 22 +
.../resources/META-INF/classnames.properties | 8 +-
.../GridDiscoveryManagerAttributesSelfTest.java | 45 +
.../GridPortableAffinityKeySelfTest.java | 218 +
.../GridPortableBuilderAdditionalSelfTest.java | 1226 ++++++
.../portable/GridPortableBuilderSelfTest.java | 1021 +++++
...eBuilderStringAsCharsAdditionalSelfTest.java | 28 +
...ridPortableBuilderStringAsCharsSelfTest.java | 28 +
...idPortableMarshallerCtxDisabledSelfTest.java | 256 ++
.../GridPortableMarshallerSelfTest.java | 3807 ++++++++++++++++++
.../GridPortableMetaDataDisabledSelfTest.java | 238 ++
.../portable/GridPortableMetaDataSelfTest.java | 371 ++
.../portable/GridPortableWildcardsSelfTest.java | 482 +++
.../GridPortableMarshalerAwareTestClass.java | 67 +
.../mutabletest/GridPortableTestClasses.java | 434 ++
.../portable/mutabletest/package-info.java | 22 +
.../ignite/internal/portable/package-info.java | 22 +
.../portable/test/GridPortableTestClass1.java | 28 +
.../portable/test/GridPortableTestClass2.java | 24 +
.../internal/portable/test/package-info.java | 22 +
.../test/subpackage/GridPortableTestClass3.java | 24 +
.../portable/test/subpackage/package-info.java | 22 +
...ClientNodePortableMetadataMultinodeTest.java | 295 ++
...GridCacheClientNodePortableMetadataTest.java | 286 ++
...ableObjectsAbstractDataStreamerSelfTest.java | 190 +
...bleObjectsAbstractMultiThreadedSelfTest.java | 231 ++
...ridCachePortableObjectsAbstractSelfTest.java | 978 +++++
.../GridCachePortableStoreAbstractSelfTest.java | 297 ++
.../GridCachePortableStoreObjectsSelfTest.java | 55 +
...GridCachePortableStorePortablesSelfTest.java | 66 +
...ridPortableCacheEntryMemorySizeSelfTest.java | 55 +
...leDuplicateIndexObjectsAbstractSelfTest.java | 158 +
.../DataStreamProcessorPortableSelfTest.java | 66 +
.../GridDataStreamerImplSelfTest.java | 345 ++
...ridCacheAffinityRoutingPortableSelfTest.java | 47 +
...lyPortableDataStreamerMultiNodeSelfTest.java | 29 +
...rtableDataStreamerMultithreadedSelfTest.java | 47 +
...artitionedOnlyPortableMultiNodeSelfTest.java | 28 +
...tionedOnlyPortableMultithreadedSelfTest.java | 47 +
.../GridCacheMemoryModePortableSelfTest.java | 36 +
...acheOffHeapTieredAtomicPortableSelfTest.java | 47 +
...eapTieredEvictionAtomicPortableSelfTest.java | 95 +
...heOffHeapTieredEvictionPortableSelfTest.java | 95 +
.../GridCacheOffHeapTieredPortableSelfTest.java | 47 +
...ateIndexObjectPartitionedAtomicSelfTest.java | 38 +
...xObjectPartitionedTransactionalSelfTest.java | 41 +
...AtomicNearDisabledOffheapTieredSelfTest.java | 29 +
...rtableObjectsAtomicNearDisabledSelfTest.java | 51 +
...tableObjectsAtomicOffheapTieredSelfTest.java | 29 +
.../GridCachePortableObjectsAtomicSelfTest.java | 51 +
...tionedNearDisabledOffheapTieredSelfTest.java | 30 +
...eObjectsPartitionedNearDisabledSelfTest.java | 51 +
...ObjectsPartitionedOffheapTieredSelfTest.java | 30 +
...CachePortableObjectsPartitionedSelfTest.java | 51 +
...sNearPartitionedByteArrayValuesSelfTest.java | 41 +
...sPartitionedOnlyByteArrayValuesSelfTest.java | 42 +
...dCachePortableObjectsReplicatedSelfTest.java | 51 +
...CachePortableObjectsAtomicLocalSelfTest.java | 32 +
...rtableObjectsLocalOffheapTieredSelfTest.java | 29 +
.../GridCachePortableObjectsLocalSelfTest.java | 51 +
.../ignite/testframework/junits/IgniteMock.java | 8 +-
.../multijvm/IgniteCacheProcessProxy.java | 5 +
.../junits/multijvm/IgniteProcessProxy.java | 2 +-
.../IgnitePortableCacheFullApiTestSuite.java | 37 +
.../IgnitePortableCacheTestSuite.java | 103 +
.../IgnitePortableObjectsTestSuite.java | 92 +
.../ignite/portable/test1/1.1/test1-1.1.jar | Bin 0 -> 2548 bytes
.../ignite/portable/test1/1.1/test1-1.1.pom | 9 +
.../portable/test1/maven-metadata-local.xml | 12 +
.../ignite/portable/test2/1.1/test2-1.1.jar | Bin 0 -> 1361 bytes
.../ignite/portable/test2/1.1/test2-1.1.pom | 9 +
.../portable/test2/maven-metadata-local.xml | 12 +
.../HadoopDefaultMapReducePlannerSelfTest.java | 6 -
.../IgnitePortableCacheQueryTestSuite.java | 117 +
.../platform/PlatformContextImpl.java | 4 +-
.../platform/compute/PlatformCompute.java | 2 +-
.../cpp/PlatformCppConfigurationClosure.java | 2 +-
.../PlatformDotNetConfigurationClosure.java | 6 +-
.../Config/Compute/compute-grid1.xml | 8 +-
.../PlatformComputePortableArgTask.java | 8 +-
.../org/apache/ignite/IgniteSpringBean.java | 7 +
parent/pom.xml | 10 +
176 files changed, 17425 insertions(+), 2778 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/config/example-default.xml
----------------------------------------------------------------------
diff --git a/examples/config/example-default.xml b/examples/config/example-default.xml
new file mode 100644
index 0000000..e6c359d
--- /dev/null
+++ b/examples/config/example-default.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<!--
+ Ignite configuration with all defaults and enabled p2p deployment and enabled events.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util.xsd">
+ <bean abstract="true" id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
+ <!-- Set to true to enable distributed class loading for examples, default is false. -->
+ <property name="peerClassLoadingEnabled" value="true"/>
+
+ <!-- Enable task execution events for examples. -->
+ <property name="includeEventTypes">
+ <list>
+ <!--Task execution events-->
+ <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED"/>
+ <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED"/>
+ <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED"/>
+ <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_TIMEDOUT"/>
+ <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_SESSION_ATTR_SET"/>
+ <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_REDUCED"/>
+
+ <!--Cache events-->
+ <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT"/>
+ <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ"/>
+ <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED"/>
+ </list>
+ </property>
+
+ <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
+ <property name="discoverySpi">
+ <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
+ <property name="ipFinder">
+ <!--
+ Ignite provides several options for automatic discovery that can be used
+ instead os static IP based discovery. For information on all options refer
+ to our documentation: http://apacheignite.readme.io/docs/cluster-config
+ -->
+ <!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
+ <!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
+ <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
+ <property name="addresses">
+ <list>
+ <!-- In distributed environment, replace with actual host IP address. -->
+ <value>127.0.0.1:47500..47509</value>
+ </list>
+ </property>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean>
+</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/config/example-ignite.xml
----------------------------------------------------------------------
diff --git a/examples/config/example-ignite.xml b/examples/config/example-ignite.xml
index e7adb54..d842a6d 100644
--- a/examples/config/example-ignite.xml
+++ b/examples/config/example-ignite.xml
@@ -22,62 +22,18 @@
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/util
- http://www.springframework.org/schema/util/spring-util.xsd">
- <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
- <!-- Set to true to enable distributed class loading for examples, default is false. -->
- <property name="peerClassLoadingEnabled" value="true"/>
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+ <!-- Imports default Ignite configuration -->
+ <import resource="example-default.xml"/>
+ <bean parent="ignite.cfg">
+ <!-- Enabled optimized marshaller -->
<property name="marshaller">
<bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
<!-- Set to false to allow non-serializable objects in examples, default is true. -->
<property name="requireSerializable" value="false"/>
</bean>
</property>
-
- <!-- Enable task execution events for examples. -->
- <property name="includeEventTypes">
- <list>
- <!--Task execution events-->
- <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_STARTED"/>
- <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FINISHED"/>
- <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_FAILED"/>
- <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_TIMEDOUT"/>
- <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_SESSION_ATTR_SET"/>
- <util:constant static-field="org.apache.ignite.events.EventType.EVT_TASK_REDUCED"/>
-
- <!--Cache events-->
- <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT"/>
- <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ"/>
- <util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED"/>
- </list>
- </property>
-
- <!-- Explicitly configure TCP discovery SPI to provide list of initial nodes. -->
- <property name="discoverySpi">
- <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
- <property name="ipFinder">
- <!--
- Ignite provides several options for automatic discovery that can be used
- instead os static IP based discovery. For information on all options refer
- to our documentation: http://apacheignite.readme.io/docs/cluster-config
- -->
- <!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
- <!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
- <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
- <property name="addresses">
- <list>
- <!-- In distributed environment, replace with actual host IP address. -->
- <value>127.0.0.1:47500..47509</value>
- </list>
- </property>
- </bean>
- </property>
- </bean>
- </property>
</bean>
</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/config/portable/example-ignite-portable.xml
----------------------------------------------------------------------
diff --git a/examples/config/portable/example-ignite-portable.xml b/examples/config/portable/example-ignite-portable.xml
new file mode 100644
index 0000000..cde15ea
--- /dev/null
+++ b/examples/config/portable/example-ignite-portable.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<!--
+ Ignite configuration with all defaults and enabled p2p deployment, events and portable marshaller.
+
+ Use this configuration file when running HTTP REST examples (see 'examples/rest' folder).
+
+ When starting a standalone node, you need to execute the following command:
+ {IGNITE_HOME}/bin/ignite.{bat|sh} examples/config/portable/example-ignite-portable.xml
+
+ When starting Ignite from Java IDE, pass path to this file to Ignition:
+ Ignition.start("examples/config/portable/example-ignite-portable.xml");
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+ <!-- Imports default Ignite configuration -->
+ <import resource="../example-default.xml"/>
+
+ <bean parent="ignite.cfg">
+ <!-- Enables portable marshaller -->
+ <property name="marshaller">
+ <bean class="org.apache.ignite.marshaller.portable.PortableMarshaller"/>
+ </property>
+ </bean>
+</beans>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/Address.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/Address.java b/examples/src/main/java/org/apache/ignite/examples/portable/Address.java
new file mode 100644
index 0000000..cb08b25
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/Address.java
@@ -0,0 +1,72 @@
+/*
+ * 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.examples.portable;
+
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMarshalAware;
+import org.apache.ignite.portable.PortableReader;
+import org.apache.ignite.portable.PortableWriter;
+
+/**
+ * Employee address.
+ * <p>
+ * This class implements {@link PortableMarshalAware} only for example purposes,
+ * in order to show how to customize serialization and deserialization of
+ * portable objects.
+ */
+public class Address implements PortableMarshalAware {
+ /** Street. */
+ private String street;
+
+ /** ZIP code. */
+ private int zip;
+
+ /**
+ * Required for portable deserialization.
+ */
+ public Address() {
+ // No-op.
+ }
+
+ /**
+ * @param street Street.
+ * @param zip ZIP code.
+ */
+ public Address(String street, int zip) {
+ this.street = street;
+ this.zip = zip;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writePortable(PortableWriter writer) throws PortableException {
+ writer.writeString("street", street);
+ writer.writeInt("zip", zip);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(PortableReader reader) throws PortableException {
+ street = reader.readString("street");
+ zip = reader.readInt("zip");
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "Address [street=" + street +
+ ", zip=" + zip + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/Employee.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/Employee.java b/examples/src/main/java/org/apache/ignite/examples/portable/Employee.java
new file mode 100644
index 0000000..9614168
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/Employee.java
@@ -0,0 +1,93 @@
+/*
+ * 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.examples.portable;
+
+import java.util.Collection;
+
+/**
+ * This class represents employee object.
+ */
+public class Employee {
+ /** Name. */
+ private String name;
+
+ /** Salary. */
+ private long salary;
+
+ /** Address. */
+ private Address address;
+
+ /** Departments. */
+ private Collection<String> departments;
+
+ /**
+ * Required for portable deserialization.
+ */
+ public Employee() {
+ // No-op.
+ }
+
+ /**
+ * @param name Name.
+ * @param salary Salary.
+ * @param address Address.
+ * @param departments Departments.
+ */
+ public Employee(String name, long salary, Address address, Collection<String> departments) {
+ this.name = name;
+ this.salary = salary;
+ this.address = address;
+ this.departments = departments;
+ }
+
+ /**
+ * @return Name.
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * @return Salary.
+ */
+ public long salary() {
+ return salary;
+ }
+
+ /**
+ * @return Address.
+ */
+ public Address address() {
+ return address;
+ }
+
+ /**
+ * @return Departments.
+ */
+ public Collection<String> departments() {
+ return departments;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "Employee [name=" + name +
+ ", salary=" + salary +
+ ", address=" + address +
+ ", departments=" + departments + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/EmployeeKey.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/EmployeeKey.java b/examples/src/main/java/org/apache/ignite/examples/portable/EmployeeKey.java
new file mode 100644
index 0000000..f322167
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/EmployeeKey.java
@@ -0,0 +1,90 @@
+/*
+ * 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.examples.portable;
+
+/**
+ * This class represents key for employee object.
+ * <p>
+ * Used in query example to collocate employees
+ * with their organizations.
+ */
+public class EmployeeKey {
+ /** ID. */
+ private int id;
+
+ /** Organization ID. */
+ private int organizationId;
+
+ /**
+ * Required for portable deserialization.
+ */
+ public EmployeeKey() {
+ // No-op.
+ }
+
+ /**
+ * @param id ID.
+ * @param organizationId Organization ID.
+ */
+ public EmployeeKey(int id, int organizationId) {
+ this.id = id;
+ this.organizationId = organizationId;
+ }
+
+ /**
+ * @return ID.
+ */
+ public int id() {
+ return id;
+ }
+
+ /**
+ * @return Organization ID.
+ */
+ public int organizationId() {
+ return organizationId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ EmployeeKey key = (EmployeeKey)o;
+
+ return id == key.id && organizationId == key.organizationId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ int res = id;
+
+ res = 31 * res + organizationId;
+
+ return res;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "EmployeeKey [id=" + id +
+ ", organizationId=" + organizationId + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/ExamplePortableNodeStartup.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/ExamplePortableNodeStartup.java b/examples/src/main/java/org/apache/ignite/examples/portable/ExamplePortableNodeStartup.java
new file mode 100644
index 0000000..87a41f7
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/ExamplePortableNodeStartup.java
@@ -0,0 +1,36 @@
+/*
+ * 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.examples.portable;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.Ignition;
+
+/**
+ * Starts up an empty node with example configuration and portable marshaller enabled.
+ */
+public class ExamplePortableNodeStartup {
+ /**
+ * Start up an empty node with example configuration and portable marshaller enabled.
+ *
+ * @param args Command line arguments, none required.
+ * @throws IgniteException If failed.
+ */
+ public static void main(String[] args) throws IgniteException {
+ Ignition.start("examples/config/portable/example-ignite-portable.xml");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/Organization.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/Organization.java b/examples/src/main/java/org/apache/ignite/examples/portable/Organization.java
new file mode 100644
index 0000000..f52cac1
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/Organization.java
@@ -0,0 +1,93 @@
+/*
+ * 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.examples.portable;
+
+import java.sql.Timestamp;
+
+/**
+ * This class represents organization object.
+ */
+public class Organization {
+ /** Name. */
+ private String name;
+
+ /** Address. */
+ private Address address;
+
+ /** Type. */
+ private OrganizationType type;
+
+ /** Last update time. */
+ private Timestamp lastUpdated;
+
+ /**
+ * Required for portable deserialization.
+ */
+ public Organization() {
+ // No-op.
+ }
+
+ /**
+ * @param name Name.
+ * @param address Address.
+ * @param type Type.
+ * @param lastUpdated Last update time.
+ */
+ public Organization(String name, Address address, OrganizationType type, Timestamp lastUpdated) {
+ this.name = name;
+ this.address = address;
+ this.type = type;
+ this.lastUpdated = lastUpdated;
+ }
+
+ /**
+ * @return Name.
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * @return Address.
+ */
+ public Address address() {
+ return address;
+ }
+
+ /**
+ * @return Type.
+ */
+ public OrganizationType type() {
+ return type;
+ }
+
+ /**
+ * @return Last update time.
+ */
+ public Timestamp lastUpdated() {
+ return lastUpdated;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return "Organization [name=" + name +
+ ", address=" + address +
+ ", type=" + type +
+ ", lastUpdated=" + lastUpdated + ']';
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/OrganizationType.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/OrganizationType.java b/examples/src/main/java/org/apache/ignite/examples/portable/OrganizationType.java
new file mode 100644
index 0000000..c753e2d
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/OrganizationType.java
@@ -0,0 +1,32 @@
+/*
+ * 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.examples.portable;
+
+/**
+ * Organization type enum.
+ */
+public enum OrganizationType {
+ /** Non-profit organization. */
+ NON_PROFIT,
+
+ /** Private organization. */
+ PRIVATE,
+
+ /** Government organization. */
+ GOVERNMENT
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientPortableTaskExecutionExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientPortableTaskExecutionExample.java b/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientPortableTaskExecutionExample.java
new file mode 100644
index 0000000..34d9cde
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientPortableTaskExecutionExample.java
@@ -0,0 +1,154 @@
+/*
+ * 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.examples.portable.computegrid;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.examples.portable.Address;
+import org.apache.ignite.examples.portable.Employee;
+import org.apache.ignite.examples.portable.ExamplePortableNodeStartup;
+import org.apache.ignite.portable.PortableObject;
+
+/**
+ * This example demonstrates use of portable objects with task execution.
+ * Specifically it shows that portable objects are simple Java POJOs and do not require any special treatment.
+ * <p>
+ * The example executes map-reduce task that accepts collection of portable objects as an argument.
+ * Since these objects are never deserialized on remote nodes, classes are not required on classpath
+ * of these nodes.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables the portable marshaller: {@code 'ignite.{sh|bat} examples/config/portable/example-ignite-portable.xml'}.
+ * <p>
+ * Alternatively you can run {@link ExamplePortableNodeStartup} in another JVM which will
+ * start node with {@code examples/config/portable/example-ignite-portable.xml} configuration.
+ */
+public class ComputeClientPortableTaskExecutionExample {
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ try (Ignite ignite = Ignition.start("examples/config/portable/example-ignite-portable.xml")) {
+ System.out.println();
+ System.out.println(">>> Portable objects task execution example started.");
+
+ if (ignite.cluster().forRemotes().nodes().isEmpty()) {
+ System.out.println();
+ System.out.println(">>> This example requires remote nodes to be started.");
+ System.out.println(">>> Please start at least 1 remote node.");
+ System.out.println(">>> Refer to example's javadoc for details on configuration.");
+ System.out.println();
+
+ return;
+ }
+
+ // Generate employees to calculate average salary for.
+ Collection<Employee> employees = employees();
+
+ System.out.println();
+ System.out.println(">>> Calculating average salary for employees:");
+
+ for (Employee employee : employees)
+ System.out.println(">>> " + employee);
+
+ // Convert collection of employees to collection of portable objects.
+ // This allows to send objects across nodes without requiring to have
+ // Employee class on classpath of these nodes.
+ Collection<PortableObject> portables = ignite.portables().toPortable(employees);
+
+ // Execute task and get average salary.
+ Long avgSalary = ignite.compute(ignite.cluster().forRemotes()).execute(new ComputeClientTask(), portables);
+
+ System.out.println();
+ System.out.println(">>> Average salary for all employees: " + avgSalary);
+ System.out.println();
+ }
+ }
+
+ /**
+ * Creates collection of employees.
+ *
+ * @return Collection of employees.
+ */
+ private static Collection<Employee> employees() {
+ Collection<Employee> employees = new ArrayList<>();
+
+ employees.add(new Employee(
+ "James Wilson",
+ 12500,
+ new Address("1096 Eddy Street, San Francisco, CA", 94109),
+ Arrays.asList("Human Resources", "Customer Service")
+ ));
+
+ employees.add(new Employee(
+ "Daniel Adams",
+ 11000,
+ new Address("184 Fidler Drive, San Antonio, TX", 78205),
+ Arrays.asList("Development", "QA")
+ ));
+
+ employees.add(new Employee(
+ "Cristian Moss",
+ 12500,
+ new Address("667 Jerry Dove Drive, Florence, SC", 29501),
+ Arrays.asList("Logistics")
+ ));
+
+ employees.add(new Employee(
+ "Allison Mathis",
+ 25300,
+ new Address("2702 Freedom Lane, Hornitos, CA", 95325),
+ Arrays.asList("Development")
+ ));
+
+ employees.add(new Employee(
+ "Breana Robbin",
+ 6500,
+ new Address("3960 Sundown Lane, Austin, TX", 78758),
+ Arrays.asList("Sales")
+ ));
+
+ employees.add(new Employee(
+ "Philip Horsley",
+ 19800,
+ new Address("2803 Elsie Drive, Sioux Falls, SD", 57104),
+ Arrays.asList("Sales")
+ ));
+
+ employees.add(new Employee(
+ "Brian Peters",
+ 10600,
+ new Address("1407 Pearlman Avenue, Boston, MA", 12110),
+ Arrays.asList("Development", "QA")
+ ));
+
+ employees.add(new Employee(
+ "Jack Yang",
+ 12900,
+ new Address("4425 Parrish Avenue Smithsons Valley, TX", 78130),
+ Arrays.asList("Sales")
+ ));
+
+ return employees;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientTask.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientTask.java b/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientTask.java
new file mode 100644
index 0000000..0eee8c6
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/ComputeClientTask.java
@@ -0,0 +1,116 @@
+/*
+ * 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.examples.portable.computegrid;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobAdapter;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.compute.ComputeTaskSplitAdapter;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.portable.PortableObject;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Task that is used for {@link ComputeClientPortableTaskExecutionExample} and
+ * similar examples in .NET and C++.
+ * <p>
+ * This task calculates average salary for provided collection of employees.
+ * It splits the collection into batches of size {@code 3} and creates a job
+ * for each batch. After all jobs are executed, there results are reduced to
+ * get the average salary.
+ */
+public class ComputeClientTask extends ComputeTaskSplitAdapter<Collection<PortableObject>, Long> {
+ /** {@inheritDoc} */
+ @Override protected Collection<? extends ComputeJob> split(
+ int gridSize,
+ Collection<PortableObject> arg
+ ) {
+ Collection<ComputeClientJob> jobs = new ArrayList<>();
+
+ Collection<PortableObject> employees = new ArrayList<>();
+
+ // Split provided collection into batches and
+ // create a job for each batch.
+ for (PortableObject employee : arg) {
+ employees.add(employee);
+
+ if (employees.size() == 3) {
+ jobs.add(new ComputeClientJob(employees));
+
+ employees = new ArrayList<>(3);
+ }
+ }
+
+ if (!employees.isEmpty())
+ jobs.add(new ComputeClientJob(employees));
+
+ return jobs;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Long reduce(List<ComputeJobResult> results) {
+ long sum = 0;
+ int cnt = 0;
+
+ for (ComputeJobResult res : results) {
+ IgniteBiTuple<Long, Integer> t = res.getData();
+
+ sum += t.get1();
+ cnt += t.get2();
+ }
+
+ return sum / cnt;
+ }
+
+ /**
+ * Remote job for {@link ComputeClientTask}.
+ */
+ private static class ComputeClientJob extends ComputeJobAdapter {
+ /** Collection of employees. */
+ private final Collection<PortableObject> employees;
+
+ /**
+ * @param employees Collection of employees.
+ */
+ private ComputeClientJob(Collection<PortableObject> employees) {
+ this.employees = employees;
+ }
+
+ /** {@inheritDoc} */
+ @Nullable @Override public Object execute() {
+ long sum = 0;
+ int cnt = 0;
+
+ for (PortableObject employee : employees) {
+ System.out.println(">>> Processing employee: " + employee.field("name"));
+
+ // Get salary from portable object. Note that object
+ // doesn't need to be fully deserialized.
+ long salary = employee.field("salary");
+
+ sum += salary;
+ cnt++;
+ }
+
+ return new IgniteBiTuple<>(sum, cnt);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/package-info.java b/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/package-info.java
new file mode 100644
index 0000000..469128c
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/computegrid/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Demonstrates the usage of portable objects with task execution.
+ */
+package org.apache.ignite.examples.portable.computegrid;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortablePutGetExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortablePutGetExample.java b/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortablePutGetExample.java
new file mode 100644
index 0000000..77c5d95
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortablePutGetExample.java
@@ -0,0 +1,230 @@
+/*
+ * 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.examples.portable.datagrid;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.examples.portable.Address;
+import org.apache.ignite.examples.portable.ExamplePortableNodeStartup;
+import org.apache.ignite.examples.portable.Organization;
+import org.apache.ignite.examples.portable.OrganizationType;
+import org.apache.ignite.portable.PortableObject;
+
+/**
+ * This example demonstrates use of portable objects with Ignite cache.
+ * Specifically it shows that portable objects are simple Java POJOs and do not require any special treatment.
+ * <p>
+ * The example executes several put-get operations on Ignite cache with portable values. Note that
+ * it demonstrates how portable object can be retrieved in fully-deserialized form or in portable object
+ * format using special cache projection.
+ * <p>
+ * Remote nodes should always be started with special configuration file which
+ * enables the portable marshaller: {@code 'ignite.{sh|bat} examples/config/portable/example-ignite-portable.xml'}.
+ * <p>
+ * Alternatively you can run {@link ExamplePortableNodeStartup} in another JVM which will
+ * start node with {@code examples/config/portable/example-ignite-portable.xml} configuration.
+ */
+public class CacheClientPortablePutGetExample {
+ /** Cache name. */
+ private static final String CACHE_NAME = CacheClientPortablePutGetExample.class.getSimpleName();
+
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ try (Ignite ignite = Ignition.start("examples/config/portable/example-ignite-portable.xml")) {
+ System.out.println();
+ System.out.println(">>> Portable objects cache put-get example started.");
+
+ CacheConfiguration<Integer, Organization> cfg = new CacheConfiguration<>();
+
+ cfg.setCacheMode(CacheMode.PARTITIONED);
+ cfg.setName(CACHE_NAME);
+ cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+
+ try (IgniteCache<Integer, Organization> cache = ignite.createCache(cfg)) {
+ if (ignite.cluster().forDataNodes(cache.getName()).nodes().isEmpty()) {
+ System.out.println();
+ System.out.println(">>> This example requires remote cache node nodes to be started.");
+ System.out.println(">>> Please start at least 1 remote cache node.");
+ System.out.println(">>> Refer to example's javadoc for details on configuration.");
+ System.out.println();
+
+ return;
+ }
+
+ putGet(cache);
+ putGetPortable(cache);
+ putGetAll(cache);
+ putGetAllPortable(cache);
+
+ System.out.println();
+ }
+ finally {
+ // Delete cache with its content completely.
+ ignite.destroyCache(CACHE_NAME);
+ }
+ }
+ }
+
+ /**
+ * Execute individual put and get.
+ *
+ * @param cache Cache.
+ */
+ private static void putGet(IgniteCache<Integer, Organization> cache) {
+ // Create new Organization portable object to store in cache.
+ Organization org = new Organization(
+ "Microsoft", // Name.
+ new Address("1096 Eddy Street, San Francisco, CA", 94109), // Address.
+ OrganizationType.PRIVATE, // Type.
+ new Timestamp(System.currentTimeMillis())); // Last update time.
+
+ // Put created data entry to cache.
+ cache.put(1, org);
+
+ // Get recently created organization as a strongly-typed fully de-serialized instance.
+ Organization orgFromCache = cache.get(1);
+
+ System.out.println();
+ System.out.println(">>> Retrieved organization instance from cache: " + orgFromCache);
+ }
+
+ /**
+ * Execute individual put and get, getting value in portable format, without de-serializing it.
+ *
+ * @param cache Cache.
+ */
+ private static void putGetPortable(IgniteCache<Integer, Organization> cache) {
+ // Create new Organization portable object to store in cache.
+ Organization org = new Organization(
+ "Microsoft", // Name.
+ new Address("1096 Eddy Street, San Francisco, CA", 94109), // Address.
+ OrganizationType.PRIVATE, // Type.
+ new Timestamp(System.currentTimeMillis())); // Last update time.
+
+ // Put created data entry to cache.
+ cache.put(1, org);
+
+ // Get cache that will get values as portable objects.
+ IgniteCache<Integer, PortableObject> portableCache = cache.withKeepPortable();
+
+ // Get recently created organization as a portable object.
+ PortableObject po = portableCache.get(1);
+
+ // Get organization's name from portable object (note that
+ // object doesn't need to be fully deserialized).
+ String name = po.field("name");
+
+ System.out.println();
+ System.out.println(">>> Retrieved organization name from portable object: " + name);
+ }
+
+ /**
+ * Execute bulk {@code putAll(...)} and {@code getAll(...)} operations.
+ *
+ * @param cache Cache.
+ */
+ private static void putGetAll(IgniteCache<Integer, Organization> cache) {
+ // Create new Organization portable objects to store in cache.
+ Organization org1 = new Organization(
+ "Microsoft", // Name.
+ new Address("1096 Eddy Street, San Francisco, CA", 94109), // Address.
+ OrganizationType.PRIVATE, // Type.
+ new Timestamp(System.currentTimeMillis())); // Last update time.
+
+ Organization org2 = new Organization(
+ "Red Cross", // Name.
+ new Address("184 Fidler Drive, San Antonio, TX", 78205), // Address.
+ OrganizationType.NON_PROFIT, // Type.
+ new Timestamp(System.currentTimeMillis())); // Last update time.
+
+ Map<Integer, Organization> map = new HashMap<>();
+
+ map.put(1, org1);
+ map.put(2, org2);
+
+ // Put created data entries to cache.
+ cache.putAll(map);
+
+ // Get recently created organizations as a strongly-typed fully de-serialized instances.
+ Map<Integer, Organization> mapFromCache = cache.getAll(map.keySet());
+
+ System.out.println();
+ System.out.println(">>> Retrieved organization instances from cache:");
+
+ for (Organization org : mapFromCache.values())
+ System.out.println(">>> " + org);
+ }
+
+ /**
+ * Execute bulk {@code putAll(...)} and {@code getAll(...)} operations,
+ * getting values in portable format, without de-serializing it.
+ *
+ * @param cache Cache.
+ */
+ private static void putGetAllPortable(IgniteCache<Integer, Organization> cache) {
+ // Create new Organization portable objects to store in cache.
+ Organization org1 = new Organization(
+ "Microsoft", // Name.
+ new Address("1096 Eddy Street, San Francisco, CA", 94109), // Address.
+ OrganizationType.PRIVATE, // Type.
+ new Timestamp(System.currentTimeMillis())); // Last update time.
+
+ Organization org2 = new Organization(
+ "Red Cross", // Name.
+ new Address("184 Fidler Drive, San Antonio, TX", 78205), // Address.
+ OrganizationType.NON_PROFIT, // Type.
+ new Timestamp(System.currentTimeMillis())); // Last update time.
+
+ Map<Integer, Organization> map = new HashMap<>();
+
+ map.put(1, org1);
+ map.put(2, org2);
+
+ // Put created data entries to cache.
+ cache.putAll(map);
+
+ // Get cache that will get values as portable objects.
+ IgniteCache<Integer, PortableObject> portableCache = cache.withKeepPortable();
+
+ // Get recently created organizations as portable objects.
+ Map<Integer, PortableObject> poMap = portableCache.getAll(map.keySet());
+
+ Collection<String> names = new ArrayList<>();
+
+ // Get organizations' names from portable objects (note that
+ // objects don't need to be fully deserialized).
+ for (PortableObject po : poMap.values())
+ names.add(po.<String>field("name"));
+
+ System.out.println();
+ System.out.println(">>> Retrieved organization names from portable objects: " + names);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortableQueryExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortableQueryExample.java b/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortableQueryExample.java
new file mode 100644
index 0000000..3170864
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/CacheClientPortableQueryExample.java
@@ -0,0 +1,325 @@
+/*
+ * 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.examples.portable.datagrid;
+
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.cache.Cache;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheTypeMetadata;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.cache.query.TextQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.examples.portable.Address;
+import org.apache.ignite.examples.portable.Employee;
+import org.apache.ignite.examples.portable.EmployeeKey;
+import org.apache.ignite.examples.portable.ExamplePortableNodeStartup;
+import org.apache.ignite.examples.portable.Organization;
+import org.apache.ignite.examples.portable.OrganizationType;
+import org.apache.ignite.portable.PortableObject;
+
+/**
+ * This example demonstrates use of portable objects with cache queries.
+ * The example populates cache with sample data and runs several SQL and full text queries over this data.
+ * <p>
+ * Remote nodes should always be started with {@link ExamplePortableNodeStartup} which starts a node with
+ * {@code examples/config/portable/example-ignite-portable.xml} configuration.
+ */
+public class CacheClientPortableQueryExample {
+ /** Organization cache name. */
+ private static final String ORGANIZATION_CACHE_NAME = CacheClientPortableQueryExample.class.getSimpleName()
+ + "Organizations";
+
+ /** Employee cache name. */
+ private static final String EMPLOYEE_CACHE_NAME = CacheClientPortableQueryExample.class.getSimpleName()
+ + "Employees";
+
+ /**
+ * Executes example.
+ *
+ * @param args Command line arguments, none required.
+ */
+ public static void main(String[] args) {
+ try (Ignite ignite = Ignition.start("examples/config/portable/example-ignite-portable.xml")) {
+ System.out.println();
+ System.out.println(">>> Portable objects cache query example started.");
+
+ CacheConfiguration<Integer, Organization> orgCacheCfg = new CacheConfiguration<>();
+
+ orgCacheCfg.setCacheMode(CacheMode.PARTITIONED);
+ orgCacheCfg.setName(ORGANIZATION_CACHE_NAME);
+
+ orgCacheCfg.setTypeMetadata(Arrays.asList(createOrganizationTypeMetadata()));
+
+ CacheConfiguration<EmployeeKey, Employee> employeeCacheCfg = new CacheConfiguration<>();
+
+ employeeCacheCfg.setCacheMode(CacheMode.PARTITIONED);
+ employeeCacheCfg.setName(EMPLOYEE_CACHE_NAME);
+
+ employeeCacheCfg.setTypeMetadata(Arrays.asList(createEmployeeTypeMetadata()));
+
+ try (IgniteCache<Integer, Organization> orgCache = ignite.createCache(orgCacheCfg);
+ IgniteCache<EmployeeKey, Employee> employeeCache = ignite.createCache(employeeCacheCfg)
+ ) {
+ if (ignite.cluster().forDataNodes(orgCache.getName()).nodes().isEmpty()) {
+ System.out.println();
+ System.out.println(">>> This example requires remote cache nodes to be started.");
+ System.out.println(">>> Please start at least 1 remote cache node.");
+ System.out.println(">>> Refer to example's javadoc for details on configuration.");
+ System.out.println();
+
+ return;
+ }
+
+ // Populate cache with sample data entries.
+ populateCache(orgCache, employeeCache);
+
+ // Get cache that will work with portable objects.
+ IgniteCache<PortableObject, PortableObject> portableCache = employeeCache.withKeepPortable();
+
+ // Run SQL query example.
+ sqlQuery(portableCache);
+
+ // Run SQL query with join example.
+ sqlJoinQuery(portableCache);
+
+ // Run SQL fields query example.
+ sqlFieldsQuery(portableCache);
+
+ // Run full text query example.
+ textQuery(portableCache);
+
+ System.out.println();
+ }
+ finally {
+ // Delete caches with their content completely.
+ ignite.destroyCache(ORGANIZATION_CACHE_NAME);
+ ignite.destroyCache(EMPLOYEE_CACHE_NAME);
+ }
+ }
+ }
+
+ /**
+ * Create cache type metadata for {@link Employee}.
+ *
+ * @return Cache type metadata.
+ */
+ private static CacheTypeMetadata createEmployeeTypeMetadata() {
+ CacheTypeMetadata employeeTypeMeta = new CacheTypeMetadata();
+
+ employeeTypeMeta.setValueType(Employee.class);
+
+ employeeTypeMeta.setKeyType(EmployeeKey.class);
+
+ Map<String, Class<?>> ascFields = new HashMap<>();
+
+ ascFields.put("name", String.class);
+ ascFields.put("salary", Long.class);
+ ascFields.put("address.zip", Integer.class);
+ ascFields.put("organizationId", Integer.class);
+
+ employeeTypeMeta.setAscendingFields(ascFields);
+
+ employeeTypeMeta.setTextFields(Arrays.asList("address.street"));
+
+ return employeeTypeMeta;
+ }
+
+ /**
+ * Create cache type metadata for {@link Organization}.
+ *
+ * @return Cache type metadata.
+ */
+ private static CacheTypeMetadata createOrganizationTypeMetadata() {
+ CacheTypeMetadata organizationTypeMeta = new CacheTypeMetadata();
+
+ organizationTypeMeta.setValueType(Organization.class);
+
+ organizationTypeMeta.setKeyType(Integer.class);
+
+ Map<String, Class<?>> ascFields = new HashMap<>();
+
+ ascFields.put("name", String.class);
+
+ Map<String, Class<?>> queryFields = new HashMap<>();
+
+ queryFields.put("address.street", String.class);
+
+ organizationTypeMeta.setAscendingFields(ascFields);
+
+ organizationTypeMeta.setQueryFields(queryFields);
+
+ return organizationTypeMeta;
+ }
+
+ /**
+ * Queries employees that have provided ZIP code in address.
+ *
+ * @param cache Ignite cache.
+ */
+ private static void sqlQuery(IgniteCache<PortableObject, PortableObject> cache) {
+ SqlQuery<PortableObject, PortableObject> query = new SqlQuery<>(Employee.class, "zip = ?");
+
+ int zip = 94109;
+
+ QueryCursor<Cache.Entry<PortableObject, PortableObject>> employees = cache.query(query.setArgs(zip));
+
+ System.out.println();
+ System.out.println(">>> Employees with zip " + zip + ':');
+
+ for (Cache.Entry<PortableObject, PortableObject> e : employees.getAll())
+ System.out.println(">>> " + e.getValue().deserialize());
+ }
+
+ /**
+ * Queries employees that work for organization with provided name.
+ *
+ * @param cache Ignite cache.
+ */
+ private static void sqlJoinQuery(IgniteCache<PortableObject, PortableObject> cache) {
+ SqlQuery<PortableObject, PortableObject> query = new SqlQuery<>(Employee.class,
+ "from Employee, \"" + ORGANIZATION_CACHE_NAME + "\".Organization as org " +
+ "where Employee.organizationId = org._key and org.name = ?");
+
+ String organizationName = "GridGain";
+
+ QueryCursor<Cache.Entry<PortableObject, PortableObject>> employees =
+ cache.query(query.setArgs(organizationName));
+
+ System.out.println();
+ System.out.println(">>> Employees working for " + organizationName + ':');
+
+ for (Cache.Entry<PortableObject, PortableObject> e : employees.getAll())
+ System.out.println(">>> " + e.getValue());
+ }
+
+ /**
+ * Queries names and salaries for all employees.
+ *
+ * @param cache Ignite cache.
+ */
+ private static void sqlFieldsQuery(IgniteCache<PortableObject, PortableObject> cache) {
+ SqlFieldsQuery query = new SqlFieldsQuery("select name, salary from Employee");
+
+ QueryCursor<List<?>> employees = cache.query(query);
+
+ System.out.println();
+ System.out.println(">>> Employee names and their salaries:");
+
+ for (List<?> row : employees.getAll())
+ System.out.println(">>> [Name=" + row.get(0) + ", salary=" + row.get(1) + ']');
+ }
+
+ /**
+ * Queries employees that live in Texas using full-text query API.
+ *
+ * @param cache Ignite cache.
+ */
+ private static void textQuery(IgniteCache<PortableObject, PortableObject> cache) {
+ TextQuery<PortableObject, PortableObject> query = new TextQuery<>(Employee.class, "TX");
+
+ QueryCursor<Cache.Entry<PortableObject, PortableObject>> employees = cache.query(query);
+
+ System.out.println();
+ System.out.println(">>> Employees living in Texas:");
+
+ for (Cache.Entry<PortableObject, PortableObject> e : employees.getAll())
+ System.out.println(">>> " + e.getValue().deserialize());
+ }
+
+ /**
+ * Populates cache with data.
+ *
+ * @param orgCache Organization cache.
+ * @param employeeCache Employee cache.
+ */
+ private static void populateCache(IgniteCache<Integer, Organization> orgCache,
+ IgniteCache<EmployeeKey, Employee> employeeCache) {
+ orgCache.put(1, new Organization(
+ "GridGain",
+ new Address("1065 East Hillsdale Blvd, Foster City, CA", 94404),
+ OrganizationType.PRIVATE,
+ new Timestamp(System.currentTimeMillis())
+ ));
+
+ orgCache.put(2, new Organization(
+ "Microsoft",
+ new Address("1096 Eddy Street, San Francisco, CA", 94109),
+ OrganizationType.PRIVATE,
+ new Timestamp(System.currentTimeMillis())
+ ));
+
+ employeeCache.put(new EmployeeKey(1, 1), new Employee(
+ "James Wilson",
+ 12500,
+ new Address("1096 Eddy Street, San Francisco, CA", 94109),
+ Arrays.asList("Human Resources", "Customer Service")
+ ));
+
+ employeeCache.put(new EmployeeKey(2, 1), new Employee(
+ "Daniel Adams",
+ 11000,
+ new Address("184 Fidler Drive, San Antonio, TX", 78130),
+ Arrays.asList("Development", "QA")
+ ));
+
+ employeeCache.put(new EmployeeKey(3, 1), new Employee(
+ "Cristian Moss",
+ 12500,
+ new Address("667 Jerry Dove Drive, Florence, SC", 29501),
+ Arrays.asList("Logistics")
+ ));
+
+ employeeCache.put(new EmployeeKey(4, 2), new Employee(
+ "Allison Mathis",
+ 25300,
+ new Address("2702 Freedom Lane, San Francisco, CA", 94109),
+ Arrays.asList("Development")
+ ));
+
+ employeeCache.put(new EmployeeKey(5, 2), new Employee(
+ "Breana Robbin",
+ 6500,
+ new Address("3960 Sundown Lane, Austin, TX", 78130),
+ Arrays.asList("Sales")
+ ));
+
+ employeeCache.put(new EmployeeKey(6, 2), new Employee(
+ "Philip Horsley",
+ 19800,
+ new Address("2803 Elsie Drive, Sioux Falls, SD", 57104),
+ Arrays.asList("Sales")
+ ));
+
+ employeeCache.put(new EmployeeKey(7, 2), new Employee(
+ "Brian Peters",
+ 10600,
+ new Address("1407 Pearlman Avenue, Boston, MA", 12110),
+ Arrays.asList("Development", "QA")
+ ));
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/package-info.java b/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/package-info.java
new file mode 100644
index 0000000..b24f233
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/datagrid/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Demonstrates the usage of portable objects with cache.
+ */
+package org.apache.ignite.examples.portable.datagrid;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/main/java/org/apache/ignite/examples/portable/package-info.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/portable/package-info.java b/examples/src/main/java/org/apache/ignite/examples/portable/package-info.java
new file mode 100644
index 0000000..4301027
--- /dev/null
+++ b/examples/src/main/java/org/apache/ignite/examples/portable/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+/**
+ * Contains portable classes and examples.
+ */
+package org.apache.ignite.examples.portable;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java b/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java
new file mode 100644
index 0000000..6ea1484
--- /dev/null
+++ b/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.examples;
+
+import org.apache.ignite.examples.portable.datagrid.CacheClientPortablePutGetExample;
+import org.apache.ignite.examples.portable.datagrid.CacheClientPortableQueryExample;
+import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
+
+/**
+ *
+ */
+public class CacheClientPortableExampleTest extends GridAbstractExamplesTest {
+ /** {@inheritDoc} */
+ @Override protected String defaultConfig() {
+ return "examples/config/portable/example-ignite-portable.xml";
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortablePutGetExample() throws Exception {
+ CacheClientPortablePutGetExample.main(new String[] {});
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableQueryExample() throws Exception {
+ CacheClientPortableQueryExample.main(new String[] {});
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java b/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java
new file mode 100644
index 0000000..2223aec
--- /dev/null
+++ b/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.examples;
+
+import org.apache.ignite.examples.portable.computegrid.ComputeClientPortableTaskExecutionExample;
+import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
+
+/**
+ *
+ */
+public class ComputeClientPortableExampleTest extends GridAbstractExamplesTest {
+ /** {@inheritDoc} */
+ @Override protected String defaultConfig() {
+ return "examples/config/portable/example-ignite-portable.xml";
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testPortableTaskExecutionExample() throws Exception {
+ ComputeClientPortableTaskExecutionExample.main(new String[] {});
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java b/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java
index 4669ae4..baa23fc 100644
--- a/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java
+++ b/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java
@@ -20,10 +20,12 @@ package org.apache.ignite.testsuites;
import junit.framework.TestSuite;
import org.apache.ignite.examples.BasicExamplesMultiNodeSelfTest;
import org.apache.ignite.examples.BasicExamplesSelfTest;
+import org.apache.ignite.examples.CacheClientPortableExampleTest;
import org.apache.ignite.examples.CacheExamplesMultiNodeSelfTest;
import org.apache.ignite.examples.CacheExamplesSelfTest;
import org.apache.ignite.examples.CheckpointExamplesSelfTest;
import org.apache.ignite.examples.ClusterGroupExampleSelfTest;
+import org.apache.ignite.examples.ComputeClientPortableExampleTest;
import org.apache.ignite.examples.ContinuationExamplesMultiNodeSelfTest;
import org.apache.ignite.examples.ContinuationExamplesSelfTest;
import org.apache.ignite.examples.ContinuousMapperExamplesMultiNodeSelfTest;
@@ -93,6 +95,10 @@ public class IgniteExamplesSelfTestSuite extends TestSuite {
suite.addTest(new TestSuite(MonteCarloExamplesMultiNodeSelfTest.class));
suite.addTest(new TestSuite(HibernateL2CacheExampleMultiNodeSelfTest.class));
+ // Portable.
+ suite.addTest(new TestSuite(CacheClientPortableExampleTest.class));
+ suite.addTest(new TestSuite(ComputeClientPortableExampleTest.class));
+
return suite;
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/pom.xml
----------------------------------------------------------------------
diff --git a/modules/core/pom.xml b/modules/core/pom.xml
index 6467119..e02bb23 100644
--- a/modules/core/pom.xml
+++ b/modules/core/pom.xml
@@ -34,6 +34,13 @@
<version>1.5.0-SNAPSHOT</version>
<url>http://ignite.apache.org</url>
+ <repositories>
+ <repository>
+ <id>ignite-portables-test-repo</id>
+ <url>file://${basedir}/src/test/portables/repo</url>
+ </repository>
+ </repositories>
+
<properties>
<ignite.update.notifier.product>apache-ignite</ignite.update.notifier.product>
</properties>
@@ -169,6 +176,20 @@
<version>2.4</version>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.ignite.portable</groupId>
+ <artifactId>test1</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.ignite.portable</groupId>
+ <artifactId>test2</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/Ignite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java b/modules/core/src/main/java/org/apache/ignite/Ignite.java
index 0afccd0..62fd020 100644
--- a/modules/core/src/main/java/org/apache/ignite/Ignite.java
+++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java
@@ -459,6 +459,13 @@ public interface Ignite extends AutoCloseable {
public <T extends IgnitePlugin> T plugin(String name) throws PluginNotFoundException;
/**
+ * Gets an instance of {@link IgnitePortables} interface.
+ *
+ * @return Instance of {@link IgnitePortables} interface.
+ */
+ public IgnitePortables portables();
+
+ /**
* Closes {@code this} instance of grid. This method is identical to calling
* {@link G#stop(String, boolean) G.stop(gridName, true)}.
* <p>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
index 5558a26..e0f9f55 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
@@ -18,9 +18,12 @@
package org.apache.ignite;
import java.io.Serializable;
+import java.sql.Timestamp;
import java.util.Collection;
+import java.util.Date;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import javax.cache.Cache;
@@ -52,6 +55,7 @@ import org.apache.ignite.lang.IgniteAsyncSupported;
import org.apache.ignite.lang.IgniteBiInClosure;
import org.apache.ignite.lang.IgniteBiPredicate;
import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
import org.apache.ignite.mxbean.CacheMetricsMXBean;
import org.jetbrains.annotations.Nullable;
@@ -128,6 +132,44 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
public IgniteCache<K, V> withNoRetries();
/**
+ * Returns cache that will operate with portable objects.
+ * <p>
+ * Cache returned by this method will not be forced to deserialize portable objects,
+ * so keys and values will be returned from cache API methods without changes. Therefore,
+ * signature of the cache can contain only following types:
+ * <ul>
+ * <li><code>org.apache.ignite.portable.PortableObject</code> for portable classes</li>
+ * <li>All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)</li>
+ * <li>Arrays of primitives (byte[], int[], ...)</li>
+ * <li>{@link String} and array of {@link String}s</li>
+ * <li>{@link UUID} and array of {@link UUID}s</li>
+ * <li>{@link Date} and array of {@link Date}s</li>
+ * <li>{@link Timestamp} and array of {@link Timestamp}s</li>
+ * <li>Enums and array of enums</li>
+ * <li>
+ * Maps, collections and array of objects (but objects inside
+ * them will still be converted if they are portable)
+ * </li>
+ * </ul>
+ * <p>
+ * For example, if you use {@link Integer} as a key and {@code Value} class as a value
+ * (which will be stored in portable format), you should acquire following projection
+ * to avoid deserialization:
+ * <pre>
+ * IgniteCache<Integer, PortableObject> prj = cache.withKeepPortable();
+ *
+ * // Value is not deserialized and returned in portable format.
+ * PortableObject po = prj.get(1);
+ * </pre>
+ * <p>
+ * Note that this method makes sense only if cache is working in portable mode ({@link PortableMarshaller} is used).
+ * If not, this method is no-op and will return current cache.
+ *
+ * @return New cache instance for portable objects.
+ */
+ public <K1, V1> IgniteCache<K1, V1> withKeepPortable();
+
+ /**
* Executes {@link #localLoadCache(IgniteBiPredicate, Object...)} on all cache nodes.
*
* @param p Optional predicate (may be {@code null}). If provided, will be used to
@@ -619,4 +661,4 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
* @return MxBean.
*/
public CacheMetricsMXBean mxBean();
-}
+}
\ No newline at end of file
[07/11] ignite git commit: Revert "ignite-1462: hid portable API in
1.4 release" This reverts commit 71379a8061f50f336adc31fa20cd593b659b050f.
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableWriter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableWriter.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableWriter.java
new file mode 100644
index 0000000..0d7160f
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableWriter.java
@@ -0,0 +1,266 @@
+/*
+ * 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.portable;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Writer for portable object used in {@link PortableMarshalAware} implementations.
+ * Useful for the cases when user wants a fine-grained control over serialization.
+ * <p>
+ * Note that Ignite never writes full strings for field or type names. Instead,
+ * for performance reasons, Ignite writes integer hash codes for type and field names.
+ * It has been tested that hash code conflicts for the type names or the field names
+ * within the same type are virtually non-existent and, to gain performance, it is safe
+ * to work with hash codes. For the cases when hash codes for different types or fields
+ * actually do collide, Ignite provides {@link PortableIdMapper} which
+ * allows to override the automatically generated hash code IDs for the type and field names.
+ */
+public interface PortableWriter {
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeByte(String fieldName, byte val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeShort(String fieldName, short val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeInt(String fieldName, int val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeLong(String fieldName, long val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeFloat(String fieldName, float val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeDouble(String fieldName, double val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeChar(String fieldName, char val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeBoolean(String fieldName, boolean val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeString(String fieldName, @Nullable String val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val UUID to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeUuid(String fieldName, @Nullable UUID val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Date to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeDate(String fieldName, @Nullable Date val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Timestamp to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param obj Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeObject(String fieldName, @Nullable Object obj) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeByteArray(String fieldName, @Nullable byte[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeShortArray(String fieldName, @Nullable short[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeIntArray(String fieldName, @Nullable int[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeLongArray(String fieldName, @Nullable long[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeFloatArray(String fieldName, @Nullable float[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeDoubleArray(String fieldName, @Nullable double[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeCharArray(String fieldName, @Nullable char[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeBooleanArray(String fieldName, @Nullable boolean[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeStringArray(String fieldName, @Nullable String[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeDateArray(String fieldName, @Nullable Date[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeObjectArray(String fieldName, @Nullable Object[] val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param col Collection to write.
+ * @throws PortableException In case of error.
+ */
+ public <T> void writeCollection(String fieldName, @Nullable Collection<T> col) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param map Map to write.
+ * @throws PortableException In case of error.
+ */
+ public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws PortableException;
+
+ /**
+ * Gets raw writer. Raw writer does not write field name hash codes, therefore,
+ * making the format even more compact. However, if the raw writer is used,
+ * dynamic structure changes to the portable objects are not supported.
+ *
+ * @return Raw writer.
+ */
+ public PortableRawWriter rawWriter();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/package-info.java b/modules/core/src/main/java/org/apache/ignite/portable/package-info.java
new file mode 100644
index 0000000..0105b15
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains portable objects API classes.
+ */
+package org.apache.ignite.portable;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/resources/META-INF/classnames.properties
----------------------------------------------------------------------
diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties
index 36ac156..70c32e5 100644
--- a/modules/core/src/main/resources/META-INF/classnames.properties
+++ b/modules/core/src/main/resources/META-INF/classnames.properties
@@ -1572,10 +1572,10 @@ org.apache.ignite.plugin.security.SecuritySubject
org.apache.ignite.plugin.security.SecuritySubjectType
org.apache.ignite.plugin.segmentation.SegmentationPolicy
org.apache.ignite.plugin.segmentation.SegmentationResolver
-org.apache.ignite.internal.portable.api.PortableException
-org.apache.ignite.internal.portable.api.PortableInvalidClassException
-org.apache.ignite.internal.portable.api.PortableObject
-org.apache.ignite.internal.portable.api.PortableProtocolVersion
+org.apache.ignite.portable.PortableException
+org.apache.ignite.portable.PortableInvalidClassException
+org.apache.ignite.portable.PortableObject
+org.apache.ignite.portable.PortableProtocolVersion
org.apache.ignite.services.Service
org.apache.ignite.services.ServiceConfiguration
org.apache.ignite.services.ServiceContext
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAttributesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAttributesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAttributesSelfTest.java
index dc73cff..82da10f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAttributesSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManagerAttributesSelfTest.java
@@ -159,6 +159,51 @@ public abstract class GridDiscoveryManagerAttributesSelfTest extends GridCommonA
}
/**
+ * @throws Exception If failed.
+ */
+ public void testDifferentPortableProtocolVersions() throws Exception {
+ startGridWithPortableProtocolVer("VER_99_99_99");
+
+ try {
+ startGrid(1);
+
+ fail();
+ }
+ catch (IgniteCheckedException e) {
+ if (!e.getCause().getMessage().startsWith("Remote node has portable protocol version different from local"))
+ throw e;
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testNullPortableProtocolVersion() throws Exception {
+ startGridWithPortableProtocolVer(null);
+
+ // Must not fail in order to preserve backward compatibility with the nodes that don't have this property yet.
+ startGrid(1);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ private void startGridWithPortableProtocolVer(String ver) throws Exception {
+ Ignite ignite = startGrid(0);
+
+ ClusterNode clusterNode = ignite.cluster().localNode();
+
+ Field f = clusterNode.getClass().getDeclaredField("attrs");
+ f.setAccessible(true);
+
+ Map<String, Object> attrs = new HashMap<>((Map<String, Object>)f.get(clusterNode));
+
+ attrs.put(IgniteNodeAttributes.ATTR_PORTABLE_PROTO_VER, ver);
+
+ f.set(clusterNode, attrs);
+ }
+
+ /**
* @param preferIpV4 {@code java.net.preferIPv4Stack} system property value.
* @throws Exception If failed.
*/
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
new file mode 100644
index 0000000..59084db
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
@@ -0,0 +1,218 @@
+/*
+ * 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;
+
+import java.util.Collections;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.affinity.GridAffinityProcessor;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.apache.ignite.resources.IgniteInstanceResource;
+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.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable object affinity key.
+ */
+public class GridPortableAffinityKeySelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final AtomicReference<UUID> nodeId = new AtomicReference<>();
+
+ /** VM ip finder for TCP discovery. */
+ private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+ /** */
+ private static int GRID_CNT = 5;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableTypeConfiguration typeCfg = new PortableTypeConfiguration();
+
+ typeCfg.setClassName(TestObject.class.getName());
+ typeCfg.setAffinityKeyFieldName("affKey");
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setTypeConfigurations(Collections.singleton(typeCfg));
+
+ cfg.setMarshaller(marsh);
+
+ if (!gridName.equals(getTestGridName(GRID_CNT))) {
+ CacheConfiguration cacheCfg = new CacheConfiguration();
+
+ cacheCfg.setCacheMode(PARTITIONED);
+
+ cfg.setCacheConfiguration(cacheCfg);
+ }
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGridsMultiThreaded(GRID_CNT);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAffinity() throws Exception {
+ checkAffinity(grid(0));
+
+ try (Ignite igniteNoCache = startGrid(GRID_CNT)) {
+ try {
+ igniteNoCache.cache(null);
+ }
+ catch (IllegalArgumentException ignore) {
+ // Expected error.
+ }
+
+ checkAffinity(igniteNoCache);
+ }
+ }
+
+ /**
+ * @param ignite Ignite.
+ * @throws Exception If failed.
+ */
+ private void checkAffinity(Ignite ignite) throws Exception {
+ Affinity<Object> aff = ignite.affinity(null);
+
+ GridAffinityProcessor affProc = ((IgniteKernal)ignite).context().affinity();
+
+ IgniteCacheObjectProcessor cacheObjProc = ((IgniteKernal)ignite).context().cacheObjects();
+
+ CacheObjectContext cacheObjCtx = cacheObjProc.contextForCache(
+ ignite.cache(null).getConfiguration(CacheConfiguration.class));
+
+ for (int i = 0; i < 1000; i++) {
+ assertEquals(i, aff.affinityKey(i));
+
+ assertEquals(i, aff.affinityKey(new TestObject(i)));
+
+ CacheObject cacheObj = cacheObjProc.toCacheObject(cacheObjCtx, new TestObject(i), true);
+
+ assertEquals(i, aff.affinityKey(cacheObj));
+
+ assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(new TestObject(i)));
+
+ assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(cacheObj));
+
+ assertEquals(i, affProc.affinityKey(null, i));
+
+ assertEquals(i, affProc.affinityKey(null, new TestObject(i)));
+
+ assertEquals(i, affProc.affinityKey(null, cacheObj));
+
+ assertEquals(affProc.mapKeyToNode(null, i), affProc.mapKeyToNode(null, new TestObject(i)));
+
+ assertEquals(affProc.mapKeyToNode(null, i), affProc.mapKeyToNode(null, cacheObj));
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAffinityRun() throws Exception {
+ Affinity<Object> aff = grid(0).affinity(null);
+
+ for (int i = 0; i < 1000; i++) {
+ nodeId.set(null);
+
+ grid(0).compute().affinityRun(null, new TestObject(i), new IgniteRunnable() {
+ @IgniteInstanceResource
+ private Ignite ignite;
+
+ @Override public void run() {
+ nodeId.set(ignite.configuration().getNodeId());
+ }
+ });
+
+ assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testAffinityCall() throws Exception {
+ Affinity<Object> aff = grid(0).affinity(null);
+
+ for (int i = 0; i < 1000; i++) {
+ nodeId.set(null);
+
+ grid(0).compute().affinityCall(null, new TestObject(i), new IgniteCallable<Object>() {
+ @IgniteInstanceResource
+ private Ignite ignite;
+
+ @Override public Object call() {
+ nodeId.set(ignite.configuration().getNodeId());
+
+ return null;
+ }
+ });
+
+ assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
+ }
+ }
+
+ /**
+ */
+ private static class TestObject {
+ /** */
+ @SuppressWarnings("UnusedDeclaration")
+ private int affKey;
+
+ /**
+ */
+ private TestObject() {
+ // No-op.
+ }
+
+ /**
+ * @param affKey Affinity key.
+ */
+ private TestObject(int affKey) {
+ this.affKey = affKey;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderAdditionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderAdditionalSelfTest.java
new file mode 100644
index 0000000..61ec714
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderAdditionalSelfTest.java
@@ -0,0 +1,1226 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgnitePortables;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.portable.builder.PortableBuilderEnum;
+import org.apache.ignite.internal.portable.builder.PortableBuilderImpl;
+import org.apache.ignite.internal.portable.mutabletest.GridPortableMarshalerAwareTestClass;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
+import org.apache.ignite.internal.processors.cache.portable.IgnitePortablesImpl;
+import org.apache.ignite.internal.util.lang.GridMapEntry;
+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.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Assert;
+
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.Address;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.AddressBook;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.Company;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectAllTypes;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectArrayList;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectContainer;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectEnum;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectInner;
+import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectOuter;
+
+/**
+ *
+ */
+public class GridPortableBuilderAdditionalSelfTest extends GridCommonAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ CacheConfiguration cacheCfg = new CacheConfiguration();
+
+ cacheCfg.setCacheMode(REPLICATED);
+
+ cfg.setCacheConfiguration(cacheCfg);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList("org.apache.ignite.internal.portable.mutabletest.*"));
+
+ marsh.setConvertStringToBytes(useUtf8());
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGrids(1);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ jcache(0).clear();
+ }
+
+ /**
+ * @return Whether to use UTF8 strings.
+ */
+ protected boolean useUtf8() {
+ return true;
+ }
+
+ /**
+ * @return Portables API.
+ */
+ protected IgnitePortables portables() {
+ return grid(0).portables();
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testSimpleTypeFieldRead() throws Exception {
+ TestObjectAllTypes exp = new TestObjectAllTypes();
+
+ exp.setDefaultData();
+
+ PortableBuilder mutPo = wrap(exp);
+
+ for (Field field : TestObjectAllTypes.class.getDeclaredFields()) {
+ Object expVal = field.get(exp);
+ Object actVal = mutPo.getField(field.getName());
+
+ switch (field.getName()) {
+ case "anEnum":
+ assertEquals(((PortableBuilderEnum)actVal).getOrdinal(), ((Enum)expVal).ordinal());
+ break;
+
+ case "enumArr": {
+ PortableBuilderEnum[] actArr = (PortableBuilderEnum[])actVal;
+ Enum[] expArr = (Enum[])expVal;
+
+ assertEquals(expArr.length, actArr.length);
+
+ for (int i = 0; i < actArr.length; i++)
+ assertEquals(expArr[i].ordinal(), actArr[i].getOrdinal());
+
+ break;
+ }
+
+ case "entry":
+ assertEquals(((Map.Entry)expVal).getKey(), ((Map.Entry)actVal).getKey());
+ assertEquals(((Map.Entry)expVal).getValue(), ((Map.Entry)actVal).getValue());
+ break;
+
+ default:
+ assertTrue(field.getName(), Objects.deepEquals(expVal, actVal));
+ break;
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public void testSimpleTypeFieldSerialize() {
+ TestObjectAllTypes exp = new TestObjectAllTypes();
+
+ exp.setDefaultData();
+
+ PortableBuilderImpl mutPo = wrap(exp);
+
+ TestObjectAllTypes res = mutPo.build().deserialize();
+
+ GridTestUtils.deepEquals(exp, res);
+ }
+
+ /**
+ * @throws Exception If any error occurs.
+ */
+ public void testSimpleTypeFieldOverride() throws Exception {
+ TestObjectAllTypes exp = new TestObjectAllTypes();
+
+ exp.setDefaultData();
+
+ PortableBuilderImpl mutPo = wrap(new TestObjectAllTypes());
+
+ for (Field field : TestObjectAllTypes.class.getDeclaredFields())
+ mutPo.setField(field.getName(), field.get(exp));
+
+ TestObjectAllTypes res = mutPo.build().deserialize();
+
+ GridTestUtils.deepEquals(exp, res);
+ }
+
+ /**
+ * @throws Exception If any error occurs.
+ */
+ public void testSimpleTypeFieldSetNull() throws Exception {
+ TestObjectAllTypes exp = new TestObjectAllTypes();
+
+ exp.setDefaultData();
+
+ PortableBuilderImpl mutPo = wrap(exp);
+
+ for (Field field : TestObjectAllTypes.class.getDeclaredFields()) {
+ if (!field.getType().isPrimitive())
+ mutPo.setField(field.getName(), null);
+ }
+
+ TestObjectAllTypes res = mutPo.build().deserialize();
+
+ for (Field field : TestObjectAllTypes.class.getDeclaredFields()) {
+ if (!field.getType().isPrimitive())
+ assertNull(field.getName(), field.get(res));
+ }
+ }
+
+ /**
+ * @throws IgniteCheckedException If any error occurs.
+ */
+ public void testMakeCyclicDependency() throws IgniteCheckedException {
+ TestObjectOuter outer = new TestObjectOuter();
+ outer.inner = new TestObjectInner();
+
+ PortableBuilderImpl mutOuter = wrap(outer);
+
+ PortableBuilderImpl mutInner = mutOuter.getField("inner");
+
+ mutInner.setField("outer", mutOuter);
+ mutInner.setField("foo", mutInner);
+
+ TestObjectOuter res = mutOuter.build().deserialize();
+
+ assertEquals(res, res.inner.outer);
+ assertEquals(res.inner, res.inner.foo);
+ }
+
+ /**
+ *
+ */
+ public void testDateArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.dateArr = new Date[] {new Date(11111), new Date(11111), new Date(11111)};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ Date[] arr = mutObj.getField("dateArr");
+ arr[0] = new Date(22222);
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new Date[] {new Date(22222), new Date(11111), new Date(11111)}, res.dateArr);
+ }
+
+ /**
+ *
+ */
+ public void testUUIDArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.uuidArr = new UUID[] {new UUID(1, 1), new UUID(1, 1), new UUID(1, 1)};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ UUID[] arr = mutObj.getField("uuidArr");
+ arr[0] = new UUID(2, 2);
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new UUID[] {new UUID(2, 2), new UUID(1, 1), new UUID(1, 1)}, res.uuidArr);
+ }
+
+ /**
+ *
+ */
+ public void testDecimalArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.bdArr = new BigDecimal[] {new BigDecimal(1000), new BigDecimal(1000), new BigDecimal(1000)};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ BigDecimal[] arr = mutObj.getField("bdArr");
+ arr[0] = new BigDecimal(2000);
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new BigDecimal[] {new BigDecimal(1000), new BigDecimal(1000), new BigDecimal(1000)},
+ res.bdArr);
+ }
+
+ /**
+ *
+ */
+ public void testBooleanArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.zArr = new boolean[] {false, false, false};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ boolean[] arr = mutObj.getField("zArr");
+ arr[0] = true;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ boolean[] expected = new boolean[] {true, false, false};
+
+ assertEquals(expected.length, res.zArr.length);
+
+ for (int i = 0; i < expected.length; i++)
+ assertEquals(expected[i], res.zArr[i]);
+ }
+
+ /**
+ *
+ */
+ public void testCharArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.cArr = new char[] {'a', 'a', 'a'};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ char[] arr = mutObj.getField("cArr");
+ arr[0] = 'b';
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new char[] {'b', 'a', 'a'}, res.cArr);
+ }
+
+ /**
+ *
+ */
+ public void testDoubleArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.dArr = new double[] {1.0, 1.0, 1.0};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ double[] arr = mutObj.getField("dArr");
+ arr[0] = 2.0;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new double[] {2.0, 1.0, 1.0}, res.dArr, 0);
+ }
+
+ /**
+ *
+ */
+ public void testFloatArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.fArr = new float[] {1.0f, 1.0f, 1.0f};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ float[] arr = mutObj.getField("fArr");
+ arr[0] = 2.0f;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new float[] {2.0f, 1.0f, 1.0f}, res.fArr, 0);
+ }
+
+ /**
+ *
+ */
+ public void testLongArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.lArr = new long[] {1, 1, 1};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ long[] arr = mutObj.getField("lArr");
+ arr[0] = 2;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new long[] {2, 1, 1}, res.lArr);
+ }
+
+ /**
+ *
+ */
+ public void testIntArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.iArr = new int[] {1, 1, 1};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ int[] arr = mutObj.getField("iArr");
+ arr[0] = 2;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new int[] {2, 1, 1}, res.iArr);
+ }
+
+ /**
+ *
+ */
+ public void testShortArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.sArr = new short[] {1, 1, 1};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ short[] arr = mutObj.getField("sArr");
+ arr[0] = 2;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new short[] {2, 1, 1}, res.sArr);
+ }
+
+ /**
+ *
+ */
+ public void testByteArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.bArr = new byte[] {1, 1, 1};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ byte[] arr = mutObj.getField("bArr");
+ arr[0] = 2;
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new byte[] {2, 1, 1}, res.bArr);
+ }
+
+ /**
+ *
+ */
+ public void testStringArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.strArr = new String[] {"a", "a", "a"};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ String[] arr = mutObj.getField("strArr");
+ arr[0] = "b";
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new String[] {"b", "a", "a"}, res.strArr);
+ }
+
+ /**
+ *
+ */
+ public void testModifyObjectArray() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = new Object[] {"a"};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ Object[] arr = mutObj.getField("foo");
+
+ Assert.assertArrayEquals(new Object[] {"a"}, arr);
+
+ arr[0] = "b";
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new Object[] {"b"}, (Object[])res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testOverrideObjectArrayField() {
+ PortableBuilderImpl mutObj = wrap(new TestObjectContainer());
+
+ Object[] createdArr = {mutObj, "a", 1, new String[] {"s", "s"}, new byte[] {1, 2}, new UUID(3, 0)};
+
+ mutObj.setField("foo", createdArr.clone());
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ createdArr[0] = res;
+
+ assertTrue(Objects.deepEquals(createdArr, res.foo));
+ }
+
+ /**
+ *
+ */
+ public void testDeepArray() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = new Object[] {new Object[] {"a", obj}};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ Object[] arr = (Object[])mutObj.<Object[]>getField("foo")[0];
+
+ assertEquals("a", arr[0]);
+ assertSame(mutObj, arr[1]);
+
+ arr[0] = mutObj;
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ arr = (Object[])((Object[])res.foo)[0];
+
+ assertSame(arr[0], res);
+ assertSame(arr[0], arr[1]);
+ }
+
+ /**
+ *
+ */
+ public void testArrayListRead() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Lists.newArrayList(obj, "a");
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ List<Object> list = mutObj.getField("foo");
+
+ assert list.equals(Lists.newArrayList(mutObj, "a"));
+ }
+
+ /**
+ *
+ */
+ public void testArrayListOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ ArrayList<Object> list = Lists.newArrayList(mutObj, "a", Lists.newArrayList(1, 2));
+
+ mutObj.setField("foo", list);
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ list.set(0, res);
+
+ assertNotSame(list, res.foo);
+ assertEquals(list, res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testArrayListModification() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Lists.newArrayList("a", "b", "c");
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ List<String> list = mutObj.getField("foo");
+
+ list.add("!"); // "a", "b", "c", "!"
+ list.add(0, "_"); // "_", "a", "b", "c", "!"
+
+ String s = list.remove(1); // "_", "b", "c", "!"
+ assertEquals("a", s);
+
+ assertEquals(Arrays.asList("c", "!"), list.subList(2, 4));
+ assertEquals(1, list.indexOf("b"));
+ assertEquals(1, list.lastIndexOf("b"));
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ assertTrue(res.foo instanceof ArrayList);
+ assertEquals(Arrays.asList("_", "b", "c", "!"), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testArrayListClear() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Lists.newArrayList("a", "b", "c");
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ List<String> list = mutObj.getField("foo");
+
+ list.clear();
+
+ assertEquals(Collections.emptyList(), mutObj.build().<TestObjectContainer>deserialize().foo);
+ }
+
+ /**
+ *
+ */
+ public void testArrayListWriteUnmodifiable() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ ArrayList<Object> src = Lists.newArrayList(obj, "a", "b", "c");
+
+ obj.foo = src;
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ TestObjectContainer deserialized = mutObj.build().deserialize();
+
+ List<Object> res = (List<Object>)deserialized.foo;
+
+ src.set(0, deserialized);
+
+ assertEquals(src, res);
+ }
+
+ /**
+ *
+ */
+ public void testLinkedListRead() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Lists.newLinkedList(Arrays.asList(obj, "a"));
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ List<Object> list = mutObj.getField("foo");
+
+ assert list.equals(Lists.newLinkedList(Arrays.asList(mutObj, "a")));
+ }
+
+ /**
+ *
+ */
+ public void testLinkedListOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ List<Object> list = Lists.newLinkedList(Arrays.asList(mutObj, "a", Lists.newLinkedList(Arrays.asList(1, 2))));
+
+ mutObj.setField("foo", list);
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ list.set(0, res);
+
+ assertNotSame(list, res.foo);
+ assertEquals(list, res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testLinkedListModification() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ obj.foo = Lists.newLinkedList(Arrays.asList("a", "b", "c"));
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ List<String> list = mutObj.getField("foo");
+
+ list.add("!"); // "a", "b", "c", "!"
+ list.add(0, "_"); // "_", "a", "b", "c", "!"
+
+ String s = list.remove(1); // "_", "b", "c", "!"
+ assertEquals("a", s);
+
+ assertEquals(Arrays.asList("c", "!"), list.subList(2, 4));
+ assertEquals(1, list.indexOf("b"));
+ assertEquals(1, list.lastIndexOf("b"));
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ assertTrue(res.foo instanceof LinkedList);
+ assertEquals(Arrays.asList("_", "b", "c", "!"), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testLinkedListWriteUnmodifiable() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ LinkedList<Object> src = Lists.newLinkedList(Arrays.asList(obj, "a", "b", "c"));
+
+ obj.foo = src;
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ TestObjectContainer deserialized = mutObj.build().deserialize();
+
+ List<Object> res = (List<Object>)deserialized.foo;
+
+ src.set(0, deserialized);
+
+ assertEquals(src, res);
+ }
+
+ /**
+ *
+ */
+ public void testHashSetRead() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Sets.newHashSet(obj, "a");
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ Set<Object> set = mutObj.getField("foo");
+
+ assert set.equals(Sets.newHashSet(mutObj, "a"));
+ }
+
+ /**
+ *
+ */
+ public void testHashSetOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ Set<Object> c = Sets.newHashSet(mutObj, "a", Sets.newHashSet(1, 2));
+
+ mutObj.setField("foo", c);
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ c.remove(mutObj);
+ c.add(res);
+
+ assertNotSame(c, res.foo);
+ assertEquals(c, res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testHashSetModification() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Sets.newHashSet("a", "b", "c");
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ Set<String> set = mutObj.getField("foo");
+
+ set.remove("b");
+ set.add("!");
+
+ assertEquals(Sets.newHashSet("a", "!", "c"), set);
+ assertTrue(set.contains("a"));
+ assertTrue(set.contains("!"));
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ assertTrue(res.foo instanceof HashSet);
+ assertEquals(Sets.newHashSet("a", "!", "c"), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testHashSetWriteUnmodifiable() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ Set<Object> src = Sets.newHashSet(obj, "a", "b", "c");
+
+ obj.foo = src;
+
+ TestObjectContainer deserialized = wrap(obj).build().deserialize();
+
+ Set<Object> res = (Set<Object>)deserialized.foo;
+
+ src.remove(obj);
+ src.add(deserialized);
+
+ assertEquals(src, res);
+ }
+
+ /**
+ *
+ */
+ public void testMapRead() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Maps.newHashMap(ImmutableMap.of(obj, "a", "b", obj));
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ Map<Object, Object> map = mutObj.getField("foo");
+
+ assert map.equals(ImmutableMap.of(mutObj, "a", "b", mutObj));
+ }
+
+ /**
+ *
+ */
+ public void testMapOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ Map<Object, Object> map = Maps.newHashMap(ImmutableMap.of(mutObj, "a", "b", mutObj));
+
+ mutObj.setField("foo", map);
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ assertEquals(ImmutableMap.of(res, "a", "b", res), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testMapModification() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b"));
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ Map<Object, Object> map = mutObj.getField("foo");
+
+ map.put(3, mutObj);
+ Object rmv = map.remove(1);
+
+ assertEquals("a", rmv);
+
+ TestObjectContainer res = mutObj.build().deserialize();
+
+ assertEquals(ImmutableMap.of(2, "b", 3, res), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testEnumArrayModification() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+
+ obj.enumArr = new TestObjectEnum[] {TestObjectEnum.A, TestObjectEnum.B};
+
+ PortableBuilderImpl mutObj = wrap(obj);
+
+ PortableBuilderEnum[] arr = mutObj.getField("enumArr");
+ arr[0] = new PortableBuilderEnum(mutObj.typeId(), TestObjectEnum.B);
+
+ TestObjectAllTypes res = mutObj.build().deserialize();
+
+ Assert.assertArrayEquals(new TestObjectEnum[] {TestObjectEnum.A, TestObjectEnum.B}, res.enumArr);
+ }
+
+ /**
+ *
+ */
+ public void testEditObjectWithRawData() {
+ GridPortableMarshalerAwareTestClass obj = new GridPortableMarshalerAwareTestClass();
+
+ obj.s = "a";
+ obj.sRaw = "aa";
+
+ PortableBuilderImpl mutableObj = wrap(obj);
+
+ mutableObj.setField("s", "z");
+
+ GridPortableMarshalerAwareTestClass res = mutableObj.build().deserialize();
+ assertEquals("z", res.s);
+ assertEquals("aa", res.sRaw);
+ }
+
+ /**
+ *
+ */
+ public void testHashCode() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ PortableBuilderImpl mutableObj = wrap(obj);
+
+ assertEquals(obj.hashCode(), mutableObj.build().hashCode());
+
+ mutableObj.hashCode(25);
+
+ assertEquals(25, mutableObj.build().hashCode());
+ }
+
+ /**
+ *
+ */
+ public void testCollectionsInCollection() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = Lists.newArrayList(
+ Lists.newArrayList(1, 2),
+ Lists.newLinkedList(Arrays.asList(1, 2)),
+ Sets.newHashSet("a", "b"),
+ Sets.newLinkedHashSet(Arrays.asList("a", "b")),
+ Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b")));
+
+ TestObjectContainer deserialized = wrap(obj).build().deserialize();
+
+ assertEquals(obj.foo, deserialized.foo);
+ }
+
+ /**
+ *
+ */
+ public void testMapEntryModification() {
+ TestObjectContainer obj = new TestObjectContainer();
+ obj.foo = ImmutableMap.of(1, "a").entrySet().iterator().next();
+
+ PortableBuilderImpl mutableObj = wrap(obj);
+
+ Map.Entry<Object, Object> entry = mutableObj.getField("foo");
+
+ assertEquals(1, entry.getKey());
+ assertEquals("a", entry.getValue());
+
+ entry.setValue("b");
+
+ TestObjectContainer res = mutableObj.build().deserialize();
+
+ assertEquals(new GridMapEntry<>(1, "b"), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testMapEntryOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ PortableBuilderImpl mutableObj = wrap(obj);
+
+ mutableObj.setField("foo", new GridMapEntry<>(1, "a"));
+
+ TestObjectContainer res = mutableObj.build().deserialize();
+
+ assertEquals(new GridMapEntry<>(1, "a"), res.foo);
+ }
+
+ /**
+ *
+ */
+ public void testMetadataChangingDoublePut() {
+ PortableBuilderImpl mutableObj = wrap(new TestObjectContainer());
+
+ mutableObj.setField("xx567", "a");
+ mutableObj.setField("xx567", "b");
+
+ mutableObj.build();
+
+ PortableMetadata metadata = portables().metadata(TestObjectContainer.class);
+
+ assertEquals("String", metadata.fieldTypeName("xx567"));
+ }
+
+ /**
+ *
+ */
+ public void testMetadataChangingDoublePut2() {
+ PortableBuilderImpl mutableObj = wrap(new TestObjectContainer());
+
+ mutableObj.setField("xx567", "a");
+ mutableObj.setField("xx567", "b");
+
+ mutableObj.build();
+
+ PortableMetadata metadata = portables().metadata(TestObjectContainer.class);
+
+ assertEquals("String", metadata.fieldTypeName("xx567"));
+ }
+
+ /**
+ *
+ */
+ public void testMetadataChanging() {
+ TestObjectContainer c = new TestObjectContainer();
+
+ PortableBuilderImpl mutableObj = wrap(c);
+
+ mutableObj.setField("intField", 1);
+ mutableObj.setField("intArrField", new int[] {1});
+ mutableObj.setField("arrField", new String[] {"1"});
+ mutableObj.setField("strField", "1");
+ mutableObj.setField("colField", Lists.newArrayList("1"));
+ mutableObj.setField("mapField", Maps.newHashMap(ImmutableMap.of(1, "1")));
+ mutableObj.setField("enumField", TestObjectEnum.A);
+ mutableObj.setField("enumArrField", new Enum[] {TestObjectEnum.A});
+
+ mutableObj.build();
+
+ PortableMetadata metadata = portables().metadata(c.getClass());
+
+ assertTrue(metadata.fields().containsAll(Arrays.asList("intField", "intArrField", "arrField", "strField",
+ "colField", "mapField", "enumField", "enumArrField")));
+
+ assertEquals("int", metadata.fieldTypeName("intField"));
+ assertEquals("int[]", metadata.fieldTypeName("intArrField"));
+ assertEquals("String[]", metadata.fieldTypeName("arrField"));
+ assertEquals("String", metadata.fieldTypeName("strField"));
+ assertEquals("Collection", metadata.fieldTypeName("colField"));
+ assertEquals("Map", metadata.fieldTypeName("mapField"));
+ assertEquals("Enum", metadata.fieldTypeName("enumField"));
+ assertEquals("Enum[]", metadata.fieldTypeName("enumArrField"));
+ }
+
+ /**
+ *
+ */
+ public void testDateInObjectField() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ obj.foo = new Date();
+
+ PortableBuilderImpl mutableObj = wrap(obj);
+
+ assertEquals(Timestamp.class, mutableObj.getField("foo").getClass());
+ }
+
+ /**
+ *
+ */
+ public void testDateInCollection() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ obj.foo = Lists.newArrayList(new Date());
+
+ PortableBuilderImpl mutableObj = wrap(obj);
+
+ assertEquals(Timestamp.class, ((List<?>)mutableObj.getField("foo")).get(0).getClass());
+ }
+
+ /**
+ *
+ */
+ @SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
+ public void testDateArrayOverride() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ PortableBuilderImpl mutableObj = wrap(obj);
+
+ Date[] arr = {new Date()};
+
+ mutableObj.setField("foo", arr);
+
+ TestObjectContainer res = mutableObj.build().deserialize();
+
+ assertEquals(Date[].class, res.foo.getClass());
+ assertTrue(Objects.deepEquals(arr, res.foo));
+ }
+
+ /**
+ *
+ */
+ public void testChangeMap() {
+ AddressBook addrBook = new AddressBook();
+
+ addrBook.addCompany(new Company(1, "Google inc", 100, new Address("Saint-Petersburg", "Torzhkovskya", 1, 53), "occupation"));
+ addrBook.addCompany(new Company(2, "Apple inc", 100, new Address("Saint-Petersburg", "Torzhkovskya", 1, 54), "occupation"));
+ addrBook.addCompany(new Company(3, "Microsoft", 100, new Address("Saint-Petersburg", "Torzhkovskya", 1, 55), "occupation"));
+ addrBook.addCompany(new Company(4, "Oracle", 100, new Address("Saint-Petersburg", "Nevskiy", 1, 1), "occupation"));
+
+ PortableBuilderImpl mutableObj = wrap(addrBook);
+
+ Map<String, List<PortableBuilderImpl>> map = mutableObj.getField("companyByStreet");
+
+ List<PortableBuilderImpl> list = map.get("Torzhkovskya");
+
+ PortableBuilderImpl company = list.get(0);
+
+ assert "Google inc".equals(company.<String>getField("name"));
+
+ list.remove(0);
+
+ AddressBook res = mutableObj.build().deserialize();
+
+ assertEquals(Arrays.asList("Nevskiy", "Torzhkovskya"), new ArrayList<>(res.getCompanyByStreet().keySet()));
+
+ List<Company> torzhkovskyaCompanies = res.getCompanyByStreet().get("Torzhkovskya");
+
+ assertEquals(2, torzhkovskyaCompanies.size());
+ assertEquals("Apple inc", torzhkovskyaCompanies.get(0).name);
+ }
+
+ /**
+ *
+ */
+ public void testSavingObjectWithNotZeroStart() {
+ TestObjectOuter out = new TestObjectOuter();
+ TestObjectInner inner = new TestObjectInner();
+
+ out.inner = inner;
+ inner.outer = out;
+
+ PortableBuilderImpl builder = wrap(out);
+
+ PortableBuilderImpl innerBuilder = builder.getField("inner");
+
+ TestObjectInner res = innerBuilder.build().deserialize();
+
+ assertSame(res, res.outer.inner);
+ }
+
+ /**
+ *
+ */
+ public void testPortableObjectField() {
+ TestObjectContainer container = new TestObjectContainer(toPortable(new TestObjectArrayList()));
+
+ PortableBuilderImpl wrapper = wrap(container);
+
+ assertTrue(wrapper.getField("foo") instanceof PortableObject);
+
+ TestObjectContainer deserialized = wrapper.build().deserialize();
+ assertTrue(deserialized.foo instanceof PortableObject);
+ }
+
+ /**
+ *
+ */
+ public void testAssignPortableObject() {
+ TestObjectContainer container = new TestObjectContainer();
+
+ PortableBuilderImpl wrapper = wrap(container);
+
+ wrapper.setField("foo", toPortable(new TestObjectArrayList()));
+
+ TestObjectContainer deserialized = wrapper.build().deserialize();
+ assertTrue(deserialized.foo instanceof TestObjectArrayList);
+ }
+
+ /**
+ *
+ */
+ public void testRemoveFromNewObject() {
+ PortableBuilderImpl wrapper = newWrapper(TestObjectAllTypes.class);
+
+ wrapper.setField("str", "a");
+
+ wrapper.removeField("str");
+
+ assertNull(wrapper.build().<TestObjectAllTypes>deserialize().str);
+ }
+
+ /**
+ *
+ */
+ public void testRemoveFromExistingObject() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+ obj.setDefaultData();
+
+ PortableBuilderImpl wrapper = wrap(toPortable(obj));
+
+ wrapper.removeField("str");
+
+ assertNull(wrapper.build().<TestObjectAllTypes>deserialize().str);
+ }
+
+ /**
+ *
+ */
+ public void testCyclicArrays() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ Object[] arr1 = new Object[1];
+ Object[] arr2 = new Object[] {arr1};
+
+ arr1[0] = arr2;
+
+ obj.foo = arr1;
+
+ TestObjectContainer res = toPortable(obj).deserialize();
+
+ Object[] resArr = (Object[])res.foo;
+
+ assertSame(((Object[])resArr[0])[0], resArr);
+ }
+
+ /**
+ *
+ */
+ @SuppressWarnings("TypeMayBeWeakened")
+ public void testCyclicArrayList() {
+ TestObjectContainer obj = new TestObjectContainer();
+
+ List<Object> arr1 = new ArrayList<>();
+ List<Object> arr2 = new ArrayList<>();
+
+ arr1.add(arr2);
+ arr2.add(arr1);
+
+ obj.foo = arr1;
+
+ TestObjectContainer res = toPortable(obj).deserialize();
+
+ List<?> resArr = (List<?>)res.foo;
+
+ assertSame(((List<Object>)resArr.get(0)).get(0), resArr);
+ }
+
+ /**
+ * @param obj Object.
+ * @return Object in portable format.
+ */
+ private PortableObject toPortable(Object obj) {
+ return portables().toPortable(obj);
+ }
+
+ /**
+ * @param obj Object.
+ * @return GridMutablePortableObject.
+ */
+ private PortableBuilderImpl wrap(Object obj) {
+ return PortableBuilderImpl.wrap(toPortable(obj));
+ }
+
+ /**
+ * @param aCls Class.
+ * @return Wrapper.
+ */
+ private PortableBuilderImpl newWrapper(Class<?> aCls) {
+ CacheObjectPortableProcessorImpl processor = (CacheObjectPortableProcessorImpl)(
+ (IgnitePortablesImpl)portables()).processor();
+
+ return new PortableBuilderImpl(processor.portableContext(), processor.typeId(aCls.getName()),
+ aCls.getSimpleName());
+ }
+}
\ No newline at end of file
[02/11] ignite git commit: Revert "ignite-1462: hid portable API in
1.4 release" This reverts commit 71379a8061f50f336adc31fa20cd593b659b050f.
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
new file mode 100644
index 0000000..3f8cd1c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractDataStreamerSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ *
+ */
+public class GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest extends
+ GridCachePortableObjectsAbstractDataStreamerSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return PARTITIONED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return ATOMIC;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return null;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java
new file mode 100644
index 0000000..a53a5ea
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java
@@ -0,0 +1,28 @@
+/*
+ * 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.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest extends
+ GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest {
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 4;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
new file mode 100644
index 0000000..8f3a05f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractMultiThreadedSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ *
+ */
+public class GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest extends
+ GridCachePortableObjectsAbstractMultiThreadedSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return PARTITIONED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return ATOMIC;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return null;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheMemoryModePortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheMemoryModePortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheMemoryModePortableSelfTest.java
new file mode 100644
index 0000000..ab6b0dd
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheMemoryModePortableSelfTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheMemoryModeSelfTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ * Memory models test.
+ */
+public class GridCacheMemoryModePortableSelfTest extends GridCacheMemoryModeSelfTest {
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setMarshaller(new PortableMarshaller());
+
+ return cfg;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
new file mode 100644
index 0000000..c845257
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.distributed.dht;
+
+import java.util.Arrays;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredAtomicSelfTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ *
+ */
+public class GridCacheOffHeapTieredAtomicPortableSelfTest extends GridCacheOffHeapTieredAtomicSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean portableEnabled() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ // Enable portables.
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(TestValue.class.getName()));
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
new file mode 100644
index 0000000..1a0d601
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.distributed.dht;
+
+import java.util.Arrays;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionAtomicSelfTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableObject;
+
+/**
+ *
+ */
+public class GridCacheOffHeapTieredEvictionAtomicPortableSelfTest extends GridCacheOffHeapTieredEvictionAtomicSelfTest {
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ // Enable portables.
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(TestValue.class.getName()));
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected TestPredicate testPredicate(String expVal, boolean acceptNull) {
+ return new PortableValuePredicate(expVal, acceptNull);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected TestProcessor testClosure(String expVal, boolean acceptNull) {
+ return new PortableValueClosure(expVal, acceptNull);
+ }
+
+ /**
+ *
+ */
+ @SuppressWarnings("PackageVisibleInnerClass")
+ static class PortableValuePredicate extends TestPredicate {
+ /**
+ * @param expVal Expected value.
+ * @param acceptNull If {@code true} value can be null;
+ */
+ PortableValuePredicate(String expVal, boolean acceptNull) {
+ super(expVal, acceptNull);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void checkValue(Object val) {
+ PortableObject obj = (PortableObject)val;
+
+ assertEquals(expVal, obj.field("val"));
+ }
+ }
+
+ /**
+ *
+ */
+ @SuppressWarnings("PackageVisibleInnerClass")
+ static class PortableValueClosure extends TestProcessor {
+ /**
+ * @param expVal Expected value.
+ * @param acceptNull If {@code true} value can be null;
+ */
+ PortableValueClosure(String expVal, boolean acceptNull) {
+ super(expVal, acceptNull);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void checkValue(Object val) {
+ PortableObject obj = (PortableObject)val;
+
+ assertEquals(expVal, obj.field("val"));
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
new file mode 100644
index 0000000..60eed45
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.distributed.dht;
+
+import java.util.Arrays;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableObject;
+
+/**
+ *
+ */
+public class GridCacheOffHeapTieredEvictionPortableSelfTest extends GridCacheOffHeapTieredEvictionSelfTest {
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ // Enable portables.
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(TestValue.class.getName()));
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected TestPredicate testPredicate(String expVal, boolean acceptNull) {
+ return new PortableValuePredicate(expVal, acceptNull);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected TestProcessor testClosure(String expVal, boolean acceptNull) {
+ return new PortableValueClosure(expVal, acceptNull);
+ }
+
+ /**
+ *
+ */
+ @SuppressWarnings("PackageVisibleInnerClass")
+ static class PortableValuePredicate extends TestPredicate {
+ /**
+ * @param expVal Expected value.
+ * @param acceptNull If {@code true} value can be null;
+ */
+ PortableValuePredicate(String expVal, boolean acceptNull) {
+ super(expVal, acceptNull);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void checkValue(Object val) {
+ PortableObject obj = (PortableObject)val;
+
+ assertEquals(expVal, obj.field("val"));
+ }
+ }
+
+ /**
+ *
+ */
+ @SuppressWarnings("PackageVisibleInnerClass")
+ static class PortableValueClosure extends TestProcessor {
+ /**
+ * @param expVal Expected value.
+ * @param acceptNull If {@code true} value can be null;
+ */
+ PortableValueClosure(String expVal, boolean acceptNull) {
+ super(expVal, acceptNull);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void checkValue(Object val) {
+ PortableObject obj = (PortableObject)val;
+
+ assertEquals(expVal, obj.field("val"));
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
new file mode 100644
index 0000000..6170e39
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.distributed.dht;
+
+import java.util.Arrays;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredSelfTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ *
+ */
+public class GridCacheOffHeapTieredPortableSelfTest extends GridCacheOffHeapTieredSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean portableEnabled() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ // Enable portables.
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(TestValue.class.getName()));
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java
new file mode 100644
index 0000000..e6f7499
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.internal.processors.cache.portable.GridPortableDuplicateIndexObjectsAbstractSelfTest;
+
+/**
+ * Test PARTITIONED ATOMIC.
+ */
+public class GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest extends
+ GridPortableDuplicateIndexObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override public CacheAtomicityMode atomicityMode() {
+ return CacheAtomicityMode.ATOMIC;
+ }
+
+ /** {@inheritDoc} */
+ @Override public CacheMode cacheMode() {
+ return CacheMode.PARTITIONED;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java
new file mode 100644
index 0000000..b5dc4e9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.internal.processors.cache.portable.GridPortableDuplicateIndexObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test PARTITIONED and TRANSACTIONAL.
+ */
+public class GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest extends
+ GridPortableDuplicateIndexObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override public CacheAtomicityMode atomicityMode() {
+ return TRANSACTIONAL;
+ }
+
+ /** {@inheritDoc} */
+ @Override public CacheMode cacheMode() {
+ return PARTITIONED;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest.java
new file mode 100644
index 0000000..a5c28f3
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.distributed.dht;
+
+/**
+ *
+ */
+public class GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest
+ extends GridCachePortableObjectsAtomicNearDisabledSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean offheapTiered() {
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledSelfTest.java
new file mode 100644
index 0000000..696c3ed
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicNearDisabledSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCachePortableObjectsAtomicNearDisabledSelfTest extends GridCachePortableObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return PARTITIONED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return ATOMIC;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 3;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicOffheapTieredSelfTest.java
new file mode 100644
index 0000000..8e04fa1
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicOffheapTieredSelfTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.distributed.dht;
+
+/**
+ *
+ */
+public class GridCachePortableObjectsAtomicOffheapTieredSelfTest extends GridCachePortableObjectsAtomicSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean offheapTiered() {
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicSelfTest.java
new file mode 100644
index 0000000..106e59b
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsAtomicSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCachePortableObjectsAtomicSelfTest extends GridCachePortableObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return PARTITIONED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return ATOMIC;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return new NearCacheConfiguration();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 3;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
new file mode 100644
index 0000000..5bc4672
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.distributed.dht;
+
+/**
+ *
+ */
+public class GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest
+ extends GridCachePortableObjectsPartitionedNearDisabledSelfTest{
+ /** {@inheritDoc} */
+ @Override protected boolean offheapTiered() {
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledSelfTest.java
new file mode 100644
index 0000000..df55de7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedNearDisabledSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCachePortableObjectsPartitionedNearDisabledSelfTest extends GridCachePortableObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return PARTITIONED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return TRANSACTIONAL;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 3;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedOffheapTieredSelfTest.java
new file mode 100644
index 0000000..a6bc0b4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedOffheapTieredSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.distributed.dht;
+
+/**
+ *
+ */
+public class GridCachePortableObjectsPartitionedOffheapTieredSelfTest
+ extends GridCachePortableObjectsPartitionedSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean offheapTiered() {
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedSelfTest.java
new file mode 100644
index 0000000..8c248be
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableObjectsPartitionedSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCachePortableObjectsPartitionedSelfTest extends GridCachePortableObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return PARTITIONED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return TRANSACTIONAL;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return new NearCacheConfiguration();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 3;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java
new file mode 100644
index 0000000..d984756
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAbstractNearPartitionedByteArrayValuesSelfTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ *
+ */
+public class GridCachePortablesNearPartitionedByteArrayValuesSelfTest
+ extends GridCacheAbstractNearPartitionedByteArrayValuesSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean peerClassLoading() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setMarshaller(new PortableMarshaller());
+
+ return cfg;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java
new file mode 100644
index 0000000..5830b12
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.distributed.dht;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAbstractPartitionedOnlyByteArrayValuesSelfTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ *
+ */
+public class GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest
+ extends GridCacheAbstractPartitionedOnlyByteArrayValuesSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean peerClassLoading() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ cfg.setMarshaller(new PortableMarshaller());
+
+ return cfg;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCachePortableObjectsReplicatedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCachePortableObjectsReplicatedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCachePortableObjectsReplicatedSelfTest.java
new file mode 100644
index 0000000..953fbfa
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCachePortableObjectsReplicatedSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.distributed.replicated;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCachePortableObjectsReplicatedSelfTest extends GridCachePortableObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return REPLICATED;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return TRANSACTIONAL;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 3;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsAtomicLocalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsAtomicLocalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsAtomicLocalSelfTest.java
new file mode 100644
index 0000000..3f3a350
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsAtomicLocalSelfTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.local;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+
+/**
+ *
+ */
+public class GridCachePortableObjectsAtomicLocalSelfTest extends GridCachePortableObjectsLocalSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return ATOMIC;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalOffheapTieredSelfTest.java
new file mode 100644
index 0000000..53713ce
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalOffheapTieredSelfTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.local;
+
+/**
+ *
+ */
+public class GridCachePortableObjectsLocalOffheapTieredSelfTest extends GridCachePortableObjectsLocalSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean offheapTiered() {
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalSelfTest.java
new file mode 100644
index 0000000..1a87865
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCachePortableObjectsLocalSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.local;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.portable.GridCachePortableObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.LOCAL;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCachePortableObjectsLocalSelfTest extends GridCachePortableObjectsAbstractSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheMode cacheMode() {
+ return LOCAL;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected CacheAtomicityMode atomicityMode() {
+ return TRANSACTIONAL;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected NearCacheConfiguration nearConfiguration() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected int gridCount() {
+ return 1;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
index 964753d..1e4c828 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
@@ -35,6 +35,7 @@ import org.apache.ignite.IgniteEvents;
import org.apache.ignite.IgniteFileSystem;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteMessaging;
+import org.apache.ignite.IgnitePortables;
import org.apache.ignite.IgniteQueue;
import org.apache.ignite.IgniteScheduler;
import org.apache.ignite.IgniteServices;
@@ -270,6 +271,11 @@ public class IgniteMock implements Ignite {
}
/** {@inheritDoc} */
+ @Override public IgnitePortables portables() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
@Override public void close() {}
@Nullable @Override public IgniteAtomicSequence atomicSequence(String name, long initVal, boolean create) {
@@ -333,4 +339,4 @@ public class IgniteMock implements Ignite {
public void setStaticCfg(IgniteConfiguration staticCfg) {
this.staticCfg = staticCfg;
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
index dfbb0ae..2b448f8 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteCacheProcessProxy.java
@@ -153,6 +153,11 @@ public class IgniteCacheProcessProxy<K, V> implements IgniteCache<K, V> {
}
/** {@inheritDoc} */
+ @Override public <K1, V1> IgniteCache<K1, V1> withKeepPortable() {
+ throw new UnsupportedOperationException("Method should be supported.");
+ }
+
+ /** {@inheritDoc} */
@Override public void loadCache(@Nullable IgniteBiPredicate<K, V> p, @Nullable Object... args) throws CacheException {
throw new UnsupportedOperationException("Method should be supported.");
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
index ec7dab7..3522407 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/multijvm/IgniteProcessProxy.java
@@ -41,7 +41,7 @@ import org.apache.ignite.IgniteFileSystem;
import org.apache.ignite.IgniteIllegalStateException;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteMessaging;
-import org.apache.ignite.internal.portable.api.IgnitePortables;
+import org.apache.ignite.IgnitePortables;
import org.apache.ignite.IgniteQueue;
import org.apache.ignite.IgniteScheduler;
import org.apache.ignite.IgniteServices;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java
new file mode 100644
index 0000000..d7dda61
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java
@@ -0,0 +1,37 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.testframework.config.GridTestProperties;
+
+/**
+ * Cache full API suite with portable marshaller.
+ */
+public class IgnitePortableCacheFullApiTestSuite extends TestSuite {
+ /**
+ * @return Suite.
+ * @throws Exception In case of error.
+ */
+ public static TestSuite suite() throws Exception {
+ GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, PortableMarshaller.class.getName());
+
+ return IgniteCacheFullApiSelfTestSuite.suite();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
new file mode 100644
index 0000000..db20e48
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
@@ -0,0 +1,103 @@
+/*
+ * 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.testsuites;
+
+import java.util.HashSet;
+import junit.framework.TestSuite;
+import org.apache.ignite.internal.processors.cache.GridCacheAffinityRoutingSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryMemorySizeSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheMvccSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.expiry.IgniteCacheAtomicLocalExpiryPolicyTest;
+import org.apache.ignite.internal.processors.cache.expiry.IgniteCacheExpiryPolicyTestSuite;
+import org.apache.ignite.internal.processors.cache.portable.GridPortableCacheEntryMemorySizeSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.datastreaming.DataStreamProcessorPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.datastreaming.GridDataStreamerImplSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheAffinityRoutingPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheMemoryModePortableSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheOffHeapTieredAtomicPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheOffHeapTieredEvictionAtomicPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheOffHeapTieredEvictionPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheOffHeapTieredPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortablesNearPartitionedByteArrayValuesSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest;
+import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.testframework.config.GridTestProperties;
+
+/**
+ * Cache suite with portable marshaller.
+ */
+public class IgnitePortableCacheTestSuite extends TestSuite {
+ /**
+ * @return Suite.
+ * @throws Exception In case of error.
+ */
+ public static TestSuite suite() throws Exception {
+ GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, PortableMarshaller.class.getName());
+
+ TestSuite suite = new TestSuite("Portable Cache Test Suite");
+
+ HashSet<Class> ignoredTests = new HashSet<>();
+
+ // Tests below have a special version for Portable Marshaller
+ ignoredTests.add(DataStreamProcessorSelfTest.class);
+ ignoredTests.add(GridCacheOffHeapTieredEvictionAtomicSelfTest.class);
+ ignoredTests.add(GridCacheOffHeapTieredEvictionSelfTest.class);
+ ignoredTests.add(GridCacheOffHeapTieredSelfTest.class);
+ ignoredTests.add(GridCacheOffHeapTieredAtomicSelfTest.class);
+ ignoredTests.add(GridCacheAffinityRoutingSelfTest.class);
+ ignoredTests.add(IgniteCacheAtomicLocalExpiryPolicyTest.class);
+ ignoredTests.add(GridCacheEntryMemorySizeSelfTest.class);
+
+ // Tests that are not ready to be used with PortableMarshaller
+ ignoredTests.add(GridCacheMvccSelfTest.class);
+
+ suite.addTest(IgniteCacheTestSuite.suite(ignoredTests));
+ suite.addTest(IgniteCacheExpiryPolicyTestSuite.suite());
+
+ suite.addTestSuite(GridCacheMemoryModePortableSelfTest.class);
+ suite.addTestSuite(GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.class);
+ suite.addTestSuite(GridCacheOffHeapTieredEvictionPortableSelfTest.class);
+
+ suite.addTestSuite(GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.class);
+ suite.addTestSuite(GridCachePortablesNearPartitionedByteArrayValuesSelfTest.class);
+ suite.addTestSuite(GridCacheOffHeapTieredPortableSelfTest.class);
+ suite.addTestSuite(GridCacheOffHeapTieredAtomicPortableSelfTest.class);
+
+ suite.addTestSuite(GridDataStreamerImplSelfTest.class);
+ suite.addTestSuite(DataStreamProcessorPortableSelfTest.class);
+ suite.addTestSuite(GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.class);
+ suite.addTestSuite(GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.class);
+
+ suite.addTestSuite(GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.class);
+ suite.addTestSuite(GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.class);
+
+ suite.addTestSuite(GridCacheAffinityRoutingPortableSelfTest.class);
+ suite.addTestSuite(GridPortableCacheEntryMemorySizeSelfTest.class);
+
+ return suite;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
new file mode 100644
index 0000000..ecd25e1
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
@@ -0,0 +1,92 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.internal.portable.GridPortableAffinityKeySelfTest;
+import org.apache.ignite.internal.portable.GridPortableBuilderAdditionalSelfTest;
+import org.apache.ignite.internal.portable.GridPortableBuilderSelfTest;
+import org.apache.ignite.internal.portable.GridPortableBuilderStringAsCharsAdditionalSelfTest;
+import org.apache.ignite.internal.portable.GridPortableBuilderStringAsCharsSelfTest;
+import org.apache.ignite.internal.portable.GridPortableMarshallerCtxDisabledSelfTest;
+import org.apache.ignite.internal.portable.GridPortableMarshallerSelfTest;
+import org.apache.ignite.internal.portable.GridPortableMetaDataDisabledSelfTest;
+import org.apache.ignite.internal.portable.GridPortableMetaDataSelfTest;
+import org.apache.ignite.internal.portable.GridPortableWildcardsSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.GridCacheClientNodePortableMetadataMultinodeTest;
+import org.apache.ignite.internal.processors.cache.portable.GridCacheClientNodePortableMetadataTest;
+import org.apache.ignite.internal.processors.cache.portable.GridCachePortableStoreObjectsSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.GridCachePortableStorePortablesSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsAtomicNearDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsAtomicOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsPartitionedNearDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsPartitionedOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableObjectsPartitionedSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.distributed.replicated.GridCachePortableObjectsReplicatedSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.local.GridCachePortableObjectsAtomicLocalSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.local.GridCachePortableObjectsLocalOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.portable.local.GridCachePortableObjectsLocalSelfTest;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class IgnitePortableObjectsTestSuite extends TestSuite {
+ /**
+ * @return Suite.
+ * @throws Exception If failed.
+ */
+ public static TestSuite suite() throws Exception {
+ TestSuite suite = new TestSuite("GridGain Portable Objects Test Suite");
+
+ suite.addTestSuite(GridPortableMarshallerSelfTest.class);
+ suite.addTestSuite(GridPortableMarshallerCtxDisabledSelfTest.class);
+ suite.addTestSuite(GridPortableBuilderSelfTest.class);
+ suite.addTestSuite(GridPortableBuilderStringAsCharsSelfTest.class);
+ suite.addTestSuite(GridPortableMetaDataSelfTest.class);
+ suite.addTestSuite(GridPortableMetaDataDisabledSelfTest.class);
+ suite.addTestSuite(GridPortableAffinityKeySelfTest.class);
+ suite.addTestSuite(GridPortableWildcardsSelfTest.class);
+ suite.addTestSuite(GridPortableBuilderAdditionalSelfTest.class);
+ suite.addTestSuite(GridPortableBuilderStringAsCharsAdditionalSelfTest.class);
+
+ suite.addTestSuite(GridCachePortableObjectsLocalSelfTest.class);
+ suite.addTestSuite(GridCachePortableObjectsAtomicLocalSelfTest.class);
+ suite.addTestSuite(GridCachePortableObjectsReplicatedSelfTest.class);
+ suite.addTestSuite(GridCachePortableObjectsPartitionedSelfTest.class);
+ suite.addTestSuite(GridCachePortableObjectsPartitionedNearDisabledSelfTest.class);
+ suite.addTestSuite(GridCachePortableObjectsAtomicSelfTest.class);
+ suite.addTestSuite(GridCachePortableObjectsAtomicNearDisabledSelfTest.class);
+
+ suite.addTestSuite(GridCachePortableObjectsLocalOffheapTieredSelfTest.class);
+ suite.addTestSuite(GridCachePortableObjectsAtomicOffheapTieredSelfTest.class);
+ suite.addTestSuite(GridCachePortableObjectsAtomicNearDisabledOffheapTieredSelfTest.class);
+ suite.addTestSuite(GridCachePortableObjectsPartitionedOffheapTieredSelfTest.class);
+ suite.addTestSuite(GridCachePortableObjectsPartitionedNearDisabledOffheapTieredSelfTest.class);
+
+ suite.addTestSuite(GridCachePortableStoreObjectsSelfTest.class);
+ suite.addTestSuite(GridCachePortableStorePortablesSelfTest.class);
+
+ suite.addTestSuite(GridCacheClientNodePortableMetadataTest.class);
+ suite.addTestSuite(GridCacheClientNodePortableMetadataMultinodeTest.class);
+
+ return suite;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.jar
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.jar b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.jar
new file mode 100644
index 0000000..863350d
Binary files /dev/null and b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.jar differ
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom
new file mode 100644
index 0000000..c79dfbf
--- /dev/null
+++ b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.ignite.portable</groupId>
+ <artifactId>test1</artifactId>
+ <version>1.1</version>
+ <description>POM was created from install:install-file</description>
+</project>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml
new file mode 100644
index 0000000..33f5abf
--- /dev/null
+++ b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata>
+ <groupId>org.apache.ignite.portable</groupId>
+ <artifactId>test1</artifactId>
+ <versioning>
+ <release>1.1</release>
+ <versions>
+ <version>1.1</version>
+ </versions>
+ <lastUpdated>20140806090184</lastUpdated>
+ </versioning>
+</metadata>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.jar
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.jar b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.jar
new file mode 100644
index 0000000..ccf4ea2
Binary files /dev/null and b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.jar differ
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom
new file mode 100644
index 0000000..37621e1
--- /dev/null
+++ b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.ignite.portable</groupId>
+ <artifactId>test2</artifactId>
+ <version>1.1</version>
+ <description>POM was created from install:install-file</description>
+</project>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml
new file mode 100644
index 0000000..9c705ef
--- /dev/null
+++ b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata>
+ <groupId>org.apache.ignite.portable</groupId>
+ <artifactId>test2</artifactId>
+ <versioning>
+ <release>1.1</release>
+ <versions>
+ <version>1.1</version>
+ </versions>
+ <lastUpdated>20140806090410</lastUpdated>
+ </versioning>
+</metadata>
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopDefaultMapReducePlannerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopDefaultMapReducePlannerSelfTest.java b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopDefaultMapReducePlannerSelfTest.java
index 833e49e..2bdf28c 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopDefaultMapReducePlannerSelfTest.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/internal/processors/hadoop/HadoopDefaultMapReducePlannerSelfTest.java
@@ -43,7 +43,6 @@ import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.cluster.IgniteClusterEx;
-import org.apache.ignite.internal.portable.api.IgnitePortables;
import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
import org.apache.ignite.internal.processors.igfs.IgfsBlockLocationImpl;
@@ -1025,10 +1024,5 @@ public class HadoopDefaultMapReducePlannerSelfTest extends HadoopAbstractSelfTes
@Override public GridKernalContext context() {
return null;
}
-
- /** {@inheritDoc} */
- @Override public IgnitePortables portables() {
- return null;
- }
}
}
\ No newline at end of file
[09/11] ignite git commit: Revert "ignite-1462: hid portable API in
1.4 release" This reverts commit 71379a8061f50f336adc31fa20cd593b659b050f.
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableMarshaller.java
deleted file mode 100644
index de0df8d..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableMarshaller.java
+++ /dev/null
@@ -1,358 +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.api;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableContext;
-import org.apache.ignite.marshaller.AbstractMarshaller;
-import org.apache.ignite.marshaller.MarshallerContext;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableIdMapper;
-import org.apache.ignite.internal.portable.api.PortableObject;
-import org.apache.ignite.internal.portable.api.PortableProtocolVersion;
-import org.apache.ignite.internal.portable.api.PortableSerializer;
-import org.apache.ignite.internal.portable.api.PortableTypeConfiguration;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Implementation of {@link org.apache.ignite.marshaller.Marshaller} that lets to serialize and deserialize all objects
- * in the portable format.
- * <p>
- * {@code PortableMarshaller} is tested only on Java HotSpot VM on other VMs it could yield unexpected results.
- * <p>
- * <h1 class="header">Configuration</h1>
- * <h2 class="header">Mandatory</h2>
- * This marshaller has no mandatory configuration parameters.
- * <h2 class="header">Java Example</h2>
- * <pre name="code" class="java">
- * PortableMarshaller marshaller = new PortableMarshaller();
- *
- * IgniteConfiguration cfg = new IgniteConfiguration();
- *
- * // Override marshaller.
- * cfg.setMarshaller(marshaller);
- *
- * // Starts grid.
- * G.start(cfg);
- * </pre>
- * <h2 class="header">Spring Example</h2>
- * PortableMarshaller can be configured from Spring XML configuration file:
- * <pre name="code" class="xml">
- * <bean id="grid.custom.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" singleton="true">
- * ...
- * <property name="marshaller">
- * <bean class="org.apache.ignite.internal.portable.api.PortableMarshaller">
- * ...
- * </bean>
- * </property>
- * ...
- * </bean>
- * </pre>
- * <p>
- * <img src="http://ignite.apache.org/images/spring-small.png">
- * <br>
- * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a>
- */
-public class PortableMarshaller extends AbstractMarshaller {
- /** Default portable protocol version. */
- public static final PortableProtocolVersion DFLT_PORTABLE_PROTO_VER = PortableProtocolVersion.VER_1_4_0;
-
- /** Class names. */
- private Collection<String> clsNames;
-
- /** ID mapper. */
- private PortableIdMapper idMapper;
-
- /** Serializer. */
- private PortableSerializer serializer;
-
- /** Types. */
- private Collection<PortableTypeConfiguration> typeCfgs;
-
- /** Use timestamp flag. */
- private boolean useTs = true;
-
- /** Whether to convert string to bytes using UTF-8 encoding. */
- private boolean convertString = true;
-
- /** Meta data enabled flag. */
- private boolean metaDataEnabled = true;
-
- /** Keep deserialized flag. */
- private boolean keepDeserialized = true;
-
- /** Protocol version. */
- private PortableProtocolVersion protoVer = DFLT_PORTABLE_PROTO_VER;
-
- /** */
- private GridPortableMarshaller impl;
-
- /**
- * Gets class names.
- *
- * @return Class names.
- */
- public Collection<String> getClassNames() {
- return clsNames;
- }
-
- /**
- * Sets class names of portable objects explicitly.
- *
- * @param clsNames Class names.
- */
- public void setClassNames(Collection<String> clsNames) {
- this.clsNames = new ArrayList<>(clsNames.size());
-
- for (String clsName : clsNames)
- this.clsNames.add(clsName.trim());
- }
-
- /**
- * Gets ID mapper.
- *
- * @return ID mapper.
- */
- public PortableIdMapper getIdMapper() {
- return idMapper;
- }
-
- /**
- * Sets ID mapper.
- *
- * @param idMapper ID mapper.
- */
- public void setIdMapper(PortableIdMapper idMapper) {
- this.idMapper = idMapper;
- }
-
- /**
- * Gets serializer.
- *
- * @return Serializer.
- */
- public PortableSerializer getSerializer() {
- return serializer;
- }
-
- /**
- * Sets serializer.
- *
- * @param serializer Serializer.
- */
- public void setSerializer(PortableSerializer serializer) {
- this.serializer = serializer;
- }
-
- /**
- * Gets types configuration.
- *
- * @return Types configuration.
- */
- public Collection<PortableTypeConfiguration> getTypeConfigurations() {
- return typeCfgs;
- }
-
- /**
- * Sets type configurations.
- *
- * @param typeCfgs Type configurations.
- */
- public void setTypeConfigurations(Collection<PortableTypeConfiguration> typeCfgs) {
- this.typeCfgs = typeCfgs;
- }
-
- /**
- * If {@code true} then date values converted to {@link Timestamp} on deserialization.
- * <p>
- * Default value is {@code true}.
- *
- * @return Flag indicating whether date values converted to {@link Timestamp} during unmarshalling.
- */
- public boolean isUseTimestamp() {
- return useTs;
- }
-
- /**
- * @param useTs Flag indicating whether date values converted to {@link Timestamp} during unmarshalling.
- */
- public void setUseTimestamp(boolean useTs) {
- this.useTs = useTs;
- }
-
- /**
- * Gets strings must be converted to or from bytes using UTF-8 encoding.
- * <p>
- * Default value is {@code true}.
- *
- * @return Flag indicating whether string must be converted to byte array using UTF-8 encoding.
- */
- public boolean isConvertStringToBytes() {
- return convertString;
- }
-
- /**
- * Sets strings must be converted to or from bytes using UTF-8 encoding.
- * <p>
- * Default value is {@code true}.
- *
- * @param convertString Flag indicating whether string must be converted to byte array using UTF-8 encoding.
- */
- public void setConvertStringToBytes(boolean convertString) {
- this.convertString = convertString;
- }
-
- /**
- * If {@code true}, meta data will be collected or all types. If you need to override this behaviour for
- * some specific type, use {@link PortableTypeConfiguration#setMetaDataEnabled(Boolean)} method.
- * <p>
- * Default value if {@code true}.
- *
- * @return Whether meta data is collected.
- */
- public boolean isMetaDataEnabled() {
- return metaDataEnabled;
- }
-
- /**
- * @param metaDataEnabled Whether meta data is collected.
- */
- public void setMetaDataEnabled(boolean metaDataEnabled) {
- this.metaDataEnabled = metaDataEnabled;
- }
-
- /**
- * If {@code true}, {@link PortableObject} will cache deserialized instance after
- * {@link PortableObject#deserialize()} is called. All consequent calls of this
- * method on the same instance of {@link PortableObject} will return that cached
- * value without actually deserializing portable object. If you need to override this
- * behaviour for some specific type, use {@link PortableTypeConfiguration#setKeepDeserialized(Boolean)}
- * method.
- * <p>
- * Default value if {@code true}.
- *
- * @return Whether deserialized value is kept.
- */
- public boolean isKeepDeserialized() {
- return keepDeserialized;
- }
-
- /**
- * @param keepDeserialized Whether deserialized value is kept.
- */
- public void setKeepDeserialized(boolean keepDeserialized) {
- this.keepDeserialized = keepDeserialized;
- }
-
- /**
- * Gets portable protocol version.
- * <p>
- * Defaults to {@link #DFLT_PORTABLE_PROTO_VER}.
- *
- * @return Portable protocol version.
- */
- public PortableProtocolVersion getProtocolVersion() {
- return protoVer;
- }
-
- /**
- * Sets portable protocol version.
- * <p>
- * Defaults to {@link #DFLT_PORTABLE_PROTO_VER}.
- *
- * @param protoVer Portable protocol version.
- */
- public void setProtocolVersion(PortableProtocolVersion protoVer) {
- if (protoVer == null)
- throw new IllegalArgumentException("Wrong portable protocol version: " + protoVer);
-
- this.protoVer = protoVer;
- }
-
- /**
- * Returns currently set {@link MarshallerContext}.
- *
- * @return Marshaller context.
- */
- public MarshallerContext getContext() {
- return ctx;
- }
-
- /**
- * Sets {@link PortableContext}.
- * <p/>
- * @param ctx Portable context.
- */
- private void setPortableContext(PortableContext ctx) {
- ctx.configure(this);
-
- impl = new GridPortableMarshaller(ctx);
- }
-
- /** {@inheritDoc} */
- @Override public byte[] marshal(@Nullable Object obj) throws IgniteCheckedException {
- return impl.marshal(obj, 0);
- }
-
- /** {@inheritDoc} */
- @Override public void marshal(@Nullable Object obj, OutputStream out) throws IgniteCheckedException {
- byte[] arr = marshal(obj);
-
- try {
- out.write(arr);
- }
- catch (IOException e) {
- throw new PortableException("Failed to marshal the object: " + obj, e);
- }
- }
-
- /** {@inheritDoc} */
- @Override public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
- return impl.deserialize(bytes, clsLdr);
- }
-
- /** {@inheritDoc} */
- @Override public <T> T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
- ByteArrayOutputStream buffer = new ByteArrayOutputStream();
-
- byte[] arr = new byte[4096];
- int cnt;
-
- // we have to fully read the InputStream because GridPortableMarshaller requires support of a method that
- // returns number of bytes remaining.
- try {
- while ((cnt = in.read(arr)) != -1)
- buffer.write(arr, 0, cnt);
-
- buffer.flush();
-
- return impl.deserialize(buffer.toByteArray(), clsLdr);
- }
- catch (IOException e) {
- throw new PortableException("Failed to unmarshal the object from InputStream", e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableMetadata.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableMetadata.java
deleted file mode 100644
index a90bdca..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableMetadata.java
+++ /dev/null
@@ -1,60 +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.api;
-
-import java.util.Collection;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Portable type meta data. Metadata for portable types can be accessed from any of the
- * {@link IgnitePortables#metadata(String)} methods.
- * Having metadata also allows for proper formatting of {@code PortableObject#toString()} method,
- * even when portable objects are kept in binary format only, which may be necessary for audit reasons.
- */
-public interface PortableMetadata {
- /**
- * Gets portable type name.
- *
- * @return Portable type name.
- */
- public String typeName();
-
- /**
- * Gets collection of all field names for this portable type.
- *
- * @return Collection of all field names for this portable type.
- */
- public Collection<String> fields();
-
- /**
- * Gets name of the field type for a given field.
- *
- * @param fieldName Field name.
- * @return Field type name.
- */
- @Nullable public String fieldTypeName(String fieldName);
-
- /**
- * Portable objects can optionally specify custom key-affinity mapping in the
- * configuration. This method returns the name of the field which should be
- * used for the key-affinity mapping.
- *
- * @return Affinity key field name.
- */
- @Nullable public String affinityKeyFieldName();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableObject.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableObject.java
deleted file mode 100644
index ec965c6..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableObject.java
+++ /dev/null
@@ -1,152 +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.api;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.TreeMap;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Wrapper for portable object in portable binary format. Once an object is defined as portable,
- * Ignite will always store it in memory in the portable (i.e. binary) format.
- * User can choose to work either with the portable format or with the deserialized form
- * (assuming that class definitions are present in the classpath).
- * <p>
- * <b>NOTE:</b> user does not need to (and should not) implement this interface directly.
- * <p>
- * To work with the portable format directly, user should create a cache projection
- * over {@code PortableObject} class and then retrieve individual fields as needed:
- * <pre name=code class=java>
- * IgniteCache<PortableObject, PortableObject> prj = cache.withKeepPortable();
- *
- * // Convert instance of MyKey to portable format.
- * // We could also use GridPortableBuilder to create the key in portable format directly.
- * PortableObject key = grid.portables().toPortable(new MyKey());
- *
- * PortableObject val = prj.get(key);
- *
- * String field = val.field("myFieldName");
- * </pre>
- * Alternatively, if we have class definitions in the classpath, we may choose to work with deserialized
- * typed objects at all times. In this case we do incur the deserialization cost. However, if
- * {@link PortableMarshaller#isKeepDeserialized()} is {@code true} then Ignite will only deserialize on the first access
- * and will cache the deserialized object, so it does not have to be deserialized again:
- * <pre name=code class=java>
- * IgniteCache<MyKey.class, MyValue.class> cache = grid.cache(null);
- *
- * MyValue val = cache.get(new MyKey());
- *
- * // Normal java getter.
- * String fieldVal = val.getMyFieldName();
- * </pre>
- * <h1 class="header">Working With Maps and Collections</h1>
- * All maps and collections in the portable objects are serialized automatically. When working
- * with different platforms, e.g. C++ or .NET, Ignite will automatically pick the most
- * adequate collection or map in either language. For example, {@link ArrayList} in Java will become
- * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap}
- * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary}
- * in C#, etc.
- * <h1 class="header">Dynamic Structure Changes</h1>
- * Since objects are always cached in the portable binary format, server does not need to
- * be aware of the class definitions. Moreover, if class definitions are not present or not
- * used on the server, then clients can continuously change the structure of the portable
- * objects without having to restart the cluster. For example, if one client stores a
- * certain class with fields A and B, and another client stores the same class with
- * fields B and C, then the server-side portable object will have the fields A, B, and C.
- * As the structure of a portable object changes, the new fields become available for SQL queries
- * automatically.
- * <h1 class="header">Building Portable Objects</h1>
- * Ignite comes with {@link PortableBuilder} which allows to build portable objects dynamically:
- * <pre name=code class=java>
- * PortableBuilder builder = Ignition.ignite().portables().builder("org.project.MyObject");
- *
- * builder.setField("fieldA", "A");
- * builder.setField("fieldB", "B");
- *
- * PortableObject portableObj = builder.build();
- * </pre>
- * For the cases when class definition is present
- * in the class path, it is also possible to populate a standard POJO and then
- * convert it to portable format, like so:
- * <pre name=code class=java>
- * MyObject obj = new MyObject();
- *
- * obj.setFieldA("A");
- * obj.setFieldB(123);
- *
- * PortableObject portableObj = Ignition.ignite().portables().toPortable(obj);
- * </pre>
- * <h1 class="header">Portable Metadata</h1>
- * Even though Ignite portable protocol only works with hash codes for type and field names
- * to achieve better performance, Ignite provides metadata for all portable types which
- * can be queried ar runtime via any of the {@link IgnitePortables#metadata(Class)}
- * methods. Having metadata also allows for proper formatting of {@code PortableObject.toString()} method,
- * even when portable objects are kept in binary format only, which may be necessary for audit reasons.
- */
-public interface PortableObject extends Serializable, Cloneable {
- /**
- * Gets portable object type ID.
- *
- * @return Type ID.
- */
- public int typeId();
-
- /**
- * Gets meta data for this portable object.
- *
- * @return Meta data.
- * @throws PortableException In case of error.
- */
- @Nullable public PortableMetadata metaData() throws PortableException;
-
- /**
- * Gets field value.
- *
- * @param fieldName Field name.
- * @return Field value.
- * @throws PortableException In case of any other error.
- */
- @Nullable public <F> F field(String fieldName) throws PortableException;
-
- /**
- * Checks whether field is set.
- *
- * @param fieldName Field name.
- * @return {@code true} if field is set.
- */
- public boolean hasField(String fieldName);
-
- /**
- * Gets fully deserialized instance of portable object.
- *
- * @return Fully deserialized instance of portable object.
- * @throws PortableInvalidClassException If class doesn't exist.
- * @throws PortableException In case of any other error.
- */
- @Nullable public <T> T deserialize() throws PortableException;
-
- /**
- * Copies this portable object.
- *
- * @return Copy of this portable object.
- */
- public PortableObject clone() throws CloneNotSupportedException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableProtocolVersion.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableProtocolVersion.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableProtocolVersion.java
deleted file mode 100644
index 741c2a5..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableProtocolVersion.java
+++ /dev/null
@@ -1,41 +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.api;
-
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Portable protocol version.
- */
-public enum PortableProtocolVersion {
- /** Ignite 1.4.0 release. */
- VER_1_4_0;
-
- /** Enumerated values. */
- private static final PortableProtocolVersion[] VALS = values();
-
- /**
- * Efficiently gets enumerated value from its ordinal.
- *
- * @param ord Ordinal value.
- * @return Enumerated value or {@code null} if ordinal out of range.
- */
- @Nullable public static PortableProtocolVersion fromOrdinal(int ord) {
- return ord >= 0 && ord < VALS.length ? VALS[ord] : null;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableRawReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableRawReader.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableRawReader.java
deleted file mode 100644
index c12aa1a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableRawReader.java
+++ /dev/null
@@ -1,234 +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.api;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Raw reader for portable objects. Raw reader does not use field name hash codes, therefore,
- * making the format even more compact. However, if the raw reader is used,
- * dynamic structure changes to the portable objects are not supported.
- */
-public interface PortableRawReader {
- /**
- * @return Byte value.
- * @throws PortableException In case of error.
- */
- public byte readByte() throws PortableException;
-
- /**
- * @return Short value.
- * @throws PortableException In case of error.
- */
- public short readShort() throws PortableException;
-
- /**
- * @return Integer value.
- * @throws PortableException In case of error.
- */
- public int readInt() throws PortableException;
-
- /**
- * @return Long value.
- * @throws PortableException In case of error.
- */
- public long readLong() throws PortableException;
-
- /**
- * @return Float value.
- * @throws PortableException In case of error.
- */
- public float readFloat() throws PortableException;
-
- /**
- * @return Double value.
- * @throws PortableException In case of error.
- */
- public double readDouble() throws PortableException;
-
- /**
- * @return Char value.
- * @throws PortableException In case of error.
- */
- public char readChar() throws PortableException;
-
- /**
- * @return Boolean value.
- * @throws PortableException In case of error.
- */
- public boolean readBoolean() throws PortableException;
-
- /**
- * @return Decimal value.
- * @throws PortableException In case of error.
- */
- @Nullable public BigDecimal readDecimal() throws PortableException;
-
- /**
- * @return String value.
- * @throws PortableException In case of error.
- */
- @Nullable public String readString() throws PortableException;
-
- /**
- * @return UUID.
- * @throws PortableException In case of error.
- */
- @Nullable public UUID readUuid() throws PortableException;
-
- /**
- * @return Date.
- * @throws PortableException In case of error.
- */
- @Nullable public Date readDate() throws PortableException;
-
- /**
- * @return Timestamp.
- * @throws PortableException In case of error.
- */
- @Nullable public Timestamp readTimestamp() throws PortableException;
-
- /**
- * @return Object.
- * @throws PortableException In case of error.
- */
- @Nullable public <T> T readObject() throws PortableException;
-
- /**
- * @return Byte array.
- * @throws PortableException In case of error.
- */
- @Nullable public byte[] readByteArray() throws PortableException;
-
- /**
- * @return Short array.
- * @throws PortableException In case of error.
- */
- @Nullable public short[] readShortArray() throws PortableException;
-
- /**
- * @return Integer array.
- * @throws PortableException In case of error.
- */
- @Nullable public int[] readIntArray() throws PortableException;
-
- /**
- * @return Long array.
- * @throws PortableException In case of error.
- */
- @Nullable public long[] readLongArray() throws PortableException;
-
- /**
- * @return Float array.
- * @throws PortableException In case of error.
- */
- @Nullable public float[] readFloatArray() throws PortableException;
-
- /**
- * @return Byte array.
- * @throws PortableException In case of error.
- */
- @Nullable public double[] readDoubleArray() throws PortableException;
-
- /**
- * @return Char array.
- * @throws PortableException In case of error.
- */
- @Nullable public char[] readCharArray() throws PortableException;
-
- /**
- * @return Boolean array.
- * @throws PortableException In case of error.
- */
- @Nullable public boolean[] readBooleanArray() throws PortableException;
-
- /**
- * @return Decimal array.
- * @throws PortableException In case of error.
- */
- @Nullable public BigDecimal[] readDecimalArray() throws PortableException;
-
- /**
- * @return String array.
- * @throws PortableException In case of error.
- */
- @Nullable public String[] readStringArray() throws PortableException;
-
- /**
- * @return UUID array.
- * @throws PortableException In case of error.
- */
- @Nullable public UUID[] readUuidArray() throws PortableException;
-
- /**
- * @return Date array.
- * @throws PortableException In case of error.
- */
- @Nullable public Date[] readDateArray() throws PortableException;
-
- /**
- * @return Object array.
- * @throws PortableException In case of error.
- */
- @Nullable public Object[] readObjectArray() throws PortableException;
-
- /**
- * @return Collection.
- * @throws PortableException In case of error.
- */
- @Nullable public <T> Collection<T> readCollection() throws PortableException;
-
- /**
- * @param colCls Collection class.
- * @return Collection.
- * @throws PortableException In case of error.
- */
- @Nullable public <T> Collection<T> readCollection(Class<? extends Collection<T>> colCls)
- throws PortableException;
-
- /**
- * @return Map.
- * @throws PortableException In case of error.
- */
- @Nullable public <K, V> Map<K, V> readMap() throws PortableException;
-
- /**
- * @param mapCls Map class.
- * @return Map.
- * @throws PortableException In case of error.
- */
- @Nullable public <K, V> Map<K, V> readMap(Class<? extends Map<K, V>> mapCls) throws PortableException;
-
- /**
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable public <T extends Enum<?>> T readEnum() throws PortableException;
-
- /**
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable public <T extends Enum<?>> T[] readEnumArray() throws PortableException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableRawWriter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableRawWriter.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableRawWriter.java
deleted file mode 100644
index 91f0e3b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableRawWriter.java
+++ /dev/null
@@ -1,219 +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.api;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Raw writer for portable object. Raw writer does not write field name hash codes, therefore,
- * making the format even more compact. However, if the raw writer is used,
- * dynamic structure changes to the portable objects are not supported.
- */
-public interface PortableRawWriter {
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeByte(byte val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeShort(short val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeInt(int val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeLong(long val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeFloat(float val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDouble(double val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeChar(char val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeBoolean(boolean val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDecimal(@Nullable BigDecimal val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeString(@Nullable String val) throws PortableException;
-
- /**
- * @param val UUID to write.
- * @throws PortableException In case of error.
- */
- public void writeUuid(@Nullable UUID val) throws PortableException;
-
- /**
- * @param val Date to write.
- * @throws PortableException In case of error.
- */
- public void writeDate(@Nullable Date val) throws PortableException;
-
- /**
- * @param val Timestamp to write.
- * @throws PortableException In case of error.
- */
- public void writeTimestamp(@Nullable Timestamp val) throws PortableException;
-
- /**
- * @param obj Value to write.
- * @throws PortableException In case of error.
- */
- public void writeObject(@Nullable Object obj) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeByteArray(@Nullable byte[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeShortArray(@Nullable short[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeIntArray(@Nullable int[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeLongArray(@Nullable long[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeFloatArray(@Nullable float[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDoubleArray(@Nullable double[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeCharArray(@Nullable char[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeBooleanArray(@Nullable boolean[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDecimalArray(@Nullable BigDecimal[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeStringArray(@Nullable String[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeUuidArray(@Nullable UUID[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDateArray(@Nullable Date[] val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeObjectArray(@Nullable Object[] val) throws PortableException;
-
- /**
- * @param col Collection to write.
- * @throws PortableException In case of error.
- */
- public <T> void writeCollection(@Nullable Collection<T> col) throws PortableException;
-
- /**
- * @param map Map to write.
- * @throws PortableException In case of error.
- */
- public <K, V> void writeMap(@Nullable Map<K, V> map) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public <T extends Enum<?>> void writeEnum(T val) throws PortableException;
-
- /**
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public <T extends Enum<?>> void writeEnumArray(T[] val) throws PortableException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableReader.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableReader.java
deleted file mode 100644
index ca322e7..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableReader.java
+++ /dev/null
@@ -1,284 +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.api;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Reader for portable objects used in {@link PortableMarshalAware} implementations.
- * Useful for the cases when user wants a fine-grained control over serialization.
- * <p>
- * Note that Ignite never writes full strings for field or type names. Instead,
- * for performance reasons, Ignite writes integer hash codes for type and field names.
- * It has been tested that hash code conflicts for the type names or the field names
- * within the same type are virtually non-existent and, to gain performance, it is safe
- * to work with hash codes. For the cases when hash codes for different types or fields
- * actually do collide, Ignite provides {@link PortableIdMapper} which
- * allows to override the automatically generated hash code IDs for the type and field names.
- */
-public interface PortableReader {
- /**
- * @param fieldName Field name.
- * @return Byte value.
- * @throws PortableException In case of error.
- */
- public byte readByte(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Short value.
- * @throws PortableException In case of error.
- */
- public short readShort(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Integer value.
- * @throws PortableException In case of error.
- */
- public int readInt(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Long value.
- * @throws PortableException In case of error.
- */
- public long readLong(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @throws PortableException In case of error.
- * @return Float value.
- */
- public float readFloat(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Double value.
- * @throws PortableException In case of error.
- */
- public double readDouble(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Char value.
- * @throws PortableException In case of error.
- */
- public char readChar(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Boolean value.
- * @throws PortableException In case of error.
- */
- public boolean readBoolean(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Decimal value.
- * @throws PortableException In case of error.
- */
- @Nullable public BigDecimal readDecimal(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return String value.
- * @throws PortableException In case of error.
- */
- @Nullable public String readString(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return UUID.
- * @throws PortableException In case of error.
- */
- @Nullable public UUID readUuid(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Date.
- * @throws PortableException In case of error.
- */
- @Nullable public Date readDate(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Timestamp.
- * @throws PortableException In case of error.
- */
- @Nullable public Timestamp readTimestamp(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Object.
- * @throws PortableException In case of error.
- */
- @Nullable public <T> T readObject(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Byte array.
- * @throws PortableException In case of error.
- */
- @Nullable public byte[] readByteArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Short array.
- * @throws PortableException In case of error.
- */
- @Nullable public short[] readShortArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Integer array.
- * @throws PortableException In case of error.
- */
- @Nullable public int[] readIntArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Long array.
- * @throws PortableException In case of error.
- */
- @Nullable public long[] readLongArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Float array.
- * @throws PortableException In case of error.
- */
- @Nullable public float[] readFloatArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Byte array.
- * @throws PortableException In case of error.
- */
- @Nullable public double[] readDoubleArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Char array.
- * @throws PortableException In case of error.
- */
- @Nullable public char[] readCharArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Boolean array.
- * @throws PortableException In case of error.
- */
- @Nullable public boolean[] readBooleanArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Decimal array.
- * @throws PortableException In case of error.
- */
- @Nullable public BigDecimal[] readDecimalArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return String array.
- * @throws PortableException In case of error.
- */
- @Nullable public String[] readStringArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return UUID array.
- * @throws PortableException In case of error.
- */
- @Nullable public UUID[] readUuidArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Date array.
- * @throws PortableException In case of error.
- */
- @Nullable public Date[] readDateArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Object array.
- * @throws PortableException In case of error.
- */
- @Nullable public Object[] readObjectArray(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Collection.
- * @throws PortableException In case of error.
- */
- @Nullable public <T> Collection<T> readCollection(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param colCls Collection class.
- * @return Collection.
- * @throws PortableException In case of error.
- */
- @Nullable public <T> Collection<T> readCollection(String fieldName, Class<? extends Collection<T>> colCls)
- throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Map.
- * @throws PortableException In case of error.
- */
- @Nullable public <K, V> Map<K, V> readMap(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param mapCls Map class.
- * @return Map.
- * @throws PortableException In case of error.
- */
- @Nullable public <K, V> Map<K, V> readMap(String fieldName, Class<? extends Map<K, V>> mapCls)
- throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable public <T extends Enum<?>> T readEnum(String fieldName) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @return Value.
- * @throws PortableException In case of error.
- */
- @Nullable public <T extends Enum<?>> T[] readEnumArray(String fieldName) throws PortableException;
-
- /**
- * Gets raw reader. Raw reader does not use field name hash codes, therefore,
- * making the format even more compact. However, if the raw reader is used,
- * dynamic structure changes to the portable objects are not supported.
- *
- * @return Raw reader.
- */
- public PortableRawReader rawReader();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableSerializer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableSerializer.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableSerializer.java
deleted file mode 100644
index b9e835f..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableSerializer.java
+++ /dev/null
@@ -1,47 +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.api;
-
-/**
- * Interface that allows to implement custom serialization logic for portable objects.
- * Can be used instead of {@link PortableMarshalAware} in case if the class
- * cannot be changed directly.
- * <p>
- * Portable serializer can be configured for all portable objects via
- * {@link PortableMarshaller#getSerializer()} method, or for a specific
- * portable type via {@link PortableTypeConfiguration#getSerializer()} method.
- */
-public interface PortableSerializer {
- /**
- * Writes fields to provided writer.
- *
- * @param obj Empty object.
- * @param writer Portable object writer.
- * @throws PortableException In case of error.
- */
- public void writePortable(Object obj, PortableWriter writer) throws PortableException;
-
- /**
- * Reads fields from provided reader.
- *
- * @param obj Empty object
- * @param reader Portable object reader.
- * @throws PortableException In case of error.
- */
- public void readPortable(Object obj, PortableReader reader) throws PortableException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableTypeConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableTypeConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableTypeConfiguration.java
deleted file mode 100644
index 80a043e..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableTypeConfiguration.java
+++ /dev/null
@@ -1,195 +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.api;
-
-import java.sql.Timestamp;
-import java.util.Collection;
-import org.apache.ignite.internal.util.typedef.internal.S;
-
-/**
- * Defines configuration properties for a specific portable type. Providing per-type
- * configuration is optional, as it is generally enough, and also optional, to provide global portable
- * configuration using {@link PortableMarshaller#setClassNames(Collection)}.
- * However, this class allows you to change configuration properties for a specific
- * portable type without affecting configuration for other portable types.
- * <p>
- * Per-type portable configuration can be specified in {@link PortableMarshaller#getTypeConfigurations()} method.
- */
-public class PortableTypeConfiguration {
- /** Class name. */
- private String clsName;
-
- /** ID mapper. */
- private PortableIdMapper idMapper;
-
- /** Serializer. */
- private PortableSerializer serializer;
-
- /** Use timestamp flag. */
- private Boolean useTs;
-
- /** Meta data enabled flag. */
- private Boolean metaDataEnabled;
-
- /** Keep deserialized flag. */
- private Boolean keepDeserialized;
-
- /** Affinity key field name. */
- private String affKeyFieldName;
-
- /**
- */
- public PortableTypeConfiguration() {
- // No-op.
- }
-
- /**
- * @param clsName Class name.
- */
- public PortableTypeConfiguration(String clsName) {
- this.clsName = clsName;
- }
-
- /**
- * Gets type name.
- *
- * @return Type name.
- */
- public String getClassName() {
- return clsName;
- }
-
- /**
- * Sets type name.
- *
- * @param clsName Type name.
- */
- public void setClassName(String clsName) {
- this.clsName = clsName;
- }
-
- /**
- * Gets ID mapper.
- *
- * @return ID mapper.
- */
- public PortableIdMapper getIdMapper() {
- return idMapper;
- }
-
- /**
- * Sets ID mapper.
- *
- * @param idMapper ID mapper.
- */
- public void setIdMapper(PortableIdMapper idMapper) {
- this.idMapper = idMapper;
- }
-
- /**
- * Gets serializer.
- *
- * @return Serializer.
- */
- public PortableSerializer getSerializer() {
- return serializer;
- }
-
- /**
- * Sets serializer.
- *
- * @param serializer Serializer.
- */
- public void setSerializer(PortableSerializer serializer) {
- this.serializer = serializer;
- }
-
- /**
- * If {@code true} then date values converted to {@link Timestamp} during unmarshalling.
- *
- * @return Flag indicating whether date values converted to {@link Timestamp} during unmarshalling.
- */
- public Boolean isUseTimestamp() {
- return useTs;
- }
-
- /**
- * @param useTs Flag indicating whether date values converted to {@link Timestamp} during unmarshalling.
- */
- public void setUseTimestamp(Boolean useTs) {
- this.useTs = useTs;
- }
-
- /**
- * Defines whether meta data is collected for this type. If provided, this value will override
- * {@link PortableMarshaller#isMetaDataEnabled()} property.
- *
- * @return Whether meta data is collected.
- */
- public Boolean isMetaDataEnabled() {
- return metaDataEnabled;
- }
-
- /**
- * @param metaDataEnabled Whether meta data is collected.
- */
- public void setMetaDataEnabled(Boolean metaDataEnabled) {
- this.metaDataEnabled = metaDataEnabled;
- }
-
- /**
- * Defines whether {@link PortableObject} should cache deserialized instance. If provided,
- * this value will override {@link PortableMarshaller#isKeepDeserialized()}
- * property.
- *
- * @return Whether deserialized value is kept.
- */
- public Boolean isKeepDeserialized() {
- return keepDeserialized;
- }
-
- /**
- * @param keepDeserialized Whether deserialized value is kept.
- */
- public void setKeepDeserialized(Boolean keepDeserialized) {
- this.keepDeserialized = keepDeserialized;
- }
-
- /**
- * Gets affinity key field name.
- *
- * @return Affinity key field name.
- */
- public String getAffinityKeyFieldName() {
- return affKeyFieldName;
- }
-
- /**
- * Sets affinity key field name.
- *
- * @param affKeyFieldName Affinity key field name.
- */
- public void setAffinityKeyFieldName(String affKeyFieldName) {
- this.affKeyFieldName = affKeyFieldName;
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(PortableTypeConfiguration.class, this, super.toString());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableWriter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableWriter.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableWriter.java
deleted file mode 100644
index 8af04a3..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableWriter.java
+++ /dev/null
@@ -1,266 +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.api;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Writer for portable object used in {@link PortableMarshalAware} implementations.
- * Useful for the cases when user wants a fine-grained control over serialization.
- * <p>
- * Note that Ignite never writes full strings for field or type names. Instead,
- * for performance reasons, Ignite writes integer hash codes for type and field names.
- * It has been tested that hash code conflicts for the type names or the field names
- * within the same type are virtually non-existent and, to gain performance, it is safe
- * to work with hash codes. For the cases when hash codes for different types or fields
- * actually do collide, Ignite provides {@link PortableIdMapper} which
- * allows to override the automatically generated hash code IDs for the type and field names.
- */
-public interface PortableWriter {
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeByte(String fieldName, byte val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeShort(String fieldName, short val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeInt(String fieldName, int val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeLong(String fieldName, long val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeFloat(String fieldName, float val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDouble(String fieldName, double val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeChar(String fieldName, char val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeBoolean(String fieldName, boolean val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeString(String fieldName, @Nullable String val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val UUID to write.
- * @throws PortableException In case of error.
- */
- public void writeUuid(String fieldName, @Nullable UUID val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Date to write.
- * @throws PortableException In case of error.
- */
- public void writeDate(String fieldName, @Nullable Date val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Timestamp to write.
- * @throws PortableException In case of error.
- */
- public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param obj Value to write.
- * @throws PortableException In case of error.
- */
- public void writeObject(String fieldName, @Nullable Object obj) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeByteArray(String fieldName, @Nullable byte[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeShortArray(String fieldName, @Nullable short[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeIntArray(String fieldName, @Nullable int[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeLongArray(String fieldName, @Nullable long[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeFloatArray(String fieldName, @Nullable float[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDoubleArray(String fieldName, @Nullable double[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeCharArray(String fieldName, @Nullable char[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeBooleanArray(String fieldName, @Nullable boolean[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeStringArray(String fieldName, @Nullable String[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeDateArray(String fieldName, @Nullable Date[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public void writeObjectArray(String fieldName, @Nullable Object[] val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param col Collection to write.
- * @throws PortableException In case of error.
- */
- public <T> void writeCollection(String fieldName, @Nullable Collection<T> col) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param map Map to write.
- * @throws PortableException In case of error.
- */
- public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws PortableException;
-
- /**
- * @param fieldName Field name.
- * @param val Value to write.
- * @throws PortableException In case of error.
- */
- public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws PortableException;
-
- /**
- * Gets raw writer. Raw writer does not write field name hash codes, therefore,
- * making the format even more compact. However, if the raw writer is used,
- * dynamic structure changes to the portable objects are not supported.
- *
- * @return Raw writer.
- */
- public PortableRawWriter rawWriter();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java
index 8673b70..1472d56 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.portable.builder;
import org.apache.ignite.internal.portable.GridPortableMarshaller;
import org.apache.ignite.internal.portable.PortableWriterExImpl;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.internal.portable.api.PortableInvalidClassException;
+import org.apache.ignite.portable.PortableInvalidClassException;
/**
*
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
index 96d10a2..b2e4c0d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
@@ -25,13 +25,17 @@ import java.util.Set;
import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
import org.apache.ignite.internal.util.GridArgumentCheck;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.internal.portable.api.PortableBuilder;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableInvalidClassException;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableBuilder;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableInvalidClassException;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
import org.jetbrains.annotations.Nullable;
import org.apache.ignite.internal.portable.*;
+import org.apache.ignite.internal.processors.cache.portable.*;
+import org.apache.ignite.internal.util.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.portable.*;
import static org.apache.ignite.internal.portable.GridPortableMarshaller.CLS_NAME_POS;
import static org.apache.ignite.internal.portable.GridPortableMarshaller.DFLT_HDR_LEN;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
index e93f860..45355d7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
@@ -28,7 +28,7 @@ import org.apache.ignite.internal.portable.PortablePrimitives;
import org.apache.ignite.internal.portable.PortableReaderExImpl;
import org.apache.ignite.internal.portable.PortableUtils;
import org.apache.ignite.internal.portable.PortableWriterExImpl;
-import org.apache.ignite.internal.portable.api.PortableException;
+import org.apache.ignite.portable.PortableException;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
index 6fe8875..2d9c961 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
@@ -21,8 +21,8 @@ import org.apache.ignite.internal.portable.GridPortableMarshaller;
import org.apache.ignite.internal.portable.PortableObjectEx;
import org.apache.ignite.internal.portable.PortableUtils;
import org.apache.ignite.internal.portable.PortableWriterExImpl;
-import org.apache.ignite.internal.portable.api.PortableObject;
import org.apache.ignite.internal.util.*;
+import org.apache.ignite.portable.*;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java
index 15c52e0..d864a6e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java
@@ -20,8 +20,8 @@ package org.apache.ignite.internal.portable.builder;
import org.apache.ignite.internal.portable.GridPortableMarshaller;
import org.apache.ignite.internal.portable.PortableWriterExImpl;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableInvalidClassException;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableInvalidClassException;
/**
*
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java
index 96f4944..1126a3c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.portable.builder;
import org.apache.ignite.internal.portable.GridPortableMarshaller;
import org.apache.ignite.internal.portable.PortableWriterExImpl;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.internal.portable.api.PortableInvalidClassException;
+import org.apache.ignite.portable.PortableInvalidClassException;
/**
*
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java
index 300c4ad..8743fbe 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.portable.builder;
import org.apache.ignite.internal.portable.PortableObjectImpl;
import org.apache.ignite.internal.portable.PortableObjectOffheapImpl;
import org.apache.ignite.internal.portable.PortableWriterExImpl;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableObject;
/**
*
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
index 80f91be..107b02e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
@@ -17,7 +17,7 @@
package org.apache.ignite.internal.portable.streams;
-import org.apache.ignite.internal.portable.api.PortableException;
+import org.apache.ignite.portable.PortableException;
/**
* Portable abstract input stream.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 59bb5f7..75d4c43 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -115,7 +115,7 @@ import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.lifecycle.LifecycleAware;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.marshaller.jdk.JdkMarshaller;
-import org.apache.ignite.internal.portable.api.PortableMarshaller;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
import org.apache.ignite.spi.IgniteNodeValidationResult;
import org.jetbrains.annotations.Nullable;
@@ -1063,6 +1063,12 @@ public class GridCacheProcessor extends GridProcessorAdapter {
CacheConfiguration cfg = cacheCtx.config();
+ // Intentionally compare Boolean references using '!=' below to check if the flag has been explicitly set.
+ if (cfg.isKeepPortableInStore() && cfg.isKeepPortableInStore() != CacheConfiguration.DFLT_KEEP_PORTABLE_IN_STORE
+ && !(ctx.config().getMarshaller() instanceof PortableMarshaller))
+ U.warn(log, "CacheConfiguration.isKeepPortableInStore() configuration property will be ignored because " +
+ "PortableMarshaller is not used");
+
// Start managers.
for (GridCacheManager mgr : F.view(cacheCtx.managers(), F.notContains(dhtExcludes(cacheCtx))))
mgr.start(cacheCtx);
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index cc6c19a..ce0cdd7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -311,6 +311,11 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V
}
/** {@inheritDoc} */
+ @Override public <K1, V1> IgniteCache<K1, V1> withKeepPortable() {
+ return keepPortable();
+ }
+
+ /** {@inheritDoc} */
@Override public IgniteCache<K, V> withNoRetries() {
GridCacheGateway<K, V> gate = this.gate;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java
index 0dbf71d..23edd9e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java
@@ -21,7 +21,7 @@ import org.apache.ignite.IgniteException;
import org.apache.ignite.internal.IgniteKernal;
import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableObject;
/**
*
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java
index d064601..2e0d37d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java
@@ -27,7 +27,7 @@ import org.apache.ignite.internal.portable.PortableUtils;
import org.apache.ignite.internal.processors.cache.CacheObjectContext;
import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableObject;
/**
*
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessor.java
index 7f6512b..fcd73d2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessor.java
@@ -20,11 +20,11 @@ package org.apache.ignite.internal.processors.cache.portable;
import java.util.Collection;
import java.util.Map;
import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.portable.api.IgnitePortables;
+import org.apache.ignite.IgnitePortables;
import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
-import org.apache.ignite.internal.portable.api.PortableBuilder;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableBuilder;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
import org.jetbrains.annotations.Nullable;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java
index 4cab3db..1be5aea 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableProcessorImpl.java
@@ -39,7 +39,7 @@ import javax.cache.processor.EntryProcessor;
import javax.cache.processor.MutableEntry;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.portable.api.IgnitePortables;
+import org.apache.ignite.IgnitePortables;
import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.CacheConfiguration;
@@ -80,11 +80,11 @@ import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiPredicate;
import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.internal.portable.api.PortableMarshaller;
-import org.apache.ignite.internal.portable.api.PortableBuilder;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableBuilder;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
import org.jetbrains.annotations.Nullable;
import org.jsr166.ConcurrentHashMap8;
import sun.misc.Unsafe;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgnitePortablesImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgnitePortablesImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgnitePortablesImpl.java
index 40c3b70..5ed6505 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgnitePortablesImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgnitePortablesImpl.java
@@ -18,13 +18,13 @@
package org.apache.ignite.internal.processors.cache.portable;
import java.util.Collection;
-import org.apache.ignite.internal.portable.api.IgnitePortables;
+import org.apache.ignite.IgnitePortables;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
-import org.apache.ignite.internal.portable.api.PortableBuilder;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableBuilder;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
import org.jetbrains.annotations.Nullable;
/**
[06/11] ignite git commit: Revert "ignite-1462: hid portable API in
1.4 release" This reverts commit 71379a8061f50f336adc31fa20cd593b659b050f.
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderSelfTest.java
new file mode 100644
index 0000000..7f23c1f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderSelfTest.java
@@ -0,0 +1,1021 @@
+/*
+ * 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;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgnitePortables;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.portable.builder.PortableBuilderImpl;
+import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectAllTypes;
+import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectContainer;
+import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectInner;
+import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectOuter;
+import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectPlainPortable;
+import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableBuilder;
+import org.apache.ignite.portable.PortableIdMapper;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import sun.misc.Unsafe;
+
+/**
+ * Portable builder test.
+ */
+public class GridPortableBuilderSelfTest extends GridCommonAbstractTest {
+ /** */
+ private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+ /** */
+ protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ PortableMarshaller marsh = new PortableMarshaller();
+
+ marsh.setClassNames(Arrays.asList(Key.class.getName(), Value.class.getName(),
+ "org.gridgain.grid.internal.util.portable.mutabletest.*"));
+
+ PortableTypeConfiguration customIdMapper = new PortableTypeConfiguration();
+
+ customIdMapper.setClassName(CustomIdMapper.class.getName());
+ customIdMapper.setIdMapper(new PortableIdMapper() {
+ @Override public int typeId(String clsName) {
+ return ~PortableContext.DFLT_ID_MAPPER.typeId(clsName);
+ }
+
+ @Override public int fieldId(int typeId, String fieldName) {
+ return typeId + ~PortableContext.DFLT_ID_MAPPER.fieldId(typeId, fieldName);
+ }
+ });
+
+ marsh.setTypeConfigurations(Collections.singleton(customIdMapper));
+
+ marsh.setConvertStringToBytes(useUtf8());
+
+ cfg.setMarshaller(marsh);
+
+ return cfg;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGrids(1);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * @return Whether to use UTF8 strings.
+ */
+ protected boolean useUtf8() {
+ return true;
+ }
+
+ /**
+ *
+ */
+ public void testAllFieldsSerialization() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+ obj.setDefaultData();
+ obj.enumArr = null;
+
+ TestObjectAllTypes deserialized = builder(toPortable(obj)).build().deserialize();
+
+ GridTestUtils.deepEquals(obj, deserialized);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testByteField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("byteField", (byte)1);
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals((byte)1, po.<Byte>field("byteField").byteValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testShortField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("shortField", (short)1);
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals((short)1, po.<Short>field("shortField").shortValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testIntField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("intField", 1);
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(1, po.<Integer>field("intField").intValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLongField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("longField", 1L);
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(1L, po.<Long>field("longField").longValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFloatField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("floatField", 1.0f);
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(1.0f, po.<Float>field("floatField").floatValue(), 0);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDoubleField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("doubleField", 1.0d);
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(1.0d, po.<Double>field("doubleField").doubleValue(), 0);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCharField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("charField", (char)1);
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals((char)1, po.<Character>field("charField").charValue());
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBooleanField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("booleanField", true);
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(po.<Boolean>field("booleanField"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDecimalField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("decimalField", BigDecimal.TEN);
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(BigDecimal.TEN, po.<String>field("decimalField"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testStringField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("stringField", "str");
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals("str", po.<String>field("stringField"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testUuidField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ UUID uuid = UUID.randomUUID();
+
+ builder.setField("uuidField", uuid);
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(uuid, po.<UUID>field("uuidField"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testByteArrayField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("byteArrayField", new byte[] {1, 2, 3});
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new byte[] {1, 2, 3}, po.<byte[]>field("byteArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testShortArrayField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("shortArrayField", new short[] {1, 2, 3});
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new short[] {1, 2, 3}, po.<short[]>field("shortArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testIntArrayField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("intArrayField", new int[] {1, 2, 3});
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new int[] {1, 2, 3}, po.<int[]>field("intArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testLongArrayField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("longArrayField", new long[] {1, 2, 3});
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new long[] {1, 2, 3}, po.<long[]>field("longArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testFloatArrayField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("floatArrayField", new float[] {1, 2, 3});
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new float[] {1, 2, 3}, po.<float[]>field("floatArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDoubleArrayField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("doubleArrayField", new double[] {1, 2, 3});
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new double[] {1, 2, 3}, po.<double[]>field("doubleArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCharArrayField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("charArrayField", new char[] {1, 2, 3});
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new char[] {1, 2, 3}, po.<char[]>field("charArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBooleanArrayField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("booleanArrayField", new boolean[] {true, false});
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ boolean[] arr = po.field("booleanArrayField");
+
+ assertEquals(2, arr.length);
+
+ assertTrue(arr[0]);
+ assertFalse(arr[1]);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testDecimalArrayField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("decimalArrayField", new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN});
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN}, po.<String[]>field("decimalArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testStringArrayField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("stringArrayField", new String[] {"str1", "str2", "str3"});
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(new String[] {"str1", "str2", "str3"}, po.<String[]>field("stringArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testUuidArrayField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ UUID[] arr = new UUID[] {UUID.randomUUID(), UUID.randomUUID()};
+
+ builder.setField("uuidArrayField", arr);
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertTrue(Arrays.equals(arr, po.<UUID[]>field("uuidArrayField")));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testObjectField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("objectField", new Value(1));
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(1, po.<PortableObject>field("objectField").<Value>deserialize().i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testObjectArrayField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("objectArrayField", new Value[] {new Value(1), new Value(2)});
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ Object[] arr = po.field("objectArrayField");
+
+ assertEquals(2, arr.length);
+
+ assertEquals(1, ((PortableObject)arr[0]).<Value>deserialize().i);
+ assertEquals(2, ((PortableObject)arr[1]).<Value>deserialize().i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testCollectionField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("collectionField", Arrays.asList(new Value(1), new Value(2)));
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ List<PortableObject> list = po.field("collectionField");
+
+ assertEquals(2, list.size());
+
+ assertEquals(1, list.get(0).<Value>deserialize().i);
+ assertEquals(2, list.get(1).<Value>deserialize().i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMapField() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("mapField", F.asMap(new Key(1), new Value(1), new Key(2), new Value(2)));
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ Map<PortableObject, PortableObject> map = po.field("mapField");
+
+ assertEquals(2, map.size());
+
+ for (Map.Entry<PortableObject, PortableObject> e : map.entrySet())
+ assertEquals(e.getKey().<Key>deserialize().i, e.getValue().<Value>deserialize().i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testSeveralFields() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("i", 111);
+ builder.setField("f", 111.111f);
+ builder.setField("iArr", new int[] {1, 2, 3});
+ builder.setField("obj", new Key(1));
+ builder.setField("col", Arrays.asList(new Value(1), new Value(2)));
+
+ PortableObject po = builder.build();
+
+ assertEquals("class".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(111, po.<Integer>field("i").intValue());
+ assertEquals(111.111f, po.<Float>field("f").floatValue(), 0);
+ assertTrue(Arrays.equals(new int[] {1, 2, 3}, po.<int[]>field("iArr")));
+ assertEquals(1, po.<PortableObject>field("obj").<Key>deserialize().i);
+
+ List<PortableObject> list = po.field("col");
+
+ assertEquals(2, list.size());
+
+ assertEquals(1, list.get(0).<Value>deserialize().i);
+ assertEquals(2, list.get(1).<Value>deserialize().i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testOffheapPortable() throws Exception {
+ PortableBuilder builder = builder("Class");
+
+ builder.hashCode(100);
+
+ builder.setField("i", 111);
+ builder.setField("f", 111.111f);
+ builder.setField("iArr", new int[] {1, 2, 3});
+ builder.setField("obj", new Key(1));
+ builder.setField("col", Arrays.asList(new Value(1), new Value(2)));
+
+ PortableObject po = builder.build();
+
+ byte[] arr = ((CacheObjectPortableProcessorImpl)(grid(0)).context().cacheObjects()).marshal(po);
+
+ long ptr = UNSAFE.allocateMemory(arr.length + 5);
+
+ try {
+ long ptr0 = ptr;
+
+ UNSAFE.putBoolean(null, ptr0++, false);
+
+ UNSAFE.putInt(ptr0, arr.length);
+
+ UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr0 + 4, arr.length);
+
+ PortableObject offheapObj = (PortableObject)
+ ((CacheObjectPortableProcessorImpl)(grid(0)).context().cacheObjects()).unmarshal(ptr, false);
+
+ assertEquals(PortableObjectOffheapImpl.class, offheapObj.getClass());
+
+ assertEquals("class".hashCode(), offheapObj.typeId());
+ assertEquals(100, offheapObj.hashCode());
+
+ assertEquals(111, offheapObj.<Integer>field("i").intValue());
+ assertEquals(111.111f, offheapObj.<Float>field("f").floatValue(), 0);
+ assertTrue(Arrays.equals(new int[] {1, 2, 3}, offheapObj.<int[]>field("iArr")));
+ assertEquals(1, offheapObj.<PortableObject>field("obj").<Key>deserialize().i);
+
+ List<PortableObject> list = offheapObj.field("col");
+
+ assertEquals(2, list.size());
+
+ assertEquals(1, list.get(0).<Value>deserialize().i);
+ assertEquals(2, list.get(1).<Value>deserialize().i);
+
+ assertEquals(po, offheapObj);
+ assertEquals(offheapObj, po);
+ }
+ finally {
+ UNSAFE.freeMemory(ptr);
+ }
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testBuildAndDeserialize() throws Exception {
+ PortableBuilder builder = builder(Value.class.getName());
+
+ builder.hashCode(100);
+
+ builder.setField("i", 1);
+
+ PortableObject po = builder.build();
+
+ assertEquals("value".hashCode(), po.typeId());
+ assertEquals(100, po.hashCode());
+
+ assertEquals(1, po.<Value>deserialize().i);
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMetaData2() throws Exception {
+ PortableBuilder builder = builder("org.test.MetaTest2");
+
+ builder.setField("objectField", "a", Object.class);
+
+ PortableObject po = builder.build();
+
+ PortableMetadata meta = po.metaData();
+
+ assertEquals("MetaTest2", meta.typeName());
+ assertEquals("Object", meta.fieldTypeName("objectField"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testMetaData() throws Exception {
+ PortableBuilder builder = builder("org.test.MetaTest");
+
+ builder.hashCode(100);
+
+ builder.setField("intField", 1);
+ builder.setField("byteArrayField", new byte[] {1, 2, 3});
+
+ PortableObject po = builder.build();
+
+ PortableMetadata meta = po.metaData();
+
+ assertEquals("MetaTest", meta.typeName());
+
+ Collection<String> fields = meta.fields();
+
+ assertEquals(2, fields.size());
+
+ assertTrue(fields.contains("intField"));
+ assertTrue(fields.contains("byteArrayField"));
+
+ assertEquals("int", meta.fieldTypeName("intField"));
+ assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
+
+ builder = builder("org.test.MetaTest");
+
+ builder.hashCode(100);
+
+ builder.setField("intField", 2);
+ builder.setField("uuidField", UUID.randomUUID());
+
+ po = builder.build();
+
+ meta = po.metaData();
+
+ assertEquals("MetaTest", meta.typeName());
+
+ fields = meta.fields();
+
+ assertEquals(3, fields.size());
+
+ assertTrue(fields.contains("intField"));
+ assertTrue(fields.contains("byteArrayField"));
+ assertTrue(fields.contains("uuidField"));
+
+ assertEquals("int", meta.fieldTypeName("intField"));
+ assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
+ assertEquals("UUID", meta.fieldTypeName("uuidField"));
+ }
+
+ /**
+ *
+ */
+ public void testGetFromCopiedObj() {
+ PortableObject objStr = builder(TestObjectAllTypes.class.getName()).setField("str", "aaa").build();
+
+ PortableBuilderImpl builder = builder(objStr);
+ assertEquals("aaa", builder.getField("str"));
+
+ builder.setField("str", "bbb");
+ assertEquals("bbb", builder.getField("str"));
+
+ assertNull(builder.getField("i_"));
+ assertEquals("bbb", builder.build().<TestObjectAllTypes>deserialize().str);
+ }
+
+ /**
+ *
+ */
+ public void testCopyFromInnerObjects() {
+ ArrayList<Object> list = new ArrayList<>();
+ list.add(new TestObjectAllTypes());
+ list.add(list.get(0));
+
+ TestObjectContainer c = new TestObjectContainer(list);
+
+ PortableBuilderImpl builder = builder(toPortable(c));
+ builder.<List>getField("foo").add("!!!");
+
+ PortableObject res = builder.build();
+
+ TestObjectContainer deserialized = res.deserialize();
+
+ List deserializedList = (List)deserialized.foo;
+
+ assertSame(deserializedList.get(0), deserializedList.get(1));
+ assertEquals("!!!", deserializedList.get(2));
+ assertTrue(deserializedList.get(0) instanceof TestObjectAllTypes);
+ }
+
+ /**
+ *
+ */
+ public void testSetPortableObject() {
+ PortableObject portableObj = builder(TestObjectContainer.class.getName())
+ .setField("foo", toPortable(new TestObjectAllTypes()))
+ .build();
+
+ assertTrue(portableObj.<TestObjectContainer>deserialize().foo instanceof TestObjectAllTypes);
+ }
+
+ /**
+ *
+ */
+ public void testPlainPortableObjectCopyFrom() {
+ TestObjectPlainPortable obj = new TestObjectPlainPortable(toPortable(new TestObjectAllTypes()));
+
+ PortableBuilderImpl builder = builder(toPortable(obj));
+ assertTrue(builder.getField("plainPortable") instanceof PortableObject);
+
+ TestObjectPlainPortable deserialized = builder.build().deserialize();
+ assertTrue(deserialized.plainPortable instanceof PortableObject);
+ }
+
+ /**
+ *
+ */
+ public void testRemoveFromNewObject() {
+ PortableBuilder builder = builder(TestObjectAllTypes.class.getName());
+
+ builder.setField("str", "a");
+
+ builder.removeField("str");
+
+ assertNull(builder.build().<TestObjectAllTypes>deserialize().str);
+ }
+
+ /**
+ *
+ */
+ public void testRemoveFromExistingObject() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+ obj.setDefaultData();
+ obj.enumArr = null;
+
+ PortableBuilder builder = builder(toPortable(obj));
+
+ builder.removeField("str");
+
+ assertNull(builder.build().<TestObjectAllTypes>deserialize().str);
+ }
+
+ /**
+ *
+ */
+ public void testRemoveFromExistingObjectAfterGet() {
+ TestObjectAllTypes obj = new TestObjectAllTypes();
+ obj.setDefaultData();
+ obj.enumArr = null;
+
+ PortableBuilderImpl builder = builder(toPortable(obj));
+
+ builder.getField("i_");
+
+ builder.removeField("str");
+
+ assertNull(builder.build().<TestObjectAllTypes>deserialize().str);
+ }
+
+ /**
+ * @throws IgniteCheckedException If any error occurs.
+ */
+ public void testDontBrokeCyclicDependency() throws IgniteCheckedException {
+ TestObjectOuter outer = new TestObjectOuter();
+ outer.inner = new TestObjectInner();
+ outer.inner.outer = outer;
+ outer.foo = "a";
+
+ PortableBuilder builder = builder(toPortable(outer));
+
+ builder.setField("foo", "b");
+
+ TestObjectOuter res = builder.build().deserialize();
+
+ assertEquals("b", res.foo);
+ assertSame(res, res.inner.outer);
+ }
+
+ /**
+ * @return Portables.
+ */
+ private IgnitePortables portables() {
+ return grid(0).portables();
+ }
+
+ /**
+ * @param obj Object.
+ * @return Portable object.
+ */
+ private PortableObject toPortable(Object obj) {
+ return portables().toPortable(obj);
+ }
+
+ /**
+ * @return Builder.
+ */
+ private <T> PortableBuilder builder(int typeId) {
+ return portables().builder(typeId);
+ }
+
+ /**
+ * @return Builder.
+ */
+ private <T> PortableBuilder builder(String clsName) {
+ return portables().builder(clsName);
+ }
+
+ /**
+ * @return Builder.
+ */
+ private <T> PortableBuilderImpl builder(PortableObject obj) {
+ return (PortableBuilderImpl)portables().builder(obj);
+ }
+
+ /**
+ *
+ */
+ private static class CustomIdMapper {
+ /** */
+ private String str = "a";
+
+ /** */
+ private int i = 10;
+ }
+
+ /**
+ */
+ private static class Key {
+ /** */
+ private int i;
+
+ /**
+ */
+ private Key() {
+ // No-op.
+ }
+
+ /**
+ * @param i Index.
+ */
+ private Key(int i) {
+ this.i = i;
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ Key key = (Key)o;
+
+ return i == key.i;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int hashCode() {
+ return i;
+ }
+ }
+
+ /**
+ */
+ private static class Value {
+ /** */
+ private int i;
+
+ /**
+ */
+ private Value() {
+ // No-op.
+ }
+
+ /**
+ * @param i Index.
+ */
+ private Value(int i) {
+ this.i = i;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsAdditionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsAdditionalSelfTest.java
new file mode 100644
index 0000000..2fce1a5
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsAdditionalSelfTest.java
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+/**
+ *
+ */
+public class GridPortableBuilderStringAsCharsAdditionalSelfTest extends GridPortableBuilderAdditionalSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean useUtf8() {
+ return false;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsSelfTest.java
new file mode 100644
index 0000000..5c53233
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsSelfTest.java
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+/**
+ * Portable builder test.
+ */
+public class GridPortableBuilderStringAsCharsSelfTest extends GridPortableBuilderSelfTest {
+ /** {@inheritDoc} */
+ @Override protected boolean useUtf8() {
+ return false;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java
new file mode 100644
index 0000000..bd9612c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java
@@ -0,0 +1,256 @@
+/*
+ * 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;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.MarshallerContextAdapter;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMarshalAware;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableReader;
+import org.apache.ignite.portable.PortableWriter;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public class GridPortableMarshallerCtxDisabledSelfTest extends GridCommonAbstractTest {
+ /** */
+ protected static final PortableMetaDataHandler META_HND = new PortableMetaDataHandler() {
+ @Override public void addMeta(int typeId, PortableMetadata meta) {
+ // No-op.
+ }
+
+ @Override public PortableMetadata metadata(int typeId) {
+ return null;
+ }
+ };
+
+ /**
+ * @throws Exception If failed.
+ */
+ public void testObjectExchange() throws Exception {
+ PortableMarshaller marsh = new PortableMarshaller();
+ marsh.setContext(new MarshallerContextWithNoStorage());
+
+ PortableContext context = new PortableContext(META_HND, null);
+
+ IgniteUtils.invoke(PortableMarshaller.class, marsh, "setPortableContext", context);
+
+ SimpleObject simpleObj = new SimpleObject();
+
+ simpleObj.b = 2;
+ simpleObj.bArr = new byte[] {2, 3, 4, 5, 5};
+ simpleObj.c = 'A';
+ simpleObj.enumVal = TestEnum.D;
+ simpleObj.objArr = new Object[] {"hello", "world", "from", "me"};
+ simpleObj.enumArr = new TestEnum[] {TestEnum.C, TestEnum.B};
+
+ SimpleObject otherObj = new SimpleObject();
+
+ otherObj.b = 3;
+ otherObj.bArr = new byte[] {5, 3, 4};
+
+ simpleObj.otherObj = otherObj;
+
+ assertEquals(simpleObj, marsh.unmarshal(marsh.marshal(simpleObj), null));
+
+ SimplePortable simplePortable = new SimplePortable();
+
+ simplePortable.str = "portable";
+ simplePortable.arr = new long[] {100, 200, 300};
+
+ assertEquals(simplePortable, marsh.unmarshal(marsh.marshal(simplePortable), null));
+
+ SimpleExternalizable simpleExtr = new SimpleExternalizable();
+
+ simpleExtr.str = "externalizable";
+ simpleExtr.arr = new long[] {20000, 300000, 400000};
+
+ assertEquals(simpleExtr, marsh.unmarshal(marsh.marshal(simpleExtr), null));
+ }
+
+ /**
+ * Marshaller context with no storage. Platform has to work in such environment as well by marshalling class name of
+ * a portable object.
+ */
+ private static class MarshallerContextWithNoStorage extends MarshallerContextAdapter {
+ /** */
+ public MarshallerContextWithNoStorage() {
+ super(null);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected boolean registerClassName(int id, String clsName) throws IgniteCheckedException {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected String className(int id) throws IgniteCheckedException {
+ return null;
+ }
+ }
+
+ /**
+ */
+ private enum TestEnum {
+ A, B, C, D, E
+ }
+
+ /**
+ */
+ private static class SimpleObject {
+ /** */
+ private byte b;
+
+ /** */
+ private char c;
+
+ /** */
+ private byte[] bArr;
+
+ /** */
+ private Object[] objArr;
+
+ /** */
+ private TestEnum enumVal;
+
+ /** */
+ private TestEnum[] enumArr;
+
+ private SimpleObject otherObj;
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ SimpleObject object = (SimpleObject)o;
+
+ if (b != object.b)
+ return false;
+
+ if (c != object.c)
+ return false;
+
+ if (!Arrays.equals(bArr, object.bArr))
+ return false;
+
+ // Probably incorrect - comparing Object[] arrays with Arrays.equals
+ if (!Arrays.equals(objArr, object.objArr))
+ return false;
+
+ if (enumVal != object.enumVal)
+ return false;
+
+ // Probably incorrect - comparing Object[] arrays with Arrays.equals
+ if (!Arrays.equals(enumArr, object.enumArr))
+ return false;
+
+ return !(otherObj != null ? !otherObj.equals(object.otherObj) : object.otherObj != null);
+ }
+ }
+
+ /**
+ *
+ */
+ private static class SimplePortable implements PortableMarshalAware {
+ /** */
+ private String str;
+
+ /** */
+ private long[] arr;
+
+ /** {@inheritDoc} */
+ @Override public void writePortable(PortableWriter writer) throws PortableException {
+ writer.writeString("str", str);
+ writer.writeLongArray("longArr", arr);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readPortable(PortableReader reader) throws PortableException {
+ str = reader.readString("str");
+ arr = reader.readLongArray("longArr");
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ SimplePortable that = (SimplePortable)o;
+
+ if (str != null ? !str.equals(that.str) : that.str != null)
+ return false;
+
+ return Arrays.equals(arr, that.arr);
+ }
+ }
+
+ /**
+ *
+ */
+ private static class SimpleExternalizable implements Externalizable {
+ /** */
+ private String str;
+
+ /** */
+ private long[] arr;
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeUTF(str);
+ out.writeObject(arr);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ str = in.readUTF();
+ arr = (long[])in.readObject();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean equals(Object o) {
+ if (this == o)
+ return true;
+
+ if (o == null || getClass() != o.getClass())
+ return false;
+
+ SimpleExternalizable that = (SimpleExternalizable)o;
+
+ if (str != null ? !str.equals(that.str) : that.str != null)
+ return false;
+
+ return Arrays.equals(arr, that.arr);
+ }
+ }
+}
\ No newline at end of file
[10/11] ignite git commit: Revert "ignite-1462: hid portable API in
1.4 release" This reverts commit 71379a8061f50f336adc31fa20cd593b659b050f.
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java b/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java
new file mode 100644
index 0000000..ee0a4ec
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/IgnitePortables.java
@@ -0,0 +1,370 @@
+/*
+ * 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;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.TreeMap;
+import java.util.UUID;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableBuilder;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableIdMapper;
+import org.apache.ignite.portable.PortableMarshalAware;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.portable.PortableSerializer;
+import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Defines portable objects functionality. With portable objects you are able to:
+ * <ul>
+ * <li>Seamlessly interoperate between Java, .NET, and C++.</li>
+ * <li>Make any object portable with zero code change to your existing code.</li>
+ * <li>Nest portable objects within each other.</li>
+ * <li>Automatically handle {@code circular} or {@code null} references.</li>
+ * <li>Automatically convert collections and maps between Java, .NET, and C++.</li>
+ * <li>
+ * Optionally avoid deserialization of objects on the server side
+ * (objects are stored in {@link PortableObject} format).
+ * </li>
+ * <li>Avoid need to have concrete class definitions on the server side.</li>
+ * <li>Dynamically change structure of the classes without having to restart the cluster.</li>
+ * <li>Index into portable objects for querying purposes.</li>
+ * </ul>
+ * <h1 class="header">Working With Portables Directly</h1>
+ * Once an object is defined as portable,
+ * Ignite will always store it in memory in the portable (i.e. binary) format.
+ * User can choose to work either with the portable format or with the deserialized form
+ * (assuming that class definitions are present in the classpath).
+ * <p>
+ * To work with the portable format directly, user should create a special cache projection
+ * using {@link IgniteCache#withKeepPortable()} method and then retrieve individual fields as needed:
+ * <pre name=code class=java>
+ * IgniteCache<PortableObject, PortableObject> prj = cache.withKeepPortable();
+ *
+ * // Convert instance of MyKey to portable format.
+ * // We could also use PortableBuilder to create the key in portable format directly.
+ * PortableObject key = grid.portables().toPortable(new MyKey());
+ *
+ * PortableObject val = prj.get(key);
+ *
+ * String field = val.field("myFieldName");
+ * </pre>
+ * Alternatively, if we have class definitions in the classpath, we may choose to work with deserialized
+ * typed objects at all times. In this case we do incur the deserialization cost. However, if
+ * {@link PortableMarshaller#isKeepDeserialized()} is {@code true} then Ignite will only deserialize on the first access
+ * and will cache the deserialized object, so it does not have to be deserialized again:
+ * <pre name=code class=java>
+ * IgniteCache<MyKey.class, MyValue.class> cache = grid.cache(null);
+ *
+ * MyValue val = cache.get(new MyKey());
+ *
+ * // Normal java getter.
+ * String fieldVal = val.getMyFieldName();
+ * </pre>
+ * If we used, for example, one of the automatically handled portable types for a key, like integer,
+ * and still wanted to work with binary portable format for values, then we would declare cache projection
+ * as follows:
+ * <pre name=code class=java>
+ * IgniteCache<Integer.class, PortableObject> prj = cache.withKeepPortable();
+ * </pre>
+ * <h1 class="header">Automatic Portable Types</h1>
+ * Note that only portable classes are converted to {@link PortableObject} format. Following
+ * classes are never converted (e.g., {@link #toPortable(Object)} method will return original
+ * object, and instances of these classes will be stored in cache without changes):
+ * <ul>
+ * <li>All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)</li>
+ * <li>Arrays of primitives (byte[], int[], ...)</li>
+ * <li>{@link String} and array of {@link String}s</li>
+ * <li>{@link UUID} and array of {@link UUID}s</li>
+ * <li>{@link Date} and array of {@link Date}s</li>
+ * <li>{@link Timestamp} and array of {@link Timestamp}s</li>
+ * <li>Enums and array of enums</li>
+ * <li>
+ * Maps, collections and array of objects (but objects inside
+ * them will still be converted if they are portable)
+ * </li>
+ * </ul>
+ * <h1 class="header">Working With Maps and Collections</h1>
+ * All maps and collections in the portable objects are serialized automatically. When working
+ * with different platforms, e.g. C++ or .NET, Ignite will automatically pick the most
+ * adequate collection or map in either language. For example, {@link ArrayList} in Java will become
+ * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap}
+ * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary}
+ * in C#, etc.
+ * <h1 class="header">Building Portable Objects</h1>
+ * Ignite comes with {@link PortableBuilder} which allows to build portable objects dynamically:
+ * <pre name=code class=java>
+ * PortableBuilder builder = Ignition.ignite().portables().builder();
+ *
+ * builder.typeId("MyObject");
+ *
+ * builder.stringField("fieldA", "A");
+ * build.intField("fieldB", "B");
+ *
+ * PortableObject portableObj = builder.build();
+ * </pre>
+ * For the cases when class definition is present
+ * in the class path, it is also possible to populate a standard POJO and then
+ * convert it to portable format, like so:
+ * <pre name=code class=java>
+ * MyObject obj = new MyObject();
+ *
+ * obj.setFieldA("A");
+ * obj.setFieldB(123);
+ *
+ * PortableObject portableObj = Ignition.ignite().portables().toPortable(obj);
+ * </pre>
+ * NOTE: you don't need to convert typed objects to portable format before storing
+ * them in cache, Ignite will do that automatically.
+ * <h1 class="header">Portable Metadata</h1>
+ * Even though Ignite portable protocol only works with hash codes for type and field names
+ * to achieve better performance, Ignite provides metadata for all portable types which
+ * can be queried ar runtime via any of the {@link IgnitePortables#metadata(Class)}
+ * methods. Having metadata also allows for proper formatting of {@code PortableObject#toString()} method,
+ * even when portable objects are kept in binary format only, which may be necessary for audit reasons.
+ * <h1 class="header">Dynamic Structure Changes</h1>
+ * Since objects are always cached in the portable binary format, server does not need to
+ * be aware of the class definitions. Moreover, if class definitions are not present or not
+ * used on the server, then clients can continuously change the structure of the portable
+ * objects without having to restart the cluster. For example, if one client stores a
+ * certain class with fields A and B, and another client stores the same class with
+ * fields B and C, then the server-side portable object will have the fields A, B, and C.
+ * As the structure of a portable object changes, the new fields become available for SQL queries
+ * automatically.
+ * <h1 class="header">Configuration</h1>
+ * By default all your objects are considered as portables and no specific configuration is needed.
+ * However, in some cases, like when an object is used by both Java and .Net, you may need to specify portable objects
+ * explicitly by calling {@link PortableMarshaller#setClassNames(Collection)}.
+ * The only requirement Ignite imposes is that your object has an empty
+ * constructor. Note, that since server side does not have to know the class definition,
+ * you only need to list portable objects in configuration on the client side. However, if you
+ * list them on the server side as well, then you get the ability to deserialize portable objects
+ * into concrete types on the server as well as on the client.
+ * <p>
+ * Here is an example of portable configuration (note that star (*) notation is supported):
+ * <pre name=code class=xml>
+ * ...
+ * <!-- Explicit portable objects configuration. -->
+ * <property name="marshaller">
+ * <bean class="org.apache.ignite.marshaller.portable.PortableMarshaller">
+ * <property name="classNames">
+ * <list>
+ * <value>my.package.for.portable.objects.*</value>
+ * <value>org.apache.ignite.examples.client.portable.Employee</value>
+ * </list>
+ * </property>
+ * </bean>
+ * </property>
+ * ...
+ * </pre>
+ * or from code:
+ * <pre name=code class=java>
+ * IgniteConfiguration cfg = new IgniteConfiguration();
+ *
+ * PortableMarshaller marsh = new PortableMarshaller();
+ *
+ * marsh.setClassNames(Arrays.asList(
+ * Employee.class.getName(),
+ * Address.class.getName())
+ * );
+ *
+ * cfg.setMarshaller(marsh);
+ * </pre>
+ * You can also specify class name for a portable object via {@link PortableTypeConfiguration}.
+ * Do it in case if you need to override other configuration properties on per-type level, like
+ * ID-mapper, or serializer.
+ * <h1 class="header">Custom Affinity Keys</h1>
+ * Often you need to specify an alternate key (not the cache key) for affinity routing whenever
+ * storing objects in cache. For example, if you are caching {@code Employee} object with
+ * {@code Organization}, and want to colocate employees with organization they work for,
+ * so you can process them together, you need to specify an alternate affinity key.
+ * With portable objects you would have to do it as following:
+ * <pre name=code class=xml>
+ * <property name="marshaller">
+ * <bean class="org.gridgain.grid.marshaller.portable.PortableMarshaller">
+ * ...
+ * <property name="typeConfigurations">
+ * <list>
+ * <bean class="org.apache.ignite.portable.PortableTypeConfiguration">
+ * <property name="className" value="org.apache.ignite.examples.client.portable.EmployeeKey"/>
+ * <property name="affinityKeyFieldName" value="organizationId"/>
+ * </bean>
+ * </list>
+ * </property>
+ * ...
+ * </bean>
+ * </property>
+ * </pre>
+ * <h1 class="header">Serialization</h1>
+ * Serialization and deserialization works out-of-the-box in Ignite. However, you can provide your own custom
+ * serialization logic by optionally implementing {@link PortableMarshalAware} interface, like so:
+ * <pre name=code class=java>
+ * public class Address implements PortableMarshalAware {
+ * private String street;
+ * private int zip;
+ *
+ * // Empty constructor required for portable deserialization.
+ * public Address() {}
+ *
+ * @Override public void writePortable(PortableWriter writer) throws PortableException {
+ * writer.writeString("street", street);
+ * writer.writeInt("zip", zip);
+ * }
+ *
+ * @Override public void readPortable(PortableReader reader) throws PortableException {
+ * street = reader.readString("street");
+ * zip = reader.readInt("zip");
+ * }
+ * }
+ * </pre>
+ * Alternatively, if you cannot change class definitions, you can provide custom serialization
+ * logic in {@link PortableSerializer} either globally in {@link PortableMarshaller} or
+ * for a specific type via {@link PortableTypeConfiguration} instance.
+ * <p>
+ * Similar to java serialization you can use {@code writeReplace()} and {@code readResolve()} methods.
+ * <ul>
+ * <li>
+ * {@code readResolve} is defined as follows: {@code ANY-ACCESS-MODIFIER Object readResolve()}.
+ * It may be used to replace the de-serialized object by another one of your choice.
+ * </li>
+ * <li>
+ * {@code writeReplace} is defined as follows: {@code ANY-ACCESS-MODIFIER Object writeReplace()}. This method
+ * allows the developer to provide a replacement object that will be serialized instead of the original one.
+ * </li>
+ * </ul>
+ *
+ * <h1 class="header">Custom ID Mappers</h1>
+ * Ignite implementation uses name hash codes to generate IDs for class names or field names
+ * internally. However, in cases when you want to provide your own ID mapping schema,
+ * you can provide your own {@link PortableIdMapper} implementation.
+ * <p>
+ * ID-mapper may be provided either globally in {@link PortableMarshaller},
+ * or for a specific type via {@link PortableTypeConfiguration} instance.
+ * <h1 class="header">Query Indexing</h1>
+ * Portable objects can be indexed for querying by specifying index fields in
+ * {@link org.apache.ignite.cache.CacheTypeMetadata} inside of specific
+ * {@link org.apache.ignite.configuration.CacheConfiguration} instance,
+ * like so:
+ * <pre name=code class=xml>
+ * ...
+ * <bean class="org.apache.ignite.cache.CacheConfiguration">
+ * ...
+ * <property name="typeMetadata">
+ * <list>
+ * <bean class="CacheTypeMetadata">
+ * <property name="type" value="Employee"/>
+ *
+ * <!-- Fields to index in ascending order. -->
+ * <property name="ascendingFields">
+ * <map>
+ * <entry key="name" value="java.lang.String"/>
+ *
+ * <!-- Nested portable objects can also be indexed. -->
+ * <entry key="address.zip" value="java.lang.Integer"/>
+ * </map>
+ * </property>
+ * </bean>
+ * </list>
+ * </property>
+ * </bean>
+ * </pre>
+ */
+public interface IgnitePortables {
+ /**
+ * Gets type ID for given type name.
+ *
+ * @param typeName Type name.
+ * @return Type ID.
+ */
+ public int typeId(String typeName);
+
+ /**
+ * Converts provided object to instance of {@link PortableObject}.
+ *
+ * @param obj Object to convert.
+ * @return Converted object.
+ * @throws PortableException In case of error.
+ */
+ public <T> T toPortable(@Nullable Object obj) throws PortableException;
+
+ /**
+ * Creates new portable builder.
+ *
+ * @param typeId ID of the type.
+ * @return Newly portable builder.
+ */
+ public PortableBuilder builder(int typeId);
+
+ /**
+ * Creates new portable builder.
+ *
+ * @param typeName Type name.
+ * @return Newly portable builder.
+ */
+ public PortableBuilder builder(String typeName);
+
+ /**
+ * Creates portable builder initialized by existing portable object.
+ *
+ * @param portableObj Portable object to initialize builder.
+ * @return Portable builder.
+ */
+ public PortableBuilder builder(PortableObject portableObj);
+
+ /**
+ * Gets metadata for provided class.
+ *
+ * @param cls Class.
+ * @return Metadata.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public PortableMetadata metadata(Class<?> cls) throws PortableException;
+
+ /**
+ * Gets metadata for provided class name.
+ *
+ * @param typeName Type name.
+ * @return Metadata.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public PortableMetadata metadata(String typeName) throws PortableException;
+
+ /**
+ * Gets metadata for provided type ID.
+ *
+ * @param typeId Type ID.
+ * @return Metadata.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public PortableMetadata metadata(int typeId) throws PortableException;
+
+ /**
+ * Gets metadata for all known types.
+ *
+ * @return Metadata.
+ * @throws PortableException In case of error.
+ */
+ public Collection<PortableMetadata> metadata() throws PortableException;
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index 7d1e14d..9fb56bc 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -17,24 +17,10 @@
package org.apache.ignite.configuration;
-import java.io.Serializable;
-import java.util.Collection;
-import javax.cache.Cache;
-import javax.cache.configuration.CompleteConfiguration;
-import javax.cache.configuration.Factory;
-import javax.cache.configuration.MutableConfiguration;
-import javax.cache.expiry.ExpiryPolicy;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CacheAtomicWriteOrderMode;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheEntryProcessor;
-import org.apache.ignite.cache.CacheInterceptor;
-import org.apache.ignite.cache.CacheMemoryMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.CacheRebalanceMode;
-import org.apache.ignite.cache.CacheTypeMetadata;
-import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cache.*;
import org.apache.ignite.cache.affinity.AffinityFunction;
import org.apache.ignite.cache.affinity.AffinityKeyMapper;
import org.apache.ignite.cache.eviction.EvictionFilter;
@@ -50,6 +36,15 @@ import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.plugin.CachePluginConfiguration;
import org.jetbrains.annotations.Nullable;
+import javax.cache.Cache;
+import javax.cache.CacheException;
+import javax.cache.configuration.CompleteConfiguration;
+import javax.cache.configuration.Factory;
+import javax.cache.configuration.MutableConfiguration;
+import javax.cache.expiry.ExpiryPolicy;
+import java.io.Serializable;
+import java.util.Collection;
+
/**
* This class defines grid cache configuration. This configuration is passed to
* grid via {@link IgniteConfiguration#getCacheConfiguration()} method. It defines all configuration
@@ -168,6 +163,10 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
/** Default size for onheap SQL row cache size. */
public static final int DFLT_SQL_ONHEAP_ROW_CACHE_SIZE = 10 * 1024;
+ /** Default value for keep portable in store behavior .*/
+ @SuppressWarnings({"UnnecessaryBoxing", "BooleanConstructorCall"})
+ public static final Boolean DFLT_KEEP_PORTABLE_IN_STORE = new Boolean(true);
+
/** Cache name. */
private String name;
@@ -220,6 +219,9 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
private Factory storeFactory;
/** */
+ private Boolean keepPortableInStore = DFLT_KEEP_PORTABLE_IN_STORE;
+
+ /** */
private boolean loadPrevVal = DFLT_LOAD_PREV_VAL;
/** Node group resolver. */
@@ -381,6 +383,8 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
invalidate = cc.isInvalidate();
isReadThrough = cc.isReadThrough();
isWriteThrough = cc.isWriteThrough();
+ keepPortableInStore = cc.isKeepPortableInStore() != null ? cc.isKeepPortableInStore() :
+ DFLT_KEEP_PORTABLE_IN_STORE;
listenerConfigurations = cc.listenerConfigurations;
loadPrevVal = cc.isLoadPreviousValue();
longQryWarnTimeout = cc.getLongQueryWarningTimeout();
@@ -821,6 +825,38 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
}
/**
+ * Flag indicating that {@link CacheStore} implementation
+ * is working with portable objects instead of Java objects.
+ * Default value of this flag is {@link #DFLT_KEEP_PORTABLE_IN_STORE},
+ * because this is recommended behavior from performance standpoint.
+ * <p>
+ * If set to {@code false}, Ignite will deserialize keys and
+ * values stored in portable format before they are passed
+ * to cache store.
+ * <p>
+ * Note that setting this flag to {@code false} can simplify
+ * store implementation in some cases, but it can cause performance
+ * degradation due to additional serializations and deserializations
+ * of portable objects. You will also need to have key and value
+ * classes on all nodes since portables will be deserialized when
+ * store is called.
+ *
+ * @return Keep portables in store flag.
+ */
+ public Boolean isKeepPortableInStore() {
+ return keepPortableInStore;
+ }
+
+ /**
+ * Sets keep portables in store flag.
+ *
+ * @param keepPortableInStore Keep portables in store flag.
+ */
+ public void setKeepPortableInStore(boolean keepPortableInStore) {
+ this.keepPortableInStore = keepPortableInStore;
+ }
+
+ /**
* Gets key topology resolver to provide mapping from keys to nodes.
*
* @return Key topology resolver to provide mapping from keys to nodes.
@@ -1824,4 +1860,4 @@ public class CacheConfiguration<K, V> extends MutableConfiguration<K, V> {
return obj.getClass().equals(this.getClass());
}
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java
index 9443f21..e3859c5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEx.java
@@ -20,7 +20,6 @@ package org.apache.ignite.internal;
import java.util.Collection;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteFileSystem;
-import org.apache.ignite.internal.portable.api.IgnitePortables;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.internal.cluster.IgniteClusterEx;
import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
@@ -141,12 +140,4 @@ public interface IgniteEx extends Ignite {
* @return Kernal context.
*/
public GridKernalContext context();
-
-
- /**
- * Gets an instance of {@link IgnitePortables} interface.
- *
- * @return Instance of {@link IgnitePortables} interface.
- */
- public IgnitePortables portables();
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index daf7d23..9baf2f1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -64,7 +64,7 @@ import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteFileSystem;
import org.apache.ignite.IgniteLogger;
import org.apache.ignite.IgniteMessaging;
-import org.apache.ignite.internal.portable.api.IgnitePortables;
+import org.apache.ignite.IgnitePortables;
import org.apache.ignite.IgniteQueue;
import org.apache.ignite.IgniteScheduler;
import org.apache.ignite.IgniteServices;
@@ -157,7 +157,7 @@ import org.apache.ignite.lifecycle.LifecycleBean;
import org.apache.ignite.lifecycle.LifecycleEventType;
import org.apache.ignite.marshaller.MarshallerExclusions;
import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
-import org.apache.ignite.internal.portable.api.PortableMarshaller;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
import org.apache.ignite.mxbean.ClusterLocalNodeMetricsMXBean;
import org.apache.ignite.mxbean.IgniteMXBean;
import org.apache.ignite.mxbean.ThreadPoolMXBean;
@@ -203,6 +203,7 @@ import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MARSHALLER;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_NODE_CONSISTENT_ID;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_PEER_CLASSLOADING;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_PHY_RAM;
+import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_PORTABLE_PROTO_VER;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_PREFIX;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_RESTART_ENABLED;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_REST_PORT_RANGE;
@@ -1269,6 +1270,9 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
add(ATTR_MARSHALLER, cfg.getMarshaller().getClass().getName());
add(ATTR_USER_NAME, System.getProperty("user.name"));
add(ATTR_GRID_NAME, gridName);
+ add(ATTR_PORTABLE_PROTO_VER, cfg.getMarshaller() instanceof PortableMarshaller ?
+ ((PortableMarshaller)cfg.getMarshaller()).getProtocolVersion().toString() :
+ PortableMarshaller.DFLT_PORTABLE_PROTO_VER.toString());
add(ATTR_PEER_CLASSLOADING, cfg.isPeerClassLoadingEnabled());
add(ATTR_DEPLOYMENT_MODE, cfg.getDeploymentMode());
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/IgniteNodeAttributes.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteNodeAttributes.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteNodeAttributes.java
index 10b8df0..7be2af3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteNodeAttributes.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteNodeAttributes.java
@@ -135,10 +135,13 @@ public final class IgniteNodeAttributes {
/** Node consistent id. */
public static final String ATTR_NODE_CONSISTENT_ID = ATTR_PREFIX + ".consistent.id";
+ /** Portable protocol version. */
+ public static final String ATTR_PORTABLE_PROTO_VER = ATTR_PREFIX + ".portable.proto.ver";
+
/**
* Enforces singleton.
*/
private IgniteNodeAttributes() {
/* No-op. */
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
index 3a09b2c..bc4f756 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
@@ -125,6 +125,7 @@ import static org.apache.ignite.events.EventType.EVT_NODE_SEGMENTED;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_DEPLOYMENT_MODE;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MACS;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_PEER_CLASSLOADING;
+import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_PORTABLE_PROTO_VER;
import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_USER_NAME;
import static org.apache.ignite.internal.IgniteVersionUtils.VER;
import static org.apache.ignite.plugin.segmentation.SegmentationPolicy.NOOP;
@@ -981,6 +982,8 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi> {
// Fetch local node attributes once.
String locPreferIpV4 = locNode.attribute("java.net.preferIPv4Stack");
+ String locPortableProtoVer = locNode.attribute(ATTR_PORTABLE_PROTO_VER);
+
Object locMode = locNode.attribute(ATTR_DEPLOYMENT_MODE);
int locJvmMajVer = nodeJavaMajorVersion(locNode);
@@ -1030,6 +1033,13 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi> {
", rmtId8=" + U.id8(n.id()) + ", rmtPeerClassLoading=" + rmtP2pEnabled +
", rmtAddrs=" + U.addressesAsString(n) + ']');
}
+
+ String rmtPortableProtoVer = n.attribute(ATTR_PORTABLE_PROTO_VER);
+
+ // In order to support backward compatibility skip the check for nodes that don't have this attribute.
+ if (rmtPortableProtoVer != null && !F.eq(locPortableProtoVer, rmtPortableProtoVer))
+ throw new IgniteCheckedException("Remote node has portable protocol version different from local " +
+ "[locVersion=" + locPortableProtoVer + ", rmtVersion=" + rmtPortableProtoVer + ']');
}
if (log.isDebugEnabled())
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
index 4bc8545..c7a9e6f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
@@ -19,7 +19,7 @@ package org.apache.ignite.internal.portable;
import org.apache.ignite.internal.portable.streams.PortableInputStream;
import org.apache.ignite.internal.portable.streams.PortableOutputStream;
-import org.apache.ignite.internal.portable.api.PortableException;
+import org.apache.ignite.portable.PortableException;
import org.jetbrains.annotations.Nullable;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
index e1b7324..a2b4b74 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
@@ -40,11 +40,11 @@ import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.marshaller.MarshallerExclusions;
import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
-import org.apache.ignite.internal.portable.api.PortableMarshaller;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableIdMapper;
-import org.apache.ignite.internal.portable.api.PortableMarshalAware;
-import org.apache.ignite.internal.portable.api.PortableSerializer;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableIdMapper;
+import org.apache.ignite.portable.PortableMarshalAware;
+import org.apache.ignite.portable.PortableSerializer;
import org.jetbrains.annotations.Nullable;
import static java.lang.reflect.Modifier.isStatic;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
index 2ee96b7..165ad9a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
@@ -60,16 +60,16 @@ import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.marshaller.MarshallerContext;
import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
-import org.apache.ignite.internal.portable.api.PortableMarshaller;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
import org.apache.ignite.internal.processors.platform.dotnet.PlatformDotNetConfiguration;
import org.apache.ignite.internal.processors.platform.dotnet.PlatformDotNetPortableConfiguration;
import org.apache.ignite.internal.processors.platform.dotnet.PlatformDotNetPortableTypeConfiguration;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableIdMapper;
-import org.apache.ignite.internal.portable.api.PortableInvalidClassException;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.PortableSerializer;
-import org.apache.ignite.internal.portable.api.PortableTypeConfiguration;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableIdMapper;
+import org.apache.ignite.portable.PortableInvalidClassException;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableSerializer;
+import org.apache.ignite.portable.PortableTypeConfiguration;
import org.jetbrains.annotations.Nullable;
import org.jsr166.ConcurrentHashMap8;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataCollector.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataCollector.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataCollector.java
index 05e7f20..ae5fbf0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataCollector.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataCollector.java
@@ -27,9 +27,9 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableRawWriter;
-import org.apache.ignite.internal.portable.api.PortableWriter;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableRawWriter;
+import org.apache.ignite.portable.PortableWriter;
import org.jetbrains.annotations.Nullable;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataHandler.java
index fafafad..e03d67f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataHandler.java
@@ -17,8 +17,8 @@
package org.apache.ignite.internal.portable;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMetadata;
/**
* Portable meta data handler.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataImpl.java
index c0423eb..1d26007 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableMetaDataImpl.java
@@ -27,13 +27,13 @@ import java.util.Map;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableMarshalAware;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.PortableRawReader;
-import org.apache.ignite.internal.portable.api.PortableRawWriter;
-import org.apache.ignite.internal.portable.api.PortableReader;
-import org.apache.ignite.internal.portable.api.PortableWriter;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMarshalAware;
+import org.apache.ignite.portable.PortableMetadata;
+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.jetbrains.annotations.Nullable;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java
index 229c90f..fe4b628 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectEx.java
@@ -23,9 +23,9 @@ import java.util.IdentityHashMap;
import org.apache.ignite.IgniteException;
import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
import org.apache.ignite.internal.util.typedef.internal.SB;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
import org.jetbrains.annotations.Nullable;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
index cb81efe..47ff1ab 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
@@ -34,9 +34,9 @@ import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.plugin.extensions.communication.MessageReader;
import org.apache.ignite.plugin.extensions.communication.MessageWriter;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
import org.jetbrains.annotations.Nullable;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
index e788422..ba8ee83 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
@@ -30,9 +30,9 @@ import org.apache.ignite.internal.util.GridUnsafe;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.plugin.extensions.communication.MessageReader;
import org.apache.ignite.plugin.extensions.communication.MessageWriter;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
import org.jetbrains.annotations.Nullable;
import sun.misc.Unsafe;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawReaderEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawReaderEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawReaderEx.java
index e401142..e703f2f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawReaderEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawReaderEx.java
@@ -17,8 +17,8 @@
package org.apache.ignite.internal.portable;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableRawReader;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableRawReader;
import org.jetbrains.annotations.Nullable;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawWriterEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawWriterEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawWriterEx.java
index 43b7650..a59f157 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawWriterEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableRawWriterEx.java
@@ -18,8 +18,8 @@
package org.apache.ignite.internal.portable;
import org.apache.ignite.internal.portable.streams.PortableOutputStream;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableRawWriter;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableRawWriter;
import org.jetbrains.annotations.Nullable;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
index 2537926..2d4a1c3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.portable;
import java.util.HashMap;
import java.util.Map;
import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableObject;
import org.jetbrains.annotations.Nullable;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
index a101db5..4ad125a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
@@ -45,11 +45,11 @@ import org.apache.ignite.internal.util.GridEnumCache;
import org.apache.ignite.internal.util.lang.GridMapEntry;
import org.apache.ignite.internal.util.typedef.internal.SB;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableInvalidClassException;
-import org.apache.ignite.internal.portable.api.PortableObject;
-import org.apache.ignite.internal.portable.api.PortableRawReader;
-import org.apache.ignite.internal.portable.api.PortableReader;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableInvalidClassException;
+import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.portable.PortableRawReader;
+import org.apache.ignite.portable.PortableReader;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
index ccc1a5b..7259cc9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
@@ -35,7 +35,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import org.apache.ignite.internal.portable.builder.PortableLazyValue;
import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.internal.portable.api.PortableObject;
+import org.apache.ignite.portable.PortableObject;
import org.jetbrains.annotations.Nullable;
import org.jsr166.ConcurrentHashMap8;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
index 1d5ca60..3152c4b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
@@ -18,8 +18,12 @@
package org.apache.ignite.internal.portable;
import java.io.IOException;
+import java.io.ObjectInputStream;
import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;
@@ -28,13 +32,14 @@ import java.util.Date;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.internal.portable.streams.PortableHeapOutputStream;
import org.apache.ignite.internal.portable.streams.PortableOutputStream;
import org.apache.ignite.internal.util.typedef.internal.A;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableRawWriter;
-import org.apache.ignite.internal.portable.api.PortableWriter;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableRawWriter;
+import org.apache.ignite.portable.PortableWriter;
import org.jetbrains.annotations.Nullable;
import static java.nio.charset.StandardCharsets.UTF_8;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/IgnitePortables.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/IgnitePortables.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/IgnitePortables.java
deleted file mode 100644
index 56f3768..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/IgnitePortables.java
+++ /dev/null
@@ -1,362 +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.api;
-
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.TreeMap;
-import java.util.UUID;
-import org.apache.ignite.IgniteCache;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Defines portable objects functionality. With portable objects you are able to:
- * <ul>
- * <li>Seamlessly interoperate between Java, .NET, and C++.</li>
- * <li>Make any object portable with zero code change to your existing code.</li>
- * <li>Nest portable objects within each other.</li>
- * <li>Automatically handle {@code circular} or {@code null} references.</li>
- * <li>Automatically convert collections and maps between Java, .NET, and C++.</li>
- * <li>
- * Optionally avoid deserialization of objects on the server side
- * (objects are stored in {@link PortableObject} format).
- * </li>
- * <li>Avoid need to have concrete class definitions on the server side.</li>
- * <li>Dynamically change structure of the classes without having to restart the cluster.</li>
- * <li>Index into portable objects for querying purposes.</li>
- * </ul>
- * <h1 class="header">Working With Portables Directly</h1>
- * Once an object is defined as portable,
- * Ignite will always store it in memory in the portable (i.e. binary) format.
- * User can choose to work either with the portable format or with the deserialized form
- * (assuming that class definitions are present in the classpath).
- * <p>
- * To work with the portable format directly, user should create a special cache projection
- * using {@link IgniteCache#withKeepPortable()} method and then retrieve individual fields as needed:
- * <pre name=code class=java>
- * IgniteCache<PortableObject, PortableObject> prj = cache.withKeepPortable();
- *
- * // Convert instance of MyKey to portable format.
- * // We could also use PortableBuilder to create the key in portable format directly.
- * PortableObject key = grid.portables().toPortable(new MyKey());
- *
- * PortableObject val = prj.get(key);
- *
- * String field = val.field("myFieldName");
- * </pre>
- * Alternatively, if we have class definitions in the classpath, we may choose to work with deserialized
- * typed objects at all times. In this case we do incur the deserialization cost. However, if
- * {@link PortableMarshaller#isKeepDeserialized()} is {@code true} then Ignite will only deserialize on the first access
- * and will cache the deserialized object, so it does not have to be deserialized again:
- * <pre name=code class=java>
- * IgniteCache<MyKey.class, MyValue.class> cache = grid.cache(null);
- *
- * MyValue val = cache.get(new MyKey());
- *
- * // Normal java getter.
- * String fieldVal = val.getMyFieldName();
- * </pre>
- * If we used, for example, one of the automatically handled portable types for a key, like integer,
- * and still wanted to work with binary portable format for values, then we would declare cache projection
- * as follows:
- * <pre name=code class=java>
- * IgniteCache<Integer.class, PortableObject> prj = cache.withKeepPortable();
- * </pre>
- * <h1 class="header">Automatic Portable Types</h1>
- * Note that only portable classes are converted to {@link PortableObject} format. Following
- * classes are never converted (e.g., {@link #toPortable(Object)} method will return original
- * object, and instances of these classes will be stored in cache without changes):
- * <ul>
- * <li>All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)</li>
- * <li>Arrays of primitives (byte[], int[], ...)</li>
- * <li>{@link String} and array of {@link String}s</li>
- * <li>{@link UUID} and array of {@link UUID}s</li>
- * <li>{@link Date} and array of {@link Date}s</li>
- * <li>{@link Timestamp} and array of {@link Timestamp}s</li>
- * <li>Enums and array of enums</li>
- * <li>
- * Maps, collections and array of objects (but objects inside
- * them will still be converted if they are portable)
- * </li>
- * </ul>
- * <h1 class="header">Working With Maps and Collections</h1>
- * All maps and collections in the portable objects are serialized automatically. When working
- * with different platforms, e.g. C++ or .NET, Ignite will automatically pick the most
- * adequate collection or map in either language. For example, {@link ArrayList} in Java will become
- * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap}
- * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary}
- * in C#, etc.
- * <h1 class="header">Building Portable Objects</h1>
- * Ignite comes with {@link PortableBuilder} which allows to build portable objects dynamically:
- * <pre name=code class=java>
- * PortableBuilder builder = Ignition.ignite().portables().builder();
- *
- * builder.typeId("MyObject");
- *
- * builder.stringField("fieldA", "A");
- * build.intField("fieldB", "B");
- *
- * PortableObject portableObj = builder.build();
- * </pre>
- * For the cases when class definition is present
- * in the class path, it is also possible to populate a standard POJO and then
- * convert it to portable format, like so:
- * <pre name=code class=java>
- * MyObject obj = new MyObject();
- *
- * obj.setFieldA("A");
- * obj.setFieldB(123);
- *
- * PortableObject portableObj = Ignition.ignite().portables().toPortable(obj);
- * </pre>
- * NOTE: you don't need to convert typed objects to portable format before storing
- * them in cache, Ignite will do that automatically.
- * <h1 class="header">Portable Metadata</h1>
- * Even though Ignite portable protocol only works with hash codes for type and field names
- * to achieve better performance, Ignite provides metadata for all portable types which
- * can be queried ar runtime via any of the {@link IgnitePortables#metadata(Class)}
- * methods. Having metadata also allows for proper formatting of {@code PortableObject#toString()} method,
- * even when portable objects are kept in binary format only, which may be necessary for audit reasons.
- * <h1 class="header">Dynamic Structure Changes</h1>
- * Since objects are always cached in the portable binary format, server does not need to
- * be aware of the class definitions. Moreover, if class definitions are not present or not
- * used on the server, then clients can continuously change the structure of the portable
- * objects without having to restart the cluster. For example, if one client stores a
- * certain class with fields A and B, and another client stores the same class with
- * fields B and C, then the server-side portable object will have the fields A, B, and C.
- * As the structure of a portable object changes, the new fields become available for SQL queries
- * automatically.
- * <h1 class="header">Configuration</h1>
- * By default all your objects are considered as portables and no specific configuration is needed.
- * However, in some cases, like when an object is used by both Java and .Net, you may need to specify portable objects
- * explicitly by calling {@link PortableMarshaller#setClassNames(Collection)}.
- * The only requirement Ignite imposes is that your object has an empty
- * constructor. Note, that since server side does not have to know the class definition,
- * you only need to list portable objects in configuration on the client side. However, if you
- * list them on the server side as well, then you get the ability to deserialize portable objects
- * into concrete types on the server as well as on the client.
- * <p>
- * Here is an example of portable configuration (note that star (*) notation is supported):
- * <pre name=code class=xml>
- * ...
- * <!-- Explicit portable objects configuration. -->
- * <property name="marshaller">
- * <bean class="org.apache.ignite.internal.portable.api.PortableMarshaller">
- * <property name="classNames">
- * <list>
- * <value>my.package.for.portable.objects.*</value>
- * <value>org.apache.ignite.examples.client.portable.Employee</value>
- * </list>
- * </property>
- * </bean>
- * </property>
- * ...
- * </pre>
- * or from code:
- * <pre name=code class=java>
- * IgniteConfiguration cfg = new IgniteConfiguration();
- *
- * PortableMarshaller marsh = new PortableMarshaller();
- *
- * marsh.setClassNames(Arrays.asList(
- * Employee.class.getName(),
- * Address.class.getName())
- * );
- *
- * cfg.setMarshaller(marsh);
- * </pre>
- * You can also specify class name for a portable object via {@link PortableTypeConfiguration}.
- * Do it in case if you need to override other configuration properties on per-type level, like
- * ID-mapper, or serializer.
- * <h1 class="header">Custom Affinity Keys</h1>
- * Often you need to specify an alternate key (not the cache key) for affinity routing whenever
- * storing objects in cache. For example, if you are caching {@code Employee} object with
- * {@code Organization}, and want to colocate employees with organization they work for,
- * so you can process them together, you need to specify an alternate affinity key.
- * With portable objects you would have to do it as following:
- * <pre name=code class=xml>
- * <property name="marshaller">
- * <bean class="org.gridgain.grid.marshaller.portable.PortableMarshaller">
- * ...
- * <property name="typeConfigurations">
- * <list>
- * <bean class="org.apache.ignite.internal.portable.api.PortableTypeConfiguration">
- * <property name="className" value="org.apache.ignite.examples.client.portable.EmployeeKey"/>
- * <property name="affinityKeyFieldName" value="organizationId"/>
- * </bean>
- * </list>
- * </property>
- * ...
- * </bean>
- * </property>
- * </pre>
- * <h1 class="header">Serialization</h1>
- * Serialization and deserialization works out-of-the-box in Ignite. However, you can provide your own custom
- * serialization logic by optionally implementing {@link PortableMarshalAware} interface, like so:
- * <pre name=code class=java>
- * public class Address implements PortableMarshalAware {
- * private String street;
- * private int zip;
- *
- * // Empty constructor required for portable deserialization.
- * public Address() {}
- *
- * @Override public void writePortable(PortableWriter writer) throws PortableException {
- * writer.writeString("street", street);
- * writer.writeInt("zip", zip);
- * }
- *
- * @Override public void readPortable(PortableReader reader) throws PortableException {
- * street = reader.readString("street");
- * zip = reader.readInt("zip");
- * }
- * }
- * </pre>
- * Alternatively, if you cannot change class definitions, you can provide custom serialization
- * logic in {@link PortableSerializer} either globally in {@link PortableMarshaller} or
- * for a specific type via {@link PortableTypeConfiguration} instance.
- * <p>
- * Similar to java serialization you can use {@code writeReplace()} and {@code readResolve()} methods.
- * <ul>
- * <li>
- * {@code readResolve} is defined as follows: {@code ANY-ACCESS-MODIFIER Object readResolve()}.
- * It may be used to replace the de-serialized object by another one of your choice.
- * </li>
- * <li>
- * {@code writeReplace} is defined as follows: {@code ANY-ACCESS-MODIFIER Object writeReplace()}. This method
- * allows the developer to provide a replacement object that will be serialized instead of the original one.
- * </li>
- * </ul>
- *
- * <h1 class="header">Custom ID Mappers</h1>
- * Ignite implementation uses name hash codes to generate IDs for class names or field names
- * internally. However, in cases when you want to provide your own ID mapping schema,
- * you can provide your own {@link PortableIdMapper} implementation.
- * <p>
- * ID-mapper may be provided either globally in {@link PortableMarshaller},
- * or for a specific type via {@link PortableTypeConfiguration} instance.
- * <h1 class="header">Query Indexing</h1>
- * Portable objects can be indexed for querying by specifying index fields in
- * {@link org.apache.ignite.cache.CacheTypeMetadata} inside of specific
- * {@link org.apache.ignite.configuration.CacheConfiguration} instance,
- * like so:
- * <pre name=code class=xml>
- * ...
- * <bean class="org.apache.ignite.cache.CacheConfiguration">
- * ...
- * <property name="typeMetadata">
- * <list>
- * <bean class="CacheTypeMetadata">
- * <property name="type" value="Employee"/>
- *
- * <!-- Fields to index in ascending order. -->
- * <property name="ascendingFields">
- * <map>
- * <entry key="name" value="java.lang.String"/>
- *
- * <!-- Nested portable objects can also be indexed. -->
- * <entry key="address.zip" value="java.lang.Integer"/>
- * </map>
- * </property>
- * </bean>
- * </list>
- * </property>
- * </bean>
- * </pre>
- */
-public interface IgnitePortables {
- /**
- * Gets type ID for given type name.
- *
- * @param typeName Type name.
- * @return Type ID.
- */
- public int typeId(String typeName);
-
- /**
- * Converts provided object to instance of {@link PortableObject}.
- *
- * @param obj Object to convert.
- * @return Converted object.
- * @throws PortableException In case of error.
- */
- public <T> T toPortable(@Nullable Object obj) throws PortableException;
-
- /**
- * Creates new portable builder.
- *
- * @param typeId ID of the type.
- * @return Newly portable builder.
- */
- public PortableBuilder builder(int typeId);
-
- /**
- * Creates new portable builder.
- *
- * @param typeName Type name.
- * @return Newly portable builder.
- */
- public PortableBuilder builder(String typeName);
-
- /**
- * Creates portable builder initialized by existing portable object.
- *
- * @param portableObj Portable object to initialize builder.
- * @return Portable builder.
- */
- public PortableBuilder builder(PortableObject portableObj);
-
- /**
- * Gets metadata for provided class.
- *
- * @param cls Class.
- * @return Metadata.
- * @throws PortableException In case of error.
- */
- @Nullable public PortableMetadata metadata(Class<?> cls) throws PortableException;
-
- /**
- * Gets metadata for provided class name.
- *
- * @param typeName Type name.
- * @return Metadata.
- * @throws PortableException In case of error.
- */
- @Nullable public PortableMetadata metadata(String typeName) throws PortableException;
-
- /**
- * Gets metadata for provided type ID.
- *
- * @param typeId Type ID.
- * @return Metadata.
- * @throws PortableException In case of error.
- */
- @Nullable public PortableMetadata metadata(int typeId) throws PortableException;
-
- /**
- * Gets metadata for all known types.
- *
- * @return Metadata.
- * @throws PortableException In case of error.
- */
- public Collection<PortableMetadata> metadata() throws PortableException;
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableBuilder.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableBuilder.java
deleted file mode 100644
index c819f46..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableBuilder.java
+++ /dev/null
@@ -1,136 +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.api;
-
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Portable object builder. Provides ability to build portable objects dynamically without having class definitions.
- * <p>
- * Here is an example of how a portable object can be built dynamically:
- * <pre name=code class=java>
- * PortableBuilder builder = Ignition.ignite().portables().builder("org.project.MyObject");
- *
- * builder.setField("fieldA", "A");
- * builder.setField("fieldB", "B");
- *
- * PortableObject portableObj = builder.build();
- * </pre>
- *
- * <p>
- * Also builder can be initialized by existing portable object. This allows changing some fields without affecting
- * other fields.
- * <pre name=code class=java>
- * PortableBuilder builder = Ignition.ignite().portables().builder(person);
- *
- * builder.setField("name", "John");
- *
- * person = builder.build();
- * </pre>
- * </p>
- *
- * If you need to modify nested portable object you can get builder for nested object using
- * {@link #getField(String)}, changes made on nested builder will affect parent object,
- * for example:
- *
- * <pre name=code class=java>
- * PortableBuilder personBuilder = grid.portables().createBuilder(personPortableObj);
- * PortableBuilder addressBuilder = personBuilder.setField("address");
- *
- * addressBuilder.setField("city", "New York");
- *
- * personPortableObj = personBuilder.build();
- *
- * // Should be "New York".
- * String city = personPortableObj.getField("address").getField("city");
- * </pre>
- *
- * @see IgnitePortables#builder(int)
- * @see IgnitePortables#builder(String)
- * @see IgnitePortables#builder(PortableObject)
- */
-public interface PortableBuilder {
- /**
- * Returns value assigned to the specified field.
- * If the value is a portable object instance of {@code GridPortableBuilder} will be returned,
- * which can be modified.
- * <p>
- * Collections and maps returned from this method are modifiable.
- *
- * @param name Field name.
- * @return Filed value.
- */
- public <T> T getField(String name);
-
- /**
- * Sets field value.
- *
- * @param name Field name.
- * @param val Field value (cannot be {@code null}).
- * @see PortableObject#metaData()
- */
- public PortableBuilder setField(String name, Object val);
-
- /**
- * Sets field value with value type specification.
- * <p>
- * Field type is needed for proper metadata update.
- *
- * @param name Field name.
- * @param val Field value.
- * @param type Field type.
- * @see PortableObject#metaData()
- */
- public <T> PortableBuilder setField(String name, @Nullable T val, Class<? super T> type);
-
- /**
- * Sets field value.
- * <p>
- * This method should be used if field is portable object.
- *
- * @param name Field name.
- * @param builder Builder for object field.
- */
- public PortableBuilder setField(String name, @Nullable PortableBuilder builder);
-
- /**
- * Removes field from this builder.
- *
- * @param fieldName Field name.
- * @return {@code this} instance for chaining.
- */
- public PortableBuilder removeField(String fieldName);
-
- /**
- * Sets hash code for resulting portable object returned by {@link #build()} method.
- * <p>
- * If not set {@code 0} is used.
- *
- * @param hashCode Hash code.
- * @return {@code this} instance for chaining.
- */
- public PortableBuilder hashCode(int hashCode);
-
- /**
- * Builds portable object.
- *
- * @return Portable object.
- * @throws PortableException In case of error.
- */
- public PortableObject build() throws PortableException;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableException.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableException.java
deleted file mode 100644
index f230182..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableException.java
+++ /dev/null
@@ -1,57 +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.api;
-
-import org.apache.ignite.IgniteException;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Exception indicating portable object serialization error.
- */
-public class PortableException extends IgniteException {
- /** */
- private static final long serialVersionUID = 0L;
-
- /**
- * Creates portable exception with error message.
- *
- * @param msg Error message.
- */
- public PortableException(String msg) {
- super(msg);
- }
-
- /**
- * Creates portable exception with {@link Throwable} as a cause.
- *
- * @param cause Cause.
- */
- public PortableException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Creates portable exception with error message and {@link Throwable} as a cause.
- *
- * @param msg Error message.
- * @param cause Cause.
- */
- public PortableException(String msg, @Nullable Throwable cause) {
- super(msg, cause);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableIdMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableIdMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableIdMapper.java
deleted file mode 100644
index 1e20f8e..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableIdMapper.java
+++ /dev/null
@@ -1,54 +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.api;
-
-/**
- * Type and field ID mapper for portable objects. Ignite never writes full
- * strings for field or type names. Instead, for performance reasons, Ignite
- * writes integer hash codes for type and field names. It has been tested that
- * hash code conflicts for the type names or the field names
- * within the same type are virtually non-existent and, to gain performance, it is safe
- * to work with hash codes. For the cases when hash codes for different types or fields
- * actually do collide {@code PortableIdMapper} allows to override the automatically
- * generated hash code IDs for the type and field names.
- * <p>
- * Portable ID mapper can be configured for all portable objects via {@link PortableMarshaller#getIdMapper()} method,
- * or for a specific portable type via {@link PortableTypeConfiguration#getIdMapper()} method.
- */
-public interface PortableIdMapper {
- /**
- * Gets type ID for provided class name.
- * <p>
- * If {@code 0} is returned, hash code of class simple name will be used.
- *
- * @param clsName Class name.
- * @return Type ID.
- */
- public int typeId(String clsName);
-
- /**
- * Gets ID for provided field.
- * <p>
- * If {@code 0} is returned, hash code of field name will be used.
- *
- * @param typeId Type ID.
- * @param fieldName Field name.
- * @return Field ID.
- */
- public int fieldId(int typeId, String fieldName);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableInvalidClassException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableInvalidClassException.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableInvalidClassException.java
deleted file mode 100644
index 82e6697..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableInvalidClassException.java
+++ /dev/null
@@ -1,58 +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.api;
-
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Exception indicating that class needed for deserialization of portable object does not exist.
- * <p>
- * Thrown from {@link PortableObject#deserialize()} method.
- */
-public class PortableInvalidClassException extends PortableException {
- /** */
- private static final long serialVersionUID = 0L;
-
- /**
- * Creates invalid class exception with error message.
- *
- * @param msg Error message.
- */
- public PortableInvalidClassException(String msg) {
- super(msg);
- }
-
- /**
- * Creates invalid class exception with {@link Throwable} as a cause.
- *
- * @param cause Cause.
- */
- public PortableInvalidClassException(Throwable cause) {
- super(cause);
- }
-
- /**
- * Creates invalid class exception with error message and {@link Throwable} as a cause.
- *
- * @param msg Error message.
- * @param cause Cause.
- */
- public PortableInvalidClassException(String msg, @Nullable Throwable cause) {
- super(msg, cause);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableMarshalAware.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableMarshalAware.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableMarshalAware.java
deleted file mode 100644
index f304afb..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/api/PortableMarshalAware.java
+++ /dev/null
@@ -1,48 +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.api;
-
-/**
- * Interface that allows to implement custom serialization
- * logic for portable objects. Portable objects are not required
- * to implement this interface, in which case Ignite will automatically
- * serialize portable objects using reflection.
- * <p>
- * This interface, in a way, is analogous to {@link java.io.Externalizable}
- * interface, which allows users to override default serialization logic,
- * usually for performance reasons. The only difference here is that portable
- * serialization is already very fast and implementing custom serialization
- * logic for portables does not provide significant performance gains.
- */
-public interface PortableMarshalAware {
- /**
- * Writes fields to provided writer.
- *
- * @param writer Portable object writer.
- * @throws PortableException In case of error.
- */
- public void writePortable(PortableWriter writer) throws PortableException;
-
- /**
- * Reads fields from provided reader.
- *
- * @param reader Portable object reader.
- * @throws PortableException In case of error.
- */
- public void readPortable(PortableReader reader) throws PortableException;
-}
\ No newline at end of file
[08/11] ignite git commit: Revert "ignite-1462: hid portable API in
1.4 release" This reverts commit 71379a8061f50f336adc31fa20cd593b659b050f.
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/CacheOsStoreManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/CacheOsStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/CacheOsStoreManager.java
index ef7dc9a..f7f5f4e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/CacheOsStoreManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/CacheOsStoreManager.java
@@ -23,7 +23,7 @@ import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.processors.platform.PlatformProcessor;
import org.apache.ignite.internal.processors.platform.cache.store.PlatformCacheStore;
-import org.apache.ignite.internal.portable.api.PortableMarshaller;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
/**
* Default store manager implementation.
@@ -82,6 +82,6 @@ public class CacheOsStoreManager extends GridCacheStoreManagerAdapter {
/** {@inheritDoc} */
@Override public boolean configuredConvertPortable() {
- return true;
+ return !(ctx.config().getMarshaller() instanceof PortableMarshaller && cfg.isKeepPortableInStore());
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfiguration.java
index 423b5e7..fac69fb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfiguration.java
@@ -19,12 +19,12 @@ package org.apache.ignite.internal.processors.platform.dotnet;
import org.apache.ignite.internal.processors.platform.PlatformConfiguration;
import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableMarshalAware;
-import org.apache.ignite.internal.portable.api.PortableRawReader;
-import org.apache.ignite.internal.portable.api.PortableRawWriter;
-import org.apache.ignite.internal.portable.api.PortableReader;
-import org.apache.ignite.internal.portable.api.PortableWriter;
+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 java.util.ArrayList;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetPortableConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetPortableConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetPortableConfiguration.java
index 92028b3..a9b6022 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetPortableConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetPortableConfiguration.java
@@ -18,12 +18,12 @@
package org.apache.ignite.internal.processors.platform.dotnet;
import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableMarshalAware;
-import org.apache.ignite.internal.portable.api.PortableRawReader;
-import org.apache.ignite.internal.portable.api.PortableRawWriter;
-import org.apache.ignite.internal.portable.api.PortableReader;
-import org.apache.ignite.internal.portable.api.PortableWriter;
+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 java.util.ArrayList;
import java.util.Collection;
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetPortableTypeConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetPortableTypeConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetPortableTypeConfiguration.java
index a307860..d7f1ab1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetPortableTypeConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetPortableTypeConfiguration.java
@@ -18,12 +18,12 @@
package org.apache.ignite.internal.processors.platform.dotnet;
import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.portable.api.PortableException;
-import org.apache.ignite.internal.portable.api.PortableMarshalAware;
-import org.apache.ignite.internal.portable.api.PortableRawReader;
-import org.apache.ignite.internal.portable.api.PortableRawWriter;
-import org.apache.ignite.internal.portable.api.PortableReader;
-import org.apache.ignite.internal.portable.api.PortableWriter;
+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.jetbrains.annotations.Nullable;
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java b/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
new file mode 100644
index 0000000..bfc34cd
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
@@ -0,0 +1,358 @@
+/*
+ * 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.marshaller.portable;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.portable.GridPortableMarshaller;
+import org.apache.ignite.internal.portable.PortableContext;
+import org.apache.ignite.marshaller.AbstractMarshaller;
+import org.apache.ignite.marshaller.MarshallerContext;
+import org.apache.ignite.portable.PortableException;
+import org.apache.ignite.portable.PortableIdMapper;
+import org.apache.ignite.portable.PortableObject;
+import org.apache.ignite.portable.PortableProtocolVersion;
+import org.apache.ignite.portable.PortableSerializer;
+import org.apache.ignite.portable.PortableTypeConfiguration;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Implementation of {@link org.apache.ignite.marshaller.Marshaller} that lets to serialize and deserialize all objects
+ * in the portable format.
+ * <p>
+ * {@code PortableMarshaller} is tested only on Java HotSpot VM on other VMs it could yield unexpected results.
+ * <p>
+ * <h1 class="header">Configuration</h1>
+ * <h2 class="header">Mandatory</h2>
+ * This marshaller has no mandatory configuration parameters.
+ * <h2 class="header">Java Example</h2>
+ * <pre name="code" class="java">
+ * PortableMarshaller marshaller = new PortableMarshaller();
+ *
+ * IgniteConfiguration cfg = new IgniteConfiguration();
+ *
+ * // Override marshaller.
+ * cfg.setMarshaller(marshaller);
+ *
+ * // Starts grid.
+ * G.start(cfg);
+ * </pre>
+ * <h2 class="header">Spring Example</h2>
+ * PortableMarshaller can be configured from Spring XML configuration file:
+ * <pre name="code" class="xml">
+ * <bean id="grid.custom.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" singleton="true">
+ * ...
+ * <property name="marshaller">
+ * <bean class="org.apache.ignite.marshaller.portable.PortableMarshaller">
+ * ...
+ * </bean>
+ * </property>
+ * ...
+ * </bean>
+ * </pre>
+ * <p>
+ * <img src="http://ignite.apache.org/images/spring-small.png">
+ * <br>
+ * For information about Spring framework visit <a href="http://www.springframework.org/">www.springframework.org</a>
+ */
+public class PortableMarshaller extends AbstractMarshaller {
+ /** Default portable protocol version. */
+ public static final PortableProtocolVersion DFLT_PORTABLE_PROTO_VER = PortableProtocolVersion.VER_1_4_0;
+
+ /** Class names. */
+ private Collection<String> clsNames;
+
+ /** ID mapper. */
+ private PortableIdMapper idMapper;
+
+ /** Serializer. */
+ private PortableSerializer serializer;
+
+ /** Types. */
+ private Collection<PortableTypeConfiguration> typeCfgs;
+
+ /** Use timestamp flag. */
+ private boolean useTs = true;
+
+ /** Whether to convert string to bytes using UTF-8 encoding. */
+ private boolean convertString = true;
+
+ /** Meta data enabled flag. */
+ private boolean metaDataEnabled = true;
+
+ /** Keep deserialized flag. */
+ private boolean keepDeserialized = true;
+
+ /** Protocol version. */
+ private PortableProtocolVersion protoVer = DFLT_PORTABLE_PROTO_VER;
+
+ /** */
+ private GridPortableMarshaller impl;
+
+ /**
+ * Gets class names.
+ *
+ * @return Class names.
+ */
+ public Collection<String> getClassNames() {
+ return clsNames;
+ }
+
+ /**
+ * Sets class names of portable objects explicitly.
+ *
+ * @param clsNames Class names.
+ */
+ public void setClassNames(Collection<String> clsNames) {
+ this.clsNames = new ArrayList<>(clsNames.size());
+
+ for (String clsName : clsNames)
+ this.clsNames.add(clsName.trim());
+ }
+
+ /**
+ * Gets ID mapper.
+ *
+ * @return ID mapper.
+ */
+ public PortableIdMapper getIdMapper() {
+ return idMapper;
+ }
+
+ /**
+ * Sets ID mapper.
+ *
+ * @param idMapper ID mapper.
+ */
+ public void setIdMapper(PortableIdMapper idMapper) {
+ this.idMapper = idMapper;
+ }
+
+ /**
+ * Gets serializer.
+ *
+ * @return Serializer.
+ */
+ public PortableSerializer getSerializer() {
+ return serializer;
+ }
+
+ /**
+ * Sets serializer.
+ *
+ * @param serializer Serializer.
+ */
+ public void setSerializer(PortableSerializer serializer) {
+ this.serializer = serializer;
+ }
+
+ /**
+ * Gets types configuration.
+ *
+ * @return Types configuration.
+ */
+ public Collection<PortableTypeConfiguration> getTypeConfigurations() {
+ return typeCfgs;
+ }
+
+ /**
+ * Sets type configurations.
+ *
+ * @param typeCfgs Type configurations.
+ */
+ public void setTypeConfigurations(Collection<PortableTypeConfiguration> typeCfgs) {
+ this.typeCfgs = typeCfgs;
+ }
+
+ /**
+ * If {@code true} then date values converted to {@link Timestamp} on deserialization.
+ * <p>
+ * Default value is {@code true}.
+ *
+ * @return Flag indicating whether date values converted to {@link Timestamp} during unmarshalling.
+ */
+ public boolean isUseTimestamp() {
+ return useTs;
+ }
+
+ /**
+ * @param useTs Flag indicating whether date values converted to {@link Timestamp} during unmarshalling.
+ */
+ public void setUseTimestamp(boolean useTs) {
+ this.useTs = useTs;
+ }
+
+ /**
+ * Gets strings must be converted to or from bytes using UTF-8 encoding.
+ * <p>
+ * Default value is {@code true}.
+ *
+ * @return Flag indicating whether string must be converted to byte array using UTF-8 encoding.
+ */
+ public boolean isConvertStringToBytes() {
+ return convertString;
+ }
+
+ /**
+ * Sets strings must be converted to or from bytes using UTF-8 encoding.
+ * <p>
+ * Default value is {@code true}.
+ *
+ * @param convertString Flag indicating whether string must be converted to byte array using UTF-8 encoding.
+ */
+ public void setConvertStringToBytes(boolean convertString) {
+ this.convertString = convertString;
+ }
+
+ /**
+ * If {@code true}, meta data will be collected or all types. If you need to override this behaviour for
+ * some specific type, use {@link PortableTypeConfiguration#setMetaDataEnabled(Boolean)} method.
+ * <p>
+ * Default value if {@code true}.
+ *
+ * @return Whether meta data is collected.
+ */
+ public boolean isMetaDataEnabled() {
+ return metaDataEnabled;
+ }
+
+ /**
+ * @param metaDataEnabled Whether meta data is collected.
+ */
+ public void setMetaDataEnabled(boolean metaDataEnabled) {
+ this.metaDataEnabled = metaDataEnabled;
+ }
+
+ /**
+ * If {@code true}, {@link PortableObject} will cache deserialized instance after
+ * {@link PortableObject#deserialize()} is called. All consequent calls of this
+ * method on the same instance of {@link PortableObject} will return that cached
+ * value without actually deserializing portable object. If you need to override this
+ * behaviour for some specific type, use {@link PortableTypeConfiguration#setKeepDeserialized(Boolean)}
+ * method.
+ * <p>
+ * Default value if {@code true}.
+ *
+ * @return Whether deserialized value is kept.
+ */
+ public boolean isKeepDeserialized() {
+ return keepDeserialized;
+ }
+
+ /**
+ * @param keepDeserialized Whether deserialized value is kept.
+ */
+ public void setKeepDeserialized(boolean keepDeserialized) {
+ this.keepDeserialized = keepDeserialized;
+ }
+
+ /**
+ * Gets portable protocol version.
+ * <p>
+ * Defaults to {@link #DFLT_PORTABLE_PROTO_VER}.
+ *
+ * @return Portable protocol version.
+ */
+ public PortableProtocolVersion getProtocolVersion() {
+ return protoVer;
+ }
+
+ /**
+ * Sets portable protocol version.
+ * <p>
+ * Defaults to {@link #DFLT_PORTABLE_PROTO_VER}.
+ *
+ * @param protoVer Portable protocol version.
+ */
+ public void setProtocolVersion(PortableProtocolVersion protoVer) {
+ if (protoVer == null)
+ throw new IllegalArgumentException("Wrong portable protocol version: " + protoVer);
+
+ this.protoVer = protoVer;
+ }
+
+ /**
+ * Returns currently set {@link MarshallerContext}.
+ *
+ * @return Marshaller context.
+ */
+ public MarshallerContext getContext() {
+ return ctx;
+ }
+
+ /**
+ * Sets {@link PortableContext}.
+ * <p/>
+ * @param ctx Portable context.
+ */
+ private void setPortableContext(PortableContext ctx) {
+ ctx.configure(this);
+
+ impl = new GridPortableMarshaller(ctx);
+ }
+
+ /** {@inheritDoc} */
+ @Override public byte[] marshal(@Nullable Object obj) throws IgniteCheckedException {
+ return impl.marshal(obj, 0);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void marshal(@Nullable Object obj, OutputStream out) throws IgniteCheckedException {
+ byte[] arr = marshal(obj);
+
+ try {
+ out.write(arr);
+ }
+ catch (IOException e) {
+ throw new PortableException("Failed to marshal the object: " + obj, e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
+ return impl.deserialize(bytes, clsLdr);
+ }
+
+ /** {@inheritDoc} */
+ @Override public <T> T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+
+ byte[] arr = new byte[4096];
+ int cnt;
+
+ // we have to fully read the InputStream because GridPortableMarshaller requires support of a method that
+ // returns number of bytes remaining.
+ try {
+ while ((cnt = in.read(arr)) != -1)
+ buffer.write(arr, 0, cnt);
+
+ buffer.flush();
+
+ return impl.deserialize(buffer.toByteArray(), clsLdr);
+ }
+ catch (IOException e) {
+ throw new PortableException("Failed to unmarshal the object from InputStream", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/marshaller/portable/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/portable/package-info.java b/modules/core/src/main/java/org/apache/ignite/marshaller/portable/package-info.java
new file mode 100644
index 0000000..90cc5e6
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/portable/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains portable marshaller API classes.
+ */
+package org.apache.ignite.marshaller.portable;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableBuilder.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableBuilder.java
new file mode 100644
index 0000000..377fcdc
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableBuilder.java
@@ -0,0 +1,137 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.IgnitePortables;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Portable object builder. Provides ability to build portable objects dynamically without having class definitions.
+ * <p>
+ * Here is an example of how a portable object can be built dynamically:
+ * <pre name=code class=java>
+ * PortableBuilder builder = Ignition.ignite().portables().builder("org.project.MyObject");
+ *
+ * builder.setField("fieldA", "A");
+ * builder.setField("fieldB", "B");
+ *
+ * PortableObject portableObj = builder.build();
+ * </pre>
+ *
+ * <p>
+ * Also builder can be initialized by existing portable object. This allows changing some fields without affecting
+ * other fields.
+ * <pre name=code class=java>
+ * PortableBuilder builder = Ignition.ignite().portables().builder(person);
+ *
+ * builder.setField("name", "John");
+ *
+ * person = builder.build();
+ * </pre>
+ * </p>
+ *
+ * If you need to modify nested portable object you can get builder for nested object using
+ * {@link #getField(String)}, changes made on nested builder will affect parent object,
+ * for example:
+ *
+ * <pre name=code class=java>
+ * PortableBuilder personBuilder = grid.portables().createBuilder(personPortableObj);
+ * PortableBuilder addressBuilder = personBuilder.setField("address");
+ *
+ * addressBuilder.setField("city", "New York");
+ *
+ * personPortableObj = personBuilder.build();
+ *
+ * // Should be "New York".
+ * String city = personPortableObj.getField("address").getField("city");
+ * </pre>
+ *
+ * @see IgnitePortables#builder(int)
+ * @see IgnitePortables#builder(String)
+ * @see IgnitePortables#builder(PortableObject)
+ */
+public interface PortableBuilder {
+ /**
+ * Returns value assigned to the specified field.
+ * If the value is a portable object instance of {@code GridPortableBuilder} will be returned,
+ * which can be modified.
+ * <p>
+ * Collections and maps returned from this method are modifiable.
+ *
+ * @param name Field name.
+ * @return Filed value.
+ */
+ public <T> T getField(String name);
+
+ /**
+ * Sets field value.
+ *
+ * @param name Field name.
+ * @param val Field value (cannot be {@code null}).
+ * @see PortableObject#metaData()
+ */
+ public PortableBuilder setField(String name, Object val);
+
+ /**
+ * Sets field value with value type specification.
+ * <p>
+ * Field type is needed for proper metadata update.
+ *
+ * @param name Field name.
+ * @param val Field value.
+ * @param type Field type.
+ * @see PortableObject#metaData()
+ */
+ public <T> PortableBuilder setField(String name, @Nullable T val, Class<? super T> type);
+
+ /**
+ * Sets field value.
+ * <p>
+ * This method should be used if field is portable object.
+ *
+ * @param name Field name.
+ * @param builder Builder for object field.
+ */
+ public PortableBuilder setField(String name, @Nullable PortableBuilder builder);
+
+ /**
+ * Removes field from this builder.
+ *
+ * @param fieldName Field name.
+ * @return {@code this} instance for chaining.
+ */
+ public PortableBuilder removeField(String fieldName);
+
+ /**
+ * Sets hash code for resulting portable object returned by {@link #build()} method.
+ * <p>
+ * If not set {@code 0} is used.
+ *
+ * @param hashCode Hash code.
+ * @return {@code this} instance for chaining.
+ */
+ public PortableBuilder hashCode(int hashCode);
+
+ /**
+ * Builds portable object.
+ *
+ * @return Portable object.
+ * @throws PortableException In case of error.
+ */
+ public PortableObject build() throws PortableException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableException.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableException.java
new file mode 100644
index 0000000..0f8d78b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableException.java
@@ -0,0 +1,57 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.IgniteException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Exception indicating portable object serialization error.
+ */
+public class PortableException extends IgniteException {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /**
+ * Creates portable exception with error message.
+ *
+ * @param msg Error message.
+ */
+ public PortableException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Creates portable exception with {@link Throwable} as a cause.
+ *
+ * @param cause Cause.
+ */
+ public PortableException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Creates portable exception with error message and {@link Throwable} as a cause.
+ *
+ * @param msg Error message.
+ * @param cause Cause.
+ */
+ public PortableException(String msg, @Nullable Throwable cause) {
+ super(msg, cause);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableIdMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableIdMapper.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableIdMapper.java
new file mode 100644
index 0000000..368e415
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableIdMapper.java
@@ -0,0 +1,56 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ * Type and field ID mapper for portable objects. Ignite never writes full
+ * strings for field or type names. Instead, for performance reasons, Ignite
+ * writes integer hash codes for type and field names. It has been tested that
+ * hash code conflicts for the type names or the field names
+ * within the same type are virtually non-existent and, to gain performance, it is safe
+ * to work with hash codes. For the cases when hash codes for different types or fields
+ * actually do collide {@code PortableIdMapper} allows to override the automatically
+ * generated hash code IDs for the type and field names.
+ * <p>
+ * Portable ID mapper can be configured for all portable objects via {@link PortableMarshaller#getIdMapper()} method,
+ * or for a specific portable type via {@link PortableTypeConfiguration#getIdMapper()} method.
+ */
+public interface PortableIdMapper {
+ /**
+ * Gets type ID for provided class name.
+ * <p>
+ * If {@code 0} is returned, hash code of class simple name will be used.
+ *
+ * @param clsName Class name.
+ * @return Type ID.
+ */
+ public int typeId(String clsName);
+
+ /**
+ * Gets ID for provided field.
+ * <p>
+ * If {@code 0} is returned, hash code of field name will be used.
+ *
+ * @param typeId Type ID.
+ * @param fieldName Field name.
+ * @return Field ID.
+ */
+ public int fieldId(int typeId, String fieldName);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableInvalidClassException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableInvalidClassException.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableInvalidClassException.java
new file mode 100644
index 0000000..0098ec3
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableInvalidClassException.java
@@ -0,0 +1,58 @@
+/*
+ * 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.portable;
+
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Exception indicating that class needed for deserialization of portable object does not exist.
+ * <p>
+ * Thrown from {@link PortableObject#deserialize()} method.
+ */
+public class PortableInvalidClassException extends PortableException {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /**
+ * Creates invalid class exception with error message.
+ *
+ * @param msg Error message.
+ */
+ public PortableInvalidClassException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Creates invalid class exception with {@link Throwable} as a cause.
+ *
+ * @param cause Cause.
+ */
+ public PortableInvalidClassException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Creates invalid class exception with error message and {@link Throwable} as a cause.
+ *
+ * @param msg Error message.
+ * @param cause Cause.
+ */
+ public PortableInvalidClassException(String msg, @Nullable Throwable cause) {
+ super(msg, cause);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableMarshalAware.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableMarshalAware.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableMarshalAware.java
new file mode 100644
index 0000000..4270885
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableMarshalAware.java
@@ -0,0 +1,48 @@
+/*
+ * 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.portable;
+
+/**
+ * Interface that allows to implement custom serialization
+ * logic for portable objects. Portable objects are not required
+ * to implement this interface, in which case Ignite will automatically
+ * serialize portable objects using reflection.
+ * <p>
+ * This interface, in a way, is analogous to {@link java.io.Externalizable}
+ * interface, which allows users to override default serialization logic,
+ * usually for performance reasons. The only difference here is that portable
+ * serialization is already very fast and implementing custom serialization
+ * logic for portables does not provide significant performance gains.
+ */
+public interface PortableMarshalAware {
+ /**
+ * Writes fields to provided writer.
+ *
+ * @param writer Portable object writer.
+ * @throws PortableException In case of error.
+ */
+ public void writePortable(PortableWriter writer) throws PortableException;
+
+ /**
+ * Reads fields from provided reader.
+ *
+ * @param reader Portable object reader.
+ * @throws PortableException In case of error.
+ */
+ public void readPortable(PortableReader reader) throws PortableException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableMetadata.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableMetadata.java
new file mode 100644
index 0000000..4ea808b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableMetadata.java
@@ -0,0 +1,61 @@
+/*
+ * 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.portable;
+
+import java.util.Collection;
+import org.apache.ignite.IgnitePortables;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Portable type meta data. Metadata for portable types can be accessed from any of the
+ * {@link IgnitePortables#metadata(String)} methods.
+ * Having metadata also allows for proper formatting of {@code PortableObject#toString()} method,
+ * even when portable objects are kept in binary format only, which may be necessary for audit reasons.
+ */
+public interface PortableMetadata {
+ /**
+ * Gets portable type name.
+ *
+ * @return Portable type name.
+ */
+ public String typeName();
+
+ /**
+ * Gets collection of all field names for this portable type.
+ *
+ * @return Collection of all field names for this portable type.
+ */
+ public Collection<String> fields();
+
+ /**
+ * Gets name of the field type for a given field.
+ *
+ * @param fieldName Field name.
+ * @return Field type name.
+ */
+ @Nullable public String fieldTypeName(String fieldName);
+
+ /**
+ * Portable objects can optionally specify custom key-affinity mapping in the
+ * configuration. This method returns the name of the field which should be
+ * used for the key-affinity mapping.
+ *
+ * @return Affinity key field name.
+ */
+ @Nullable public String affinityKeyFieldName();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableObject.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableObject.java
new file mode 100644
index 0000000..66b8f76
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableObject.java
@@ -0,0 +1,154 @@
+/*
+ * 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.portable;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.TreeMap;
+import org.apache.ignite.IgnitePortables;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Wrapper for portable object in portable binary format. Once an object is defined as portable,
+ * Ignite will always store it in memory in the portable (i.e. binary) format.
+ * User can choose to work either with the portable format or with the deserialized form
+ * (assuming that class definitions are present in the classpath).
+ * <p>
+ * <b>NOTE:</b> user does not need to (and should not) implement this interface directly.
+ * <p>
+ * To work with the portable format directly, user should create a cache projection
+ * over {@code PortableObject} class and then retrieve individual fields as needed:
+ * <pre name=code class=java>
+ * IgniteCache<PortableObject, PortableObject> prj = cache.withKeepPortable();
+ *
+ * // Convert instance of MyKey to portable format.
+ * // We could also use GridPortableBuilder to create the key in portable format directly.
+ * PortableObject key = grid.portables().toPortable(new MyKey());
+ *
+ * PortableObject val = prj.get(key);
+ *
+ * String field = val.field("myFieldName");
+ * </pre>
+ * Alternatively, if we have class definitions in the classpath, we may choose to work with deserialized
+ * typed objects at all times. In this case we do incur the deserialization cost. However, if
+ * {@link PortableMarshaller#isKeepDeserialized()} is {@code true} then Ignite will only deserialize on the first access
+ * and will cache the deserialized object, so it does not have to be deserialized again:
+ * <pre name=code class=java>
+ * IgniteCache<MyKey.class, MyValue.class> cache = grid.cache(null);
+ *
+ * MyValue val = cache.get(new MyKey());
+ *
+ * // Normal java getter.
+ * String fieldVal = val.getMyFieldName();
+ * </pre>
+ * <h1 class="header">Working With Maps and Collections</h1>
+ * All maps and collections in the portable objects are serialized automatically. When working
+ * with different platforms, e.g. C++ or .NET, Ignite will automatically pick the most
+ * adequate collection or map in either language. For example, {@link ArrayList} in Java will become
+ * {@code List} in C#, {@link LinkedList} in Java is {@link LinkedList} in C#, {@link HashMap}
+ * in Java is {@code Dictionary} in C#, and {@link TreeMap} in Java becomes {@code SortedDictionary}
+ * in C#, etc.
+ * <h1 class="header">Dynamic Structure Changes</h1>
+ * Since objects are always cached in the portable binary format, server does not need to
+ * be aware of the class definitions. Moreover, if class definitions are not present or not
+ * used on the server, then clients can continuously change the structure of the portable
+ * objects without having to restart the cluster. For example, if one client stores a
+ * certain class with fields A and B, and another client stores the same class with
+ * fields B and C, then the server-side portable object will have the fields A, B, and C.
+ * As the structure of a portable object changes, the new fields become available for SQL queries
+ * automatically.
+ * <h1 class="header">Building Portable Objects</h1>
+ * Ignite comes with {@link PortableBuilder} which allows to build portable objects dynamically:
+ * <pre name=code class=java>
+ * PortableBuilder builder = Ignition.ignite().portables().builder("org.project.MyObject");
+ *
+ * builder.setField("fieldA", "A");
+ * builder.setField("fieldB", "B");
+ *
+ * PortableObject portableObj = builder.build();
+ * </pre>
+ * For the cases when class definition is present
+ * in the class path, it is also possible to populate a standard POJO and then
+ * convert it to portable format, like so:
+ * <pre name=code class=java>
+ * MyObject obj = new MyObject();
+ *
+ * obj.setFieldA("A");
+ * obj.setFieldB(123);
+ *
+ * PortableObject portableObj = Ignition.ignite().portables().toPortable(obj);
+ * </pre>
+ * <h1 class="header">Portable Metadata</h1>
+ * Even though Ignite portable protocol only works with hash codes for type and field names
+ * to achieve better performance, Ignite provides metadata for all portable types which
+ * can be queried ar runtime via any of the {@link IgnitePortables#metadata(Class)}
+ * methods. Having metadata also allows for proper formatting of {@code PortableObject.toString()} method,
+ * even when portable objects are kept in binary format only, which may be necessary for audit reasons.
+ */
+public interface PortableObject extends Serializable, Cloneable {
+ /**
+ * Gets portable object type ID.
+ *
+ * @return Type ID.
+ */
+ public int typeId();
+
+ /**
+ * Gets meta data for this portable object.
+ *
+ * @return Meta data.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public PortableMetadata metaData() throws PortableException;
+
+ /**
+ * Gets field value.
+ *
+ * @param fieldName Field name.
+ * @return Field value.
+ * @throws PortableException In case of any other error.
+ */
+ @Nullable public <F> F field(String fieldName) throws PortableException;
+
+ /**
+ * Checks whether field is set.
+ *
+ * @param fieldName Field name.
+ * @return {@code true} if field is set.
+ */
+ public boolean hasField(String fieldName);
+
+ /**
+ * Gets fully deserialized instance of portable object.
+ *
+ * @return Fully deserialized instance of portable object.
+ * @throws PortableInvalidClassException If class doesn't exist.
+ * @throws PortableException In case of any other error.
+ */
+ @Nullable public <T> T deserialize() throws PortableException;
+
+ /**
+ * Copies this portable object.
+ *
+ * @return Copy of this portable object.
+ */
+ public PortableObject clone() throws CloneNotSupportedException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableProtocolVersion.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableProtocolVersion.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableProtocolVersion.java
new file mode 100644
index 0000000..9189b28
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableProtocolVersion.java
@@ -0,0 +1,41 @@
+/*
+ * 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.portable;
+
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Portable protocol version.
+ */
+public enum PortableProtocolVersion {
+ /** Ignite 1.4.0 release. */
+ VER_1_4_0;
+
+ /** Enumerated values. */
+ private static final PortableProtocolVersion[] VALS = values();
+
+ /**
+ * Efficiently gets enumerated value from its ordinal.
+ *
+ * @param ord Ordinal value.
+ * @return Enumerated value or {@code null} if ordinal out of range.
+ */
+ @Nullable public static PortableProtocolVersion fromOrdinal(int ord) {
+ return ord >= 0 && ord < VALS.length ? VALS[ord] : null;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableRawReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableRawReader.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableRawReader.java
new file mode 100644
index 0000000..3bae2e1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableRawReader.java
@@ -0,0 +1,234 @@
+/*
+ * 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.portable;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Raw reader for portable objects. Raw reader does not use field name hash codes, therefore,
+ * making the format even more compact. However, if the raw reader is used,
+ * dynamic structure changes to the portable objects are not supported.
+ */
+public interface PortableRawReader {
+ /**
+ * @return Byte value.
+ * @throws PortableException In case of error.
+ */
+ public byte readByte() throws PortableException;
+
+ /**
+ * @return Short value.
+ * @throws PortableException In case of error.
+ */
+ public short readShort() throws PortableException;
+
+ /**
+ * @return Integer value.
+ * @throws PortableException In case of error.
+ */
+ public int readInt() throws PortableException;
+
+ /**
+ * @return Long value.
+ * @throws PortableException In case of error.
+ */
+ public long readLong() throws PortableException;
+
+ /**
+ * @return Float value.
+ * @throws PortableException In case of error.
+ */
+ public float readFloat() throws PortableException;
+
+ /**
+ * @return Double value.
+ * @throws PortableException In case of error.
+ */
+ public double readDouble() throws PortableException;
+
+ /**
+ * @return Char value.
+ * @throws PortableException In case of error.
+ */
+ public char readChar() throws PortableException;
+
+ /**
+ * @return Boolean value.
+ * @throws PortableException In case of error.
+ */
+ public boolean readBoolean() throws PortableException;
+
+ /**
+ * @return Decimal value.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public BigDecimal readDecimal() throws PortableException;
+
+ /**
+ * @return String value.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public String readString() throws PortableException;
+
+ /**
+ * @return UUID.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public UUID readUuid() throws PortableException;
+
+ /**
+ * @return Date.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public Date readDate() throws PortableException;
+
+ /**
+ * @return Timestamp.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public Timestamp readTimestamp() throws PortableException;
+
+ /**
+ * @return Object.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <T> T readObject() throws PortableException;
+
+ /**
+ * @return Byte array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public byte[] readByteArray() throws PortableException;
+
+ /**
+ * @return Short array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public short[] readShortArray() throws PortableException;
+
+ /**
+ * @return Integer array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public int[] readIntArray() throws PortableException;
+
+ /**
+ * @return Long array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public long[] readLongArray() throws PortableException;
+
+ /**
+ * @return Float array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public float[] readFloatArray() throws PortableException;
+
+ /**
+ * @return Byte array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public double[] readDoubleArray() throws PortableException;
+
+ /**
+ * @return Char array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public char[] readCharArray() throws PortableException;
+
+ /**
+ * @return Boolean array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public boolean[] readBooleanArray() throws PortableException;
+
+ /**
+ * @return Decimal array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public BigDecimal[] readDecimalArray() throws PortableException;
+
+ /**
+ * @return String array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public String[] readStringArray() throws PortableException;
+
+ /**
+ * @return UUID array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public UUID[] readUuidArray() throws PortableException;
+
+ /**
+ * @return Date array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public Date[] readDateArray() throws PortableException;
+
+ /**
+ * @return Object array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public Object[] readObjectArray() throws PortableException;
+
+ /**
+ * @return Collection.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <T> Collection<T> readCollection() throws PortableException;
+
+ /**
+ * @param colCls Collection class.
+ * @return Collection.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <T> Collection<T> readCollection(Class<? extends Collection<T>> colCls)
+ throws PortableException;
+
+ /**
+ * @return Map.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <K, V> Map<K, V> readMap() throws PortableException;
+
+ /**
+ * @param mapCls Map class.
+ * @return Map.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <K, V> Map<K, V> readMap(Class<? extends Map<K, V>> mapCls) throws PortableException;
+
+ /**
+ * @return Value.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <T extends Enum<?>> T readEnum() throws PortableException;
+
+ /**
+ * @return Value.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <T extends Enum<?>> T[] readEnumArray() throws PortableException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableRawWriter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableRawWriter.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableRawWriter.java
new file mode 100644
index 0000000..53f4f92
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableRawWriter.java
@@ -0,0 +1,219 @@
+/*
+ * 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.portable;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Raw writer for portable object. Raw writer does not write field name hash codes, therefore,
+ * making the format even more compact. However, if the raw writer is used,
+ * dynamic structure changes to the portable objects are not supported.
+ */
+public interface PortableRawWriter {
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeByte(byte val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeShort(short val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeInt(int val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeLong(long val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeFloat(float val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeDouble(double val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeChar(char val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeBoolean(boolean val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeDecimal(@Nullable BigDecimal val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeString(@Nullable String val) throws PortableException;
+
+ /**
+ * @param val UUID to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeUuid(@Nullable UUID val) throws PortableException;
+
+ /**
+ * @param val Date to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeDate(@Nullable Date val) throws PortableException;
+
+ /**
+ * @param val Timestamp to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeTimestamp(@Nullable Timestamp val) throws PortableException;
+
+ /**
+ * @param obj Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeObject(@Nullable Object obj) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeByteArray(@Nullable byte[] val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeShortArray(@Nullable short[] val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeIntArray(@Nullable int[] val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeLongArray(@Nullable long[] val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeFloatArray(@Nullable float[] val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeDoubleArray(@Nullable double[] val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeCharArray(@Nullable char[] val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeBooleanArray(@Nullable boolean[] val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeDecimalArray(@Nullable BigDecimal[] val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeStringArray(@Nullable String[] val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeUuidArray(@Nullable UUID[] val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeDateArray(@Nullable Date[] val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public void writeObjectArray(@Nullable Object[] val) throws PortableException;
+
+ /**
+ * @param col Collection to write.
+ * @throws PortableException In case of error.
+ */
+ public <T> void writeCollection(@Nullable Collection<T> col) throws PortableException;
+
+ /**
+ * @param map Map to write.
+ * @throws PortableException In case of error.
+ */
+ public <K, V> void writeMap(@Nullable Map<K, V> map) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public <T extends Enum<?>> void writeEnum(T val) throws PortableException;
+
+ /**
+ * @param val Value to write.
+ * @throws PortableException In case of error.
+ */
+ public <T extends Enum<?>> void writeEnumArray(T[] val) throws PortableException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableReader.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableReader.java
new file mode 100644
index 0000000..58f078d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableReader.java
@@ -0,0 +1,284 @@
+/*
+ * 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.portable;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Reader for portable objects used in {@link PortableMarshalAware} implementations.
+ * Useful for the cases when user wants a fine-grained control over serialization.
+ * <p>
+ * Note that Ignite never writes full strings for field or type names. Instead,
+ * for performance reasons, Ignite writes integer hash codes for type and field names.
+ * It has been tested that hash code conflicts for the type names or the field names
+ * within the same type are virtually non-existent and, to gain performance, it is safe
+ * to work with hash codes. For the cases when hash codes for different types or fields
+ * actually do collide, Ignite provides {@link PortableIdMapper} which
+ * allows to override the automatically generated hash code IDs for the type and field names.
+ */
+public interface PortableReader {
+ /**
+ * @param fieldName Field name.
+ * @return Byte value.
+ * @throws PortableException In case of error.
+ */
+ public byte readByte(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Short value.
+ * @throws PortableException In case of error.
+ */
+ public short readShort(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Integer value.
+ * @throws PortableException In case of error.
+ */
+ public int readInt(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Long value.
+ * @throws PortableException In case of error.
+ */
+ public long readLong(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @throws PortableException In case of error.
+ * @return Float value.
+ */
+ public float readFloat(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Double value.
+ * @throws PortableException In case of error.
+ */
+ public double readDouble(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Char value.
+ * @throws PortableException In case of error.
+ */
+ public char readChar(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Boolean value.
+ * @throws PortableException In case of error.
+ */
+ public boolean readBoolean(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Decimal value.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public BigDecimal readDecimal(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return String value.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public String readString(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return UUID.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public UUID readUuid(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Date.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public Date readDate(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Timestamp.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public Timestamp readTimestamp(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Object.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <T> T readObject(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Byte array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public byte[] readByteArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Short array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public short[] readShortArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Integer array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public int[] readIntArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Long array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public long[] readLongArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Float array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public float[] readFloatArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Byte array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public double[] readDoubleArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Char array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public char[] readCharArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Boolean array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public boolean[] readBooleanArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Decimal array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public BigDecimal[] readDecimalArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return String array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public String[] readStringArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return UUID array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public UUID[] readUuidArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Date array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public Date[] readDateArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Object array.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public Object[] readObjectArray(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Collection.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <T> Collection<T> readCollection(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param colCls Collection class.
+ * @return Collection.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <T> Collection<T> readCollection(String fieldName, Class<? extends Collection<T>> colCls)
+ throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Map.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <K, V> Map<K, V> readMap(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @param mapCls Map class.
+ * @return Map.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <K, V> Map<K, V> readMap(String fieldName, Class<? extends Map<K, V>> mapCls)
+ throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Value.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <T extends Enum<?>> T readEnum(String fieldName) throws PortableException;
+
+ /**
+ * @param fieldName Field name.
+ * @return Value.
+ * @throws PortableException In case of error.
+ */
+ @Nullable public <T extends Enum<?>> T[] readEnumArray(String fieldName) throws PortableException;
+
+ /**
+ * Gets raw reader. Raw reader does not use field name hash codes, therefore,
+ * making the format even more compact. However, if the raw reader is used,
+ * dynamic structure changes to the portable objects are not supported.
+ *
+ * @return Raw reader.
+ */
+ public PortableRawReader rawReader();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableSerializer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableSerializer.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableSerializer.java
new file mode 100644
index 0000000..90ee562
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableSerializer.java
@@ -0,0 +1,49 @@
+/*
+ * 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.portable;
+
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ * Interface that allows to implement custom serialization logic for portable objects.
+ * Can be used instead of {@link PortableMarshalAware} in case if the class
+ * cannot be changed directly.
+ * <p>
+ * Portable serializer can be configured for all portable objects via
+ * {@link PortableMarshaller#getSerializer()} method, or for a specific
+ * portable type via {@link PortableTypeConfiguration#getSerializer()} method.
+ */
+public interface PortableSerializer {
+ /**
+ * Writes fields to provided writer.
+ *
+ * @param obj Empty object.
+ * @param writer Portable object writer.
+ * @throws PortableException In case of error.
+ */
+ public void writePortable(Object obj, PortableWriter writer) throws PortableException;
+
+ /**
+ * Reads fields from provided reader.
+ *
+ * @param obj Empty object
+ * @param reader Portable object reader.
+ * @throws PortableException In case of error.
+ */
+ public void readPortable(Object obj, PortableReader reader) throws PortableException;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/e7eb2b37/modules/core/src/main/java/org/apache/ignite/portable/PortableTypeConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/portable/PortableTypeConfiguration.java b/modules/core/src/main/java/org/apache/ignite/portable/PortableTypeConfiguration.java
new file mode 100644
index 0000000..5e6e09d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/portable/PortableTypeConfiguration.java
@@ -0,0 +1,196 @@
+/*
+ * 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.portable;
+
+import java.sql.Timestamp;
+import java.util.Collection;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.marshaller.portable.PortableMarshaller;
+
+/**
+ * Defines configuration properties for a specific portable type. Providing per-type
+ * configuration is optional, as it is generally enough, and also optional, to provide global portable
+ * configuration using {@link PortableMarshaller#setClassNames(Collection)}.
+ * However, this class allows you to change configuration properties for a specific
+ * portable type without affecting configuration for other portable types.
+ * <p>
+ * Per-type portable configuration can be specified in {@link PortableMarshaller#getTypeConfigurations()} method.
+ */
+public class PortableTypeConfiguration {
+ /** Class name. */
+ private String clsName;
+
+ /** ID mapper. */
+ private PortableIdMapper idMapper;
+
+ /** Serializer. */
+ private PortableSerializer serializer;
+
+ /** Use timestamp flag. */
+ private Boolean useTs;
+
+ /** Meta data enabled flag. */
+ private Boolean metaDataEnabled;
+
+ /** Keep deserialized flag. */
+ private Boolean keepDeserialized;
+
+ /** Affinity key field name. */
+ private String affKeyFieldName;
+
+ /**
+ */
+ public PortableTypeConfiguration() {
+ // No-op.
+ }
+
+ /**
+ * @param clsName Class name.
+ */
+ public PortableTypeConfiguration(String clsName) {
+ this.clsName = clsName;
+ }
+
+ /**
+ * Gets type name.
+ *
+ * @return Type name.
+ */
+ public String getClassName() {
+ return clsName;
+ }
+
+ /**
+ * Sets type name.
+ *
+ * @param clsName Type name.
+ */
+ public void setClassName(String clsName) {
+ this.clsName = clsName;
+ }
+
+ /**
+ * Gets ID mapper.
+ *
+ * @return ID mapper.
+ */
+ public PortableIdMapper getIdMapper() {
+ return idMapper;
+ }
+
+ /**
+ * Sets ID mapper.
+ *
+ * @param idMapper ID mapper.
+ */
+ public void setIdMapper(PortableIdMapper idMapper) {
+ this.idMapper = idMapper;
+ }
+
+ /**
+ * Gets serializer.
+ *
+ * @return Serializer.
+ */
+ public PortableSerializer getSerializer() {
+ return serializer;
+ }
+
+ /**
+ * Sets serializer.
+ *
+ * @param serializer Serializer.
+ */
+ public void setSerializer(PortableSerializer serializer) {
+ this.serializer = serializer;
+ }
+
+ /**
+ * If {@code true} then date values converted to {@link Timestamp} during unmarshalling.
+ *
+ * @return Flag indicating whether date values converted to {@link Timestamp} during unmarshalling.
+ */
+ public Boolean isUseTimestamp() {
+ return useTs;
+ }
+
+ /**
+ * @param useTs Flag indicating whether date values converted to {@link Timestamp} during unmarshalling.
+ */
+ public void setUseTimestamp(Boolean useTs) {
+ this.useTs = useTs;
+ }
+
+ /**
+ * Defines whether meta data is collected for this type. If provided, this value will override
+ * {@link PortableMarshaller#isMetaDataEnabled()} property.
+ *
+ * @return Whether meta data is collected.
+ */
+ public Boolean isMetaDataEnabled() {
+ return metaDataEnabled;
+ }
+
+ /**
+ * @param metaDataEnabled Whether meta data is collected.
+ */
+ public void setMetaDataEnabled(Boolean metaDataEnabled) {
+ this.metaDataEnabled = metaDataEnabled;
+ }
+
+ /**
+ * Defines whether {@link PortableObject} should cache deserialized instance. If provided,
+ * this value will override {@link PortableMarshaller#isKeepDeserialized()}
+ * property.
+ *
+ * @return Whether deserialized value is kept.
+ */
+ public Boolean isKeepDeserialized() {
+ return keepDeserialized;
+ }
+
+ /**
+ * @param keepDeserialized Whether deserialized value is kept.
+ */
+ public void setKeepDeserialized(Boolean keepDeserialized) {
+ this.keepDeserialized = keepDeserialized;
+ }
+
+ /**
+ * Gets affinity key field name.
+ *
+ * @return Affinity key field name.
+ */
+ public String getAffinityKeyFieldName() {
+ return affKeyFieldName;
+ }
+
+ /**
+ * Sets affinity key field name.
+ *
+ * @param affKeyFieldName Affinity key field name.
+ */
+ public void setAffinityKeyFieldName(String affKeyFieldName) {
+ this.affKeyFieldName = affKeyFieldName;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(PortableTypeConfiguration.class, this, super.toString());
+ }
+}
\ No newline at end of file