From b7788ba23876ba270abfe553b02c1145b73fcd43 Mon Sep 17 00:00:00 2001 From: tledkov-gridgain Date: Thu, 5 May 2016 11:43:40 +0300 Subject: [PATCH 01/12] stabilization: GridUnsafeDataOutputArraySizingSelfTest --- ...idUnsafeDataOutputArraySizingSelfTest.java | 137 ++++++++---------- 1 file changed, 61 insertions(+), 76 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java index 2e56bde915d3f..60ec7e42db165 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java @@ -17,6 +17,8 @@ package org.apache.ignite.internal.util.io; +import org.apache.ignite.internal.util.lang.GridAbsPredicate; +import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import static org.apache.ignite.IgniteSystemProperties.IGNITE_MARSHAL_BUFFERS_RECHECK; @@ -31,8 +33,14 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT /** Big array. */ private static final byte[] BIG = new byte[2048]; + /** Buffer timeout. */ + private static final long BUFFER_TIMEOUT = 1000; + + /** Wait timeout is bigger then buffer timeout to prevent failures due to time measurement error */ + private static final long WAIT_BUFFER_TIMEOUT = BUFFER_TIMEOUT + BUFFER_TIMEOUT / 2; + static { - System.setProperty(IGNITE_MARSHAL_BUFFERS_RECHECK, "1000"); + System.setProperty(IGNITE_MARSHAL_BUFFERS_RECHECK, Long.toString(BUFFER_TIMEOUT)); } /** @@ -40,39 +48,13 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT */ @SuppressWarnings("BusyWait") public void testSmall() throws Exception { - GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - - for (int i = 0; i < 11; i++) { - Thread.sleep(100); - - writeSmall(out); - } + final GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - assertEquals(256, out.internalArray().length); - - for (int i = 0; i < 11; i++) { - Thread.sleep(100); - - writeSmall(out); - } - - assertEquals(128, out.internalArray().length); - - for (int i = 0; i < 11; i++) { - Thread.sleep(100); - - writeSmall(out); - } - - assertEquals(64, out.internalArray().length); - - for (int i = 0; i < 11; i++) { - Thread.sleep(100); - - writeSmall(out); - } - - assertEquals(64, out.internalArray().length); + assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 256), WAIT_BUFFER_TIMEOUT)); + assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 128), WAIT_BUFFER_TIMEOUT)); + assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 64), WAIT_BUFFER_TIMEOUT)); + assertFalse(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 32), WAIT_BUFFER_TIMEOUT)); + assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 64), WAIT_BUFFER_TIMEOUT)); } /** @@ -81,7 +63,8 @@ public void testSmall() throws Exception { public void testBig() throws Exception { GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - writeBig(out); + out.write(BIG); + out.reset(); assertEquals(4096, out.internalArray().length); } @@ -96,8 +79,10 @@ public void testChanged1() throws Exception { for (int i = 0; i < 100; i++) { Thread.sleep(100); - writeSmall(out); - writeBig(out); + out.write(SMALL); + out.reset(); + out.write(BIG); + out.reset(); } assertEquals(4096, out.internalArray().length); @@ -108,54 +93,54 @@ public void testChanged1() throws Exception { */ @SuppressWarnings("BusyWait") public void testChanged2() throws Exception { - GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - - for (int i = 0; i < 11; i++) { - Thread.sleep(100); + final GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - writeSmall(out); - } - - assertEquals(256, out.internalArray().length); - - writeBig(out); - - assertEquals(4096, out.internalArray().length); - - for (int i = 0; i < 11; i++) { - Thread.sleep(100); - - writeSmall(out); - } + assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 256), WAIT_BUFFER_TIMEOUT)); + out.write(BIG); + out.reset(); assertEquals(4096, out.internalArray().length); - for (int i = 0; i < 11; i++) { - Thread.sleep(100); - - writeSmall(out); - } - - assertEquals(2048, out.internalArray().length); + assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 4096), WAIT_BUFFER_TIMEOUT)); + assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 2048), 2 * WAIT_BUFFER_TIMEOUT)); } /** - * @param out Output. - * @throws Exception If failed. + * */ - private void writeSmall(GridUnsafeDataOutput out) throws Exception { - out.write(SMALL); - - out.reset(); - } - - /** - * @param out Output. - * @throws Exception If failed. - */ - private void writeBig(GridUnsafeDataOutput out) throws Exception { - out.write(BIG); + private static class WriteAndCheckPredicate implements GridAbsPredicate { + final GridUnsafeDataOutput out; + final byte [] bytes; + final int length; + + /** + * @param out Out. + * @param bytes Bytes. + * @param length Length. + */ + WriteAndCheckPredicate(GridUnsafeDataOutput out, byte[] bytes, int length) { + this.out = out; + this.bytes = bytes; + this.length = length; + } - out.reset(); + /** + * {@inheritDoc} + */ + @Override public boolean apply() { + try { + out.write(bytes); + out.reset(); + + System.out.println("L="+out.internalArray().length); + if(out.internalArray().length == length) + return true; + return false; + } + catch (Exception e) { + assertTrue("Unexpected exception: " + e.getMessage(), false); + return false; + } + } } } \ No newline at end of file From 95bcf6c270cfcb00efcc9c13bfe7687e78b00eb3 Mon Sep 17 00:00:00 2001 From: tledkov-gridgain Date: Thu, 5 May 2016 13:28:29 +0300 Subject: [PATCH 02/12] fix:GridMessageListenSelfTest --- .../continuous/GridMessageListenSelfTest.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridMessageListenSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridMessageListenSelfTest.java index ea18f69f5a9fa..1264eecb85b88 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridMessageListenSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridMessageListenSelfTest.java @@ -341,7 +341,7 @@ public void testNonNullTopicWithDeployment() throws Exception { public void testListenActor() throws Exception { latch = new CountDownLatch(MSG_CNT * (GRID_CNT + 1)); - grid(0).message().remoteListen(null, new Actor(grid(0).cluster())); + grid(0).message().remoteListen(null, new Actor(grid(0).localNode().id())); try { Ignite g = startGrid("anotherGrid"); @@ -376,7 +376,7 @@ public void testListenActor() throws Exception { private void listen(final ClusterGroup prj, @Nullable Object topic, final boolean ret) throws Exception { assert prj != null; - message(prj).remoteListen(topic, new Listener(prj, ret)); + message(prj).remoteListen(topic, new Listener(grid(0).localNode().id(), ret)); } /** @@ -428,23 +428,21 @@ private void checkNodes(List expNodes) { /** */ private static class Listener implements P2 { - /** */ - private final ClusterGroup prj; - + /** Source node id. */ + private final UUID sourceNodeId; /** */ private final boolean ret; - /** */ @IgniteInstanceResource private Ignite ignite; /** - * @param prj Projection. * @param ret Return value. + * @param sourceNodeId expected source node id */ - private Listener(ClusterGroup prj, boolean ret) { - this.prj = prj; + private Listener(UUID sourceNodeId, boolean ret) { this.ret = ret; + this.sourceNodeId = sourceNodeId; } /** {@inheritDoc} */ @@ -454,7 +452,7 @@ private Listener(ClusterGroup prj, boolean ret) { X.println("Received message [nodeId=" + nodeId + ", locNodeId=" + ignite.cluster().localNode().id() + ']'); - assertEquals(prj.ignite().cluster().localNode().id(), nodeId); + assertEquals(sourceNodeId, nodeId); assertEquals(MSG, msg); nodes.add(ignite.configuration().getNodeId()); @@ -467,14 +465,14 @@ private Listener(ClusterGroup prj, boolean ret) { /** */ private static class Actor extends MessagingListenActor { - /** */ - private final ClusterGroup prj; + /** Source node id. */ + private final UUID sourceNodeId; /** - * @param prj Projection. + * @param sourceNodeId expected source node id */ - private Actor(ClusterGroup prj) { - this.prj = prj; + private Actor(UUID sourceNodeId) { + this.sourceNodeId = sourceNodeId; } /** {@inheritDoc} */ @@ -485,7 +483,7 @@ private Actor(ClusterGroup prj) { X.println("Received message [nodeId=" + nodeId + ", locNodeId=" + locNodeId + ']'); - assertEquals(prj.ignite().cluster().localNode().id(), nodeId); + assertEquals(sourceNodeId, nodeId); assertEquals(MSG, msg); nodes.add(locNodeId); From 098405dfe5315fff65ff3e056fc1ce9ea98aac60 Mon Sep 17 00:00:00 2001 From: sboikov Date: Thu, 5 May 2016 16:49:45 +0300 Subject: [PATCH 03/12] Minor. --- ...idUnsafeDataOutputArraySizingSelfTest.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java index 60ec7e42db165..410877924257b 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java @@ -36,9 +36,12 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT /** Buffer timeout. */ private static final long BUFFER_TIMEOUT = 1000; - /** Wait timeout is bigger then buffer timeout to prevent failures due to time measurement error */ + /** Wait timeout is bigger then buffer timeout to prevent failures due to time measurement error. */ private static final long WAIT_BUFFER_TIMEOUT = BUFFER_TIMEOUT + BUFFER_TIMEOUT / 2; + /** + * + */ static { System.setProperty(IGNITE_MARSHAL_BUFFERS_RECHECK, Long.toString(BUFFER_TIMEOUT)); } @@ -109,19 +112,24 @@ public void testChanged2() throws Exception { * */ private static class WriteAndCheckPredicate implements GridAbsPredicate { + /** */ final GridUnsafeDataOutput out; + + /** */ final byte [] bytes; - final int length; + + /** */ + final int len; /** * @param out Out. * @param bytes Bytes. - * @param length Length. + * @param len Length. */ - WriteAndCheckPredicate(GridUnsafeDataOutput out, byte[] bytes, int length) { + WriteAndCheckPredicate(GridUnsafeDataOutput out, byte[] bytes, int len) { this.out = out; this.bytes = bytes; - this.length = length; + this.len = len; } /** @@ -132,10 +140,9 @@ private static class WriteAndCheckPredicate implements GridAbsPredicate { out.write(bytes); out.reset(); - System.out.println("L="+out.internalArray().length); - if(out.internalArray().length == length) - return true; - return false; + System.out.println("L=" + out.internalArray().length); + + return out.internalArray().length == len; } catch (Exception e) { assertTrue("Unexpected exception: " + e.getMessage(), false); From ffb68ee3beb5bb539b03b62d18cc321fcf04c9bc Mon Sep 17 00:00:00 2001 From: tledkov-gridgain Date: Thu, 5 May 2016 17:18:04 +0300 Subject: [PATCH 04/12] fix:GridTaskExecutionSelfTest --- .../internal/GridTaskExecutionSelfTest.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskExecutionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridTaskExecutionSelfTest.java index 142b9db1c20ea..d6d7c42a37010 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/GridTaskExecutionSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/GridTaskExecutionSelfTest.java @@ -45,27 +45,34 @@ public GridTaskExecutionSelfTest() { super(false); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override protected void beforeTestsStarted() throws Exception { - ignite = startGrid(1); - + startGrid(1); startGrid(2); startGrid(3); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override protected void afterTestsStopped() throws Exception { - stopGrid(1); - stopGrid(2); - stopGrid(3); + stopAllGrids(); + } - ignite = null; + /** + * {@inheritDoc} + */ + @Override protected void beforeTest() throws Exception { + ignite = grid(1); } /** * @throws Exception If failed. */ public void testSynchronousExecute() throws Exception { + IgniteCompute comp = ignite.compute().withAsync(); assertNull(comp.execute(GridTestTask.class, "testArg")); From ad3ffebc222847ae2ea941c2fb8231d7e49e4f9c Mon Sep 17 00:00:00 2001 From: tledkov-gridgain Date: Fri, 6 May 2016 14:39:31 +0300 Subject: [PATCH 05/12] fix racing that is detected by GridCacheStoreManagerDeserializationTest --- .../dht/preloader/GridDhtPartitionsExchangeFuture.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java index 82e9bda91783f..c6d1a7aa1368c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java @@ -1072,10 +1072,11 @@ private void sendPartitions(ClusterNode oldestNode) { cacheValidRes = m != null ? m : Collections.emptyMap(); } - cctx.cache().onExchangeDone(exchId.topologyVersion(), reqs, err); - + // Update exchange before cache to prevent racing after cache creation. cctx.exchange().onExchangeDone(this, err); + cctx.cache().onExchangeDone(exchId.topologyVersion(), reqs, err); + if (super.onDone(res, err) && realExchange) { if (log.isDebugEnabled()) log.debug("Completed partition exchange [localNode=" + cctx.localNodeId() + ", exchange= " + this + From 3cbdba352474f90ed21a5824ccc4a1d090395fae Mon Sep 17 00:00:00 2001 From: tledkov-gridgain Date: Tue, 10 May 2016 11:47:22 +0300 Subject: [PATCH 06/12] hotfix the test that depends on IGNITE-3099 Race condition on the order of events --- ...ridEventStorageCheckAllEventsSelfTest.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java index c3f77c7c6a86d..5eb75035c4c02 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java @@ -30,10 +30,12 @@ import org.apache.ignite.compute.ComputeJobAdapter; import org.apache.ignite.compute.ComputeJobResult; import org.apache.ignite.compute.ComputeTaskFuture; +import org.apache.ignite.compute.ComputeTaskMapAsync; import org.apache.ignite.compute.ComputeTaskSession; import org.apache.ignite.compute.ComputeTaskSessionFullSupport; import org.apache.ignite.compute.ComputeTaskSplitAdapter; import org.apache.ignite.compute.ComputeTaskTimeoutException; +import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.events.CheckpointEvent; import org.apache.ignite.events.DeploymentEvent; import org.apache.ignite.events.Event; @@ -85,6 +87,15 @@ public GridEventStorageCheckAllEventsSelfTest() { super(/*start grid*/true); } + @Override protected IgniteConfiguration getConfiguration() throws Exception { + IgniteConfiguration cfg = super.getConfiguration(); + + // TODO: IGNITE-3099 Race condition on the order of events + // Hotfix the test to check the event order in common case + cfg.setPublicThreadPoolSize(1); + return cfg; + } + /** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { ignite = G.ignite(getTestGridName()); @@ -140,10 +151,24 @@ public void testCheckpointEvents() throws Exception { * @throws Exception If test failed. */ public void testTaskUndeployEvents() throws Exception { - long tstamp = startTimestamp(); + final long tstamp = startTimestamp(); generateEvents(null, new GridAllEventsSuccessTestJob()).get(); + // TODO: IGNITE-3099 Race condition on the order of events + // Hotfix the test to check the event order in common case + GridTestUtils.waitForCondition(new GridAbsPredicate() { + @Override public boolean apply() { + try { + List evts = pullEvents(tstamp, 10); + return evts.get(evts.size() - 1).type() == EVT_JOB_FINISHED; + } + catch (Exception e) { + return false; + } + } + }, 500); + ignite.compute().undeployTask(GridAllEventsTestTask.class.getName()); ignite.compute().localDeployTask(GridAllEventsTestTask.class, GridAllEventsTestTask.class.getClassLoader()); @@ -463,6 +488,9 @@ private static class GridAllCheckpointEventsTestJob extends ComputeJobAdapter { * */ @ComputeTaskSessionFullSupport + // TODO: IGNITE-3099 Race condition on the order of events + // Hotfix the test to check the event order in common case + @ComputeTaskMapAsync private static class GridAllEventsTestTask extends ComputeTaskSplitAdapter { /** {@inheritDoc} */ @Override protected Collection split(int gridSize, Object arg) { From 8ee40a8e8d11f7a68e56c003a3c98d213253fb22 Mon Sep 17 00:00:00 2001 From: tledkov-gridgain Date: Tue, 10 May 2016 11:48:21 +0300 Subject: [PATCH 07/12] increase timeout and check the property settings --- ...ridUnsafeDataOutputArraySizingSelfTest.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java index 410877924257b..6db5564634add 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java @@ -21,6 +21,8 @@ import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import java.lang.reflect.Field; + import static org.apache.ignite.IgniteSystemProperties.IGNITE_MARSHAL_BUFFERS_RECHECK; /** @@ -37,7 +39,7 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT private static final long BUFFER_TIMEOUT = 1000; /** Wait timeout is bigger then buffer timeout to prevent failures due to time measurement error. */ - private static final long WAIT_BUFFER_TIMEOUT = BUFFER_TIMEOUT + BUFFER_TIMEOUT / 2; + private static final long WAIT_BUFFER_TIMEOUT = BUFFER_TIMEOUT * 2; /** * @@ -52,6 +54,7 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT @SuppressWarnings("BusyWait") public void testSmall() throws Exception { final GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); + checkGridUnsafeDataOutputCHECK_FREQ(); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 256), WAIT_BUFFER_TIMEOUT)); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 128), WAIT_BUFFER_TIMEOUT)); @@ -97,6 +100,7 @@ public void testChanged1() throws Exception { @SuppressWarnings("BusyWait") public void testChanged2() throws Exception { final GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); + checkGridUnsafeDataOutputCHECK_FREQ(); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 256), WAIT_BUFFER_TIMEOUT)); @@ -108,6 +112,16 @@ public void testChanged2() throws Exception { assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 2048), 2 * WAIT_BUFFER_TIMEOUT)); } + /** + * Check the IGNITE_MARSHAL_BUFFERS_RECHECK property setting. The GridUnsafeDataOutput class may be created before. + */ + private static void checkGridUnsafeDataOutputCHECK_FREQ() throws NoSuchFieldException, IllegalAccessException { + Class cls = GridUnsafeDataOutput.class; + Field fieldCHECK_FREQ = cls.getDeclaredField("CHECK_FREQ"); + fieldCHECK_FREQ.setAccessible(true); + assertEquals(BUFFER_TIMEOUT, ((Long)fieldCHECK_FREQ.get(null)).longValue()); + } + /** * */ @@ -140,8 +154,6 @@ private static class WriteAndCheckPredicate implements GridAbsPredicate { out.write(bytes); out.reset(); - System.out.println("L=" + out.internalArray().length); - return out.internalArray().length == len; } catch (Exception e) { From 9db4ae5d0517664f76bdc109684a363a482f7d1d Mon Sep 17 00:00:00 2001 From: tledkov-gridgain Date: Tue, 10 May 2016 14:43:12 +0300 Subject: [PATCH 08/12] Change the sequence of tests to properly set up IGNITE_MARSHAL_BUFFERS_RECHECK property for test IGNITE_MARSHAL_BUFFERS_RECHECK --- ...ridUnsafeDataOutputArraySizingSelfTest.java | 18 +++++------------- .../ignite/testframework/GridTestUtils.java | 1 - .../testsuites/IgniteBasicTestSuite.java | 2 +- .../IgniteMarshallerSelfTestSuite.java | 2 +- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java index 6db5564634add..fce1e8527b9f0 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java @@ -39,7 +39,7 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT private static final long BUFFER_TIMEOUT = 1000; /** Wait timeout is bigger then buffer timeout to prevent failures due to time measurement error. */ - private static final long WAIT_BUFFER_TIMEOUT = BUFFER_TIMEOUT * 2; + private static final long WAIT_BUFFER_TIMEOUT = BUFFER_TIMEOUT + BUFFER_TIMEOUT / 2; /** * @@ -54,7 +54,8 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT @SuppressWarnings("BusyWait") public void testSmall() throws Exception { final GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - checkGridUnsafeDataOutputCHECK_FREQ(); + assertEquals("Check the IGNITE_MARSHAL_BUFFERS_RECHECK property setting", + BUFFER_TIMEOUT, GridTestUtils.getFieldValue(null, GridUnsafeDataOutput.class, "CHECK_FREQ")); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 256), WAIT_BUFFER_TIMEOUT)); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 128), WAIT_BUFFER_TIMEOUT)); @@ -100,7 +101,8 @@ public void testChanged1() throws Exception { @SuppressWarnings("BusyWait") public void testChanged2() throws Exception { final GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - checkGridUnsafeDataOutputCHECK_FREQ(); + assertEquals("Check the IGNITE_MARSHAL_BUFFERS_RECHECK property setting", + BUFFER_TIMEOUT, GridTestUtils.getFieldValue(null, GridUnsafeDataOutput.class, "CHECK_FREQ")); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 256), WAIT_BUFFER_TIMEOUT)); @@ -112,16 +114,6 @@ public void testChanged2() throws Exception { assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 2048), 2 * WAIT_BUFFER_TIMEOUT)); } - /** - * Check the IGNITE_MARSHAL_BUFFERS_RECHECK property setting. The GridUnsafeDataOutput class may be created before. - */ - private static void checkGridUnsafeDataOutputCHECK_FREQ() throws NoSuchFieldException, IllegalAccessException { - Class cls = GridUnsafeDataOutput.class; - Field fieldCHECK_FREQ = cls.getDeclaredField("CHECK_FREQ"); - fieldCHECK_FREQ.setAccessible(true); - assertEquals(BUFFER_TIMEOUT, ((Long)fieldCHECK_FREQ.get(null)).longValue()); - } - /** * */ diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java index 524c643989841..80f1aef199e29 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java @@ -1070,7 +1070,6 @@ public static Callable makeCallable(final Runnable run, @Nullable final T */ @SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter") public static T getFieldValue(Object obj, Class cls, String fieldName) throws IgniteException { - assert obj != null; assert fieldName != null; try { diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java index 6b4ef709bf476..d873c372c3c8a 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java @@ -76,9 +76,9 @@ public static TestSuite suite() throws Exception { public static TestSuite suite(Set ignoredTests) throws Exception { TestSuite suite = new TestSuite("Ignite Basic Test Suite"); + suite.addTest(IgniteMarshallerSelfTestSuite.suite(ignoredTests)); suite.addTest(IgniteLangSelfTestSuite.suite()); suite.addTest(IgniteUtilSelfTestSuite.suite(ignoredTests)); - suite.addTest(IgniteMarshallerSelfTestSuite.suite(ignoredTests)); suite.addTest(IgniteKernalSelfTestSuite.suite(ignoredTests)); suite.addTest(IgniteStartUpTestSuite.suite()); diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java index 191364e16b9a7..22d3add4cb1e1 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteMarshallerSelfTestSuite.java @@ -53,12 +53,12 @@ public static TestSuite suite() throws Exception { public static TestSuite suite(Set ignoredTests) throws Exception { TestSuite suite = new TestSuite("Ignite Marshaller Test Suite"); + GridTestUtils.addTestIfNeeded(suite, GridUnsafeDataOutputArraySizingSelfTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, GridJdkMarshallerSelfTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, OptimizedMarshallerEnumSelfTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, OptimizedMarshallerSelfTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, OptimizedMarshallerTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, OptimizedObjectStreamSelfTest.class, ignoredTests); - GridTestUtils.addTestIfNeeded(suite, GridUnsafeDataOutputArraySizingSelfTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, GridUnsafeDataInputOutputByteOrderSelfTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, OptimizedMarshallerNodeFailoverTest.class, ignoredTests); GridTestUtils.addTestIfNeeded(suite, OptimizedMarshallerSerialPersistentFieldsSelfTest.class, ignoredTests); From eb33bedc0e15412f02e164c01697e5dd0ce046f3 Mon Sep 17 00:00:00 2001 From: tledkov-gridgain Date: Tue, 10 May 2016 17:59:35 +0300 Subject: [PATCH 09/12] Fix test GridUnsafeDataOutputArraySizingSelfTest: add non-static field 'checkFreq' to the GridUnsafeDataOutput --- .../util/io/GridUnsafeDataOutput.java | 12 ++++++++-- ...idUnsafeDataOutputArraySizingSelfTest.java | 24 +++++-------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutput.java b/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutput.java index c0fe0d3b225da..bf60d99fc1f81 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutput.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutput.java @@ -40,6 +40,9 @@ public class GridUnsafeDataOutput extends OutputStream implements GridDataOutput /** */ private static final Long CHECK_FREQ = Long.getLong(IGNITE_MARSHAL_BUFFERS_RECHECK, 10000); + /** */ + private final Long checkFreq; + /** Length of char buffer (for writing strings). */ private static final int CHAR_BUF_SIZE = 256; @@ -65,14 +68,19 @@ public class GridUnsafeDataOutput extends OutputStream implements GridDataOutput * */ public GridUnsafeDataOutput() { - // No-op. + checkFreq = CHECK_FREQ; } /** * @param size Size */ public GridUnsafeDataOutput(int size) { + this(size, CHECK_FREQ); + } + + public GridUnsafeDataOutput(int size, long checkFreq) { bytes = new byte[size]; + this.checkFreq = checkFreq; } /** @@ -134,7 +142,7 @@ private void requestFreeSize(int size) { bytes = newBytes; } - else if (now - lastCheck > CHECK_FREQ) { + else if (now - lastCheck > checkFreq) { int halfSize = bytes.length >> 1; if (maxOff < halfSize) { diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java index fce1e8527b9f0..4fea649d079cc 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java @@ -21,10 +21,6 @@ import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import java.lang.reflect.Field; - -import static org.apache.ignite.IgniteSystemProperties.IGNITE_MARSHAL_BUFFERS_RECHECK; - /** * Test for {@link GridUnsafeDataOutput}. */ @@ -41,21 +37,13 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT /** Wait timeout is bigger then buffer timeout to prevent failures due to time measurement error. */ private static final long WAIT_BUFFER_TIMEOUT = BUFFER_TIMEOUT + BUFFER_TIMEOUT / 2; - /** - * - */ - static { - System.setProperty(IGNITE_MARSHAL_BUFFERS_RECHECK, Long.toString(BUFFER_TIMEOUT)); - } /** * @throws Exception If failed. */ @SuppressWarnings("BusyWait") public void testSmall() throws Exception { - final GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - assertEquals("Check the IGNITE_MARSHAL_BUFFERS_RECHECK property setting", - BUFFER_TIMEOUT, GridTestUtils.getFieldValue(null, GridUnsafeDataOutput.class, "CHECK_FREQ")); + GridDataOutput out = new GridUnsafeDataOutput(512, BUFFER_TIMEOUT); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 256), WAIT_BUFFER_TIMEOUT)); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 128), WAIT_BUFFER_TIMEOUT)); @@ -100,9 +88,7 @@ public void testChanged1() throws Exception { */ @SuppressWarnings("BusyWait") public void testChanged2() throws Exception { - final GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - assertEquals("Check the IGNITE_MARSHAL_BUFFERS_RECHECK property setting", - BUFFER_TIMEOUT, GridTestUtils.getFieldValue(null, GridUnsafeDataOutput.class, "CHECK_FREQ")); + GridDataOutput out = new GridUnsafeDataOutput(512, BUFFER_TIMEOUT); assertTrue(GridTestUtils.waitForCondition(new WriteAndCheckPredicate(out, SMALL, 256), WAIT_BUFFER_TIMEOUT)); @@ -119,7 +105,7 @@ public void testChanged2() throws Exception { */ private static class WriteAndCheckPredicate implements GridAbsPredicate { /** */ - final GridUnsafeDataOutput out; + final GridDataOutput out; /** */ final byte [] bytes; @@ -132,7 +118,7 @@ private static class WriteAndCheckPredicate implements GridAbsPredicate { * @param bytes Bytes. * @param len Length. */ - WriteAndCheckPredicate(GridUnsafeDataOutput out, byte[] bytes, int len) { + WriteAndCheckPredicate(GridDataOutput out, byte[] bytes, int len) { this.out = out; this.bytes = bytes; this.len = len; @@ -145,10 +131,12 @@ private static class WriteAndCheckPredicate implements GridAbsPredicate { try { out.write(bytes); out.reset(); +// System.out.println("L=" + out.internalArray().length); return out.internalArray().length == len; } catch (Exception e) { + e.printStackTrace(); assertTrue("Unexpected exception: " + e.getMessage(), false); return false; } From f51f7ec4470feb4d4ab85445010a14c6198de319 Mon Sep 17 00:00:00 2001 From: tledkov-gridgain Date: Wed, 11 May 2016 10:31:08 +0300 Subject: [PATCH 10/12] remove debug print --- .../util/io/GridUnsafeDataOutputArraySizingSelfTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java index 4fea649d079cc..54766e39d7c3d 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java @@ -131,7 +131,6 @@ private static class WriteAndCheckPredicate implements GridAbsPredicate { try { out.write(bytes); out.reset(); -// System.out.println("L=" + out.internalArray().length); return out.internalArray().length == len; } From cff5a190c40c28982ac3197d2d6aef957619f7c1 Mon Sep 17 00:00:00 2001 From: tledkov-gridgain Date: Wed, 11 May 2016 12:21:51 +0300 Subject: [PATCH 11/12] investigate TC behavior --- .../ignite/internal/util/io/GridUnsafeDataOutput.java | 11 ++++++++++- .../io/GridUnsafeDataOutputArraySizingSelfTest.java | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutput.java b/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutput.java index bf60d99fc1f81..f9fcaa13d6beb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutput.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutput.java @@ -38,7 +38,7 @@ */ public class GridUnsafeDataOutput extends OutputStream implements GridDataOutput { /** */ - private static final Long CHECK_FREQ = Long.getLong(IGNITE_MARSHAL_BUFFERS_RECHECK, 10000); + private static final Long CHECK_FREQ = getChechFreq(); /** */ private final Long checkFreq; @@ -569,4 +569,13 @@ else if (c > 0x07FF) { @Override public String toString() { return S.toString(GridUnsafeDataOutput.class, this); } + + private static Long getChechFreq() { + try{ + throw new Exception("+++ GridUnsafeDataOutput.CHECK_FREQ is setup here"); + } catch (Exception e) { + e.printStackTrace(); + } + return Long.getLong(IGNITE_MARSHAL_BUFFERS_RECHECK, 10000); + } } \ No newline at end of file diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java index 54766e39d7c3d..442053f5cde2c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java @@ -38,6 +38,9 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT private static final long WAIT_BUFFER_TIMEOUT = BUFFER_TIMEOUT + BUFFER_TIMEOUT / 2; + static { + System.out.println("GridUnsafeDataOutputArraySizingSelfTest static block"); + } /** * @throws Exception If failed. */ From c3fe718bc1f553bfa607da711bc232ee8552e2b5 Mon Sep 17 00:00:00 2001 From: tledkov-gridgain Date: Wed, 11 May 2016 12:54:25 +0300 Subject: [PATCH 12/12] revert: investigate TC behavior --- .../ignite/internal/util/io/GridUnsafeDataOutput.java | 11 +---------- .../io/GridUnsafeDataOutputArraySizingSelfTest.java | 4 ---- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutput.java b/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutput.java index f9fcaa13d6beb..bf60d99fc1f81 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutput.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutput.java @@ -38,7 +38,7 @@ */ public class GridUnsafeDataOutput extends OutputStream implements GridDataOutput { /** */ - private static final Long CHECK_FREQ = getChechFreq(); + private static final Long CHECK_FREQ = Long.getLong(IGNITE_MARSHAL_BUFFERS_RECHECK, 10000); /** */ private final Long checkFreq; @@ -569,13 +569,4 @@ else if (c > 0x07FF) { @Override public String toString() { return S.toString(GridUnsafeDataOutput.class, this); } - - private static Long getChechFreq() { - try{ - throw new Exception("+++ GridUnsafeDataOutput.CHECK_FREQ is setup here"); - } catch (Exception e) { - e.printStackTrace(); - } - return Long.getLong(IGNITE_MARSHAL_BUFFERS_RECHECK, 10000); - } } \ No newline at end of file diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java index 442053f5cde2c..fdf4c083e98af 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java @@ -37,10 +37,6 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT /** Wait timeout is bigger then buffer timeout to prevent failures due to time measurement error. */ private static final long WAIT_BUFFER_TIMEOUT = BUFFER_TIMEOUT + BUFFER_TIMEOUT / 2; - - static { - System.out.println("GridUnsafeDataOutputArraySizingSelfTest static block"); - } /** * @throws Exception If failed. */