Repository: ignite Updated Branches: refs/heads/ignite-2099 a2e18c786 -> 406ba755e
IGNITE-2099: Test for initial problem. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/810acd46 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/810acd46 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/810acd46 Branch: refs/heads/ignite-2099 Commit: 810acd46fb5d05f1cd536186eb49ac89a11c53ff Parents: a2e18c7 Author: vozerov-gridgain <[email protected]> Authored: Thu Dec 10 11:32:16 2015 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Thu Dec 10 11:32:16 2015 +0300 ---------------------------------------------------------------------- .../portable/BinaryMarshallerSelfTest.java | 84 ++++++++++++++++++++ 1 file changed, 84 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/810acd46/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryMarshallerSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryMarshallerSelfTest.java index 5a60bac..037adf9 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryMarshallerSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryMarshallerSelfTest.java @@ -51,7 +51,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListSet; import junit.framework.Assert; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.binary.BinaryCollectionFactory; import org.apache.ignite.binary.BinaryIdMapper; +import org.apache.ignite.binary.BinaryMapFactory; import org.apache.ignite.binary.BinaryObject; import org.apache.ignite.binary.BinaryObjectBuilder; import org.apache.ignite.binary.BinaryObjectException; @@ -407,6 +409,27 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest { } /** + * Test custom collections with factories. + * + * @throws Exception If failed. + */ + @SuppressWarnings("unchecked") + public void testCustomCollectionsWithFactory() throws Exception { + CustomCollectionsWithFactory cc = new CustomCollectionsWithFactory(); + + cc.list.add(new DummyHolder(1)); + cc.map.put(new DummyHolder(2), new DummyHolder(3)); + + CustomCollectionsWithFactory copiedCc = marshalUnmarshal(cc); + + assertEquals(cc.list.size(), copiedCc.list.size()); + assertEquals(cc.map.size(), copiedCc.map.size()); + + assertEquals(cc.list.get(0), copiedCc.list.get(0)); + assertEquals(cc.map.get(new DummyHolder(2)), copiedCc.map.get(new DummyHolder(2))); + } + + /** * @throws Exception If failed. */ public void testExternalizableHashCode() throws Exception { @@ -3491,6 +3514,13 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest { } /** + * Custom hash map. + */ + private static class CustomHashMap extends HashMap { + // No-op. + } + + /** * Holder for non-stadard collections. */ private static class CustomCollections { @@ -3498,6 +3528,60 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest { public List customList = new CustomArrayList(); } + @SuppressWarnings("unchecked") + private static class CustomCollectionsWithFactory implements Binarylizable { + public List list = new CustomArrayList(); + public Map map = new CustomHashMap(); + + /** {@inheritDoc} */ + @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException { + writer.writeCollection("list", list); + writer.writeMap("map", map); + } + + /** {@inheritDoc} */ + @Override public void readBinary(BinaryReader reader) throws BinaryObjectException { + list = (List)reader.readCollection("list", new BinaryCollectionFactory<Object>() { + @Override public Collection<Object> create(int size) { + return new CustomArrayList(); + } + }); + + map = reader.readMap("map", new BinaryMapFactory<Object, Object>() { + @Override public Map<Object, Object> create(int size) { + return new CustomHashMap(); + } + }); + } + } + + /** + * Dummy value holder. + */ + private static class DummyHolder { + /** Value. */ + public int val; + + /** + * Constructor. + * + * @param val Value. + */ + public DummyHolder(int val) { + this.val = val; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + return o != null && o instanceof DummyHolder && ((DummyHolder)o).val == val; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return val; + } + } + /** */ private static class CycleLinkObject {
