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/14 16:20:38 UTC
[1/4] ignite git commit: ignite-1462: cleaning imports and removing
additional tests
Repository: ignite
Updated Branches:
refs/heads/ignite-1462 b69064085 -> feac1ec26
http://git-wip-us.apache.org/repos/asf/ignite/blob/feac1ec2/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
deleted file mode 100644
index 825d678..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataDisabledSelfTest.java
+++ /dev/null
@@ -1,238 +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;
-
-import java.util.Arrays;
-import org.apache.ignite.internal.portable.api.IgnitePortables;
-import org.apache.ignite.configuration.IgniteConfiguration;
-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.PortableMarshalAware;
-import org.apache.ignite.internal.portable.api.PortableReader;
-import org.apache.ignite.internal.portable.api.PortableTypeConfiguration;
-import org.apache.ignite.internal.portable.api.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/feac1ec2/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
deleted file mode 100644
index bec70cb..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java
+++ /dev/null
@@ -1,371 +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;
-
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import org.apache.ignite.internal.portable.api.IgnitePortables;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.portable.api.PortableMarshaller;
-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.PortableObject;
-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.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/feac1ec2/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
deleted file mode 100644
index 25ff7d0..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
+++ /dev/null
@@ -1,482 +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;
-
-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.internal.portable.api.PortableMarshaller;
-import org.apache.ignite.internal.portable.api.PortableIdMapper;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.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/feac1ec2/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.java
deleted file mode 100644
index 53d84a1..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableMarshalerAwareTestClass.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.portable.mutabletest;
-
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.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.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/feac1ec2/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
deleted file mode 100644
index 13f51ba..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
+++ /dev/null
@@ -1,434 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.portable.mutabletest;
-
-import 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.internal.portable.api.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/feac1ec2/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
deleted file mode 100644
index daa13d5..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/package-info.java
+++ /dev/null
@@ -1,22 +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 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/feac1ec2/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
deleted file mode 100644
index 26897e6..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/package-info.java
+++ /dev/null
@@ -1,22 +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 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/feac1ec2/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
deleted file mode 100644
index 05a8c33..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass1.java
+++ /dev/null
@@ -1,28 +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.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/feac1ec2/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
deleted file mode 100644
index ba69991..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass2.java
+++ /dev/null
@@ -1,24 +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.test;
-
-/**
- */
-public class GridPortableTestClass2 {
- // No-op.
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/feac1ec2/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
deleted file mode 100644
index e63b814..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/package-info.java
+++ /dev/null
@@ -1,22 +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 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/feac1ec2/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
deleted file mode 100644
index cf3aa2d..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/GridPortableTestClass3.java
+++ /dev/null
@@ -1,24 +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.test.subpackage;
-
-/**
- */
-public class GridPortableTestClass3 {
- // No-op.
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/feac1ec2/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
deleted file mode 100644
index ae8ee73..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/package-info.java
+++ /dev/null
@@ -1,22 +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 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/feac1ec2/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 6299fe8..964753d 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,7 +35,6 @@ import org.apache.ignite.IgniteEvents;
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.IgniteQueue;
import org.apache.ignite.IgniteScheduler;
import org.apache.ignite.IgniteServices;
@@ -334,4 +333,4 @@ public class IgniteMock implements Ignite {
public void setStaticCfg(IgniteConfiguration staticCfg) {
this.staticCfg = staticCfg;
}
-}
\ No newline at end of file
+}
[4/4] ignite git commit: ignite-1462: cleaning imports and removing
additional tests
Posted by sb...@apache.org.
ignite-1462: cleaning imports and removing additional tests
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/feac1ec2
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/feac1ec2
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/feac1ec2
Branch: refs/heads/ignite-1462
Commit: feac1ec26dea3bb33d364dfe250de00bc04fcaf4
Parents: b690640
Author: Denis Magda <dm...@gridgain.com>
Authored: Mon Sep 14 17:20:28 2015 +0300
Committer: Denis Magda <dm...@gridgain.com>
Committed: Mon Sep 14 17:20:28 2015 +0300
----------------------------------------------------------------------
.../java/org/apache/ignite/IgniteCache.java | 6 +-
.../configuration/CacheConfiguration.java | 29 +-
.../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 -
.../ignite/testframework/junits/IgniteMock.java | 3 +-
22 files changed, 19 insertions(+), 8359 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/feac1ec2/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 e5abbb4..5558a26 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
@@ -18,12 +18,9 @@
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;
@@ -55,7 +52,6 @@ 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.internal.portable.api.PortableMarshaller;
import org.apache.ignite.mxbean.CacheMetricsMXBean;
import org.jetbrains.annotations.Nullable;
@@ -623,4 +619,4 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
* @return MxBean.
*/
public CacheMetricsMXBean mxBean();
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/feac1ec2/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 59058f8..7d1e14d 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,10 +17,24 @@
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.IgniteException;
-import org.apache.ignite.cache.*;
+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.cache.affinity.AffinityFunction;
import org.apache.ignite.cache.affinity.AffinityKeyMapper;
import org.apache.ignite.cache.eviction.EvictionFilter;
@@ -36,15 +50,6 @@ 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
@@ -1819,4 +1824,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/feac1ec2/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
deleted file mode 100644
index 36b43f6..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
+++ /dev/null
@@ -1,218 +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;
-
-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.internal.portable.api.PortableMarshaller;
-import org.apache.ignite.internal.portable.api.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/feac1ec2/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
deleted file mode 100644
index 6b9751a..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderAdditionalSelfTest.java
+++ /dev/null
@@ -1,1226 +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;
-
-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.internal.portable.api.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.internal.portable.api.PortableMarshaller;
-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.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
http://git-wip-us.apache.org/repos/asf/ignite/blob/feac1ec2/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
deleted file mode 100644
index bceec9d..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderSelfTest.java
+++ /dev/null
@@ -1,1021 +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;
-
-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.internal.portable.api.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.internal.portable.api.PortableMarshaller;
-import org.apache.ignite.internal.portable.api.PortableBuilder;
-import org.apache.ignite.internal.portable.api.PortableIdMapper;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.PortableObject;
-import org.apache.ignite.internal.portable.api.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/feac1ec2/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
deleted file mode 100644
index 2fce1a5..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsAdditionalSelfTest.java
+++ /dev/null
@@ -1,28 +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;
-
-/**
- *
- */
-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/feac1ec2/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
deleted file mode 100644
index 5c53233..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableBuilderStringAsCharsSelfTest.java
+++ /dev/null
@@ -1,28 +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;
-
-/**
- * Portable builder test.
- */
-public class GridPortableBuilderStringAsCharsSelfTest extends GridPortableBuilderSelfTest {
- /** {@inheritDoc} */
- @Override protected boolean useUtf8() {
- return false;
- }
-}
\ No newline at end of file
[3/4] ignite git commit: ignite-1462: cleaning imports and removing
additional tests
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/feac1ec2/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
deleted file mode 100644
index 71a11b1..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java
+++ /dev/null
@@ -1,256 +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;
-
-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.internal.portable.api.PortableMarshaller;
-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.PortableReader;
-import org.apache.ignite.internal.portable.api.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
[2/4] ignite git commit: ignite-1462: cleaning imports and removing
additional tests
Posted by sb...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/feac1ec2/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
deleted file mode 100644
index dc16c94..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerSelfTest.java
+++ /dev/null
@@ -1,3807 +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;
-
-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.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.PortableIdMapper;
-import org.apache.ignite.internal.portable.api.PortableInvalidClassException;
-import org.apache.ignite.internal.portable.api.PortableMarshalAware;
-import org.apache.ignite.internal.portable.api.PortableMetadata;
-import org.apache.ignite.internal.portable.api.PortableObject;
-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.PortableSerializer;
-import org.apache.ignite.internal.portable.api.PortableTypeConfiguration;
-import org.apache.ignite.internal.portable.api.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(
<TRUNCATED>