Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D1681200AFA for ; Thu, 5 May 2016 16:02:38 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D02BA160A03; Thu, 5 May 2016 14:02:38 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BEB89160A1F for ; Thu, 5 May 2016 16:02:37 +0200 (CEST) Received: (qmail 14465 invoked by uid 500); 5 May 2016 14:02:36 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 13152 invoked by uid 99); 5 May 2016 14:02:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 May 2016 14:02:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A2250E0579; Thu, 5 May 2016 14:02:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Thu, 05 May 2016 14:03:05 -0000 Message-Id: <3aec6a1207dd4773a6939c6689ff8e92@git.apache.org> In-Reply-To: <5f1852aff071435f86f1fdcd753d93b5@git.apache.org> References: <5f1852aff071435f86f1fdcd753d93b5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [32/34] ignite git commit: Fixed tests. archived-at: Thu, 05 May 2016 14:02:39 -0000 Fixed tests. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b646b549 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b646b549 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b646b549 Branch: refs/heads/ignite-1.6 Commit: b646b5491284765addf1b3bb0ea2cc6fc020a67f Parents: 764c97b Author: sboikov Authored: Thu May 5 16:56:21 2016 +0300 Committer: sboikov Committed: Thu May 5 16:56:21 2016 +0300 ---------------------------------------------------------------------- .../continuous/GridMessageListenSelfTest.java | 30 ++-- ...GridUnsafeDataOutputArraySizingSelfTest.java | 144 +++++++++---------- 2 files changed, 82 insertions(+), 92 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/b646b549/modules/core/src/test/java/org/apache/ignite/internal/processors/continuous/GridMessageListenSelfTest.java ---------------------------------------------------------------------- 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 ea18f69..1264eec 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 class GridMessageListenSelfTest extends GridCommonAbstractTest { 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 class GridMessageListenSelfTest extends GridCommonAbstractTest { 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 @@ public class GridMessageListenSelfTest extends GridCommonAbstractTest { /** */ 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 @@ public class GridMessageListenSelfTest extends GridCommonAbstractTest { 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 @@ public class GridMessageListenSelfTest extends GridCommonAbstractTest { /** */ 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 @@ public class GridMessageListenSelfTest extends GridCommonAbstractTest { X.println("Received message [nodeId=" + nodeId + ", locNodeId=" + locNodeId + ']'); - assertEquals(prj.ignite().cluster().localNode().id(), nodeId); + assertEquals(sourceNodeId, nodeId); assertEquals(MSG, msg); nodes.add(locNodeId); http://git-wip-us.apache.org/repos/asf/ignite/blob/b646b549/modules/core/src/test/java/org/apache/ignite/internal/util/io/GridUnsafeDataOutputArraySizingSelfTest.java ---------------------------------------------------------------------- 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 2e56bde..4108779 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,17 @@ 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 +51,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); - } - - assertEquals(256, out.internalArray().length); - - for (int i = 0; i < 11; i++) { - Thread.sleep(100); - - writeSmall(out); - } + final GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - 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 +66,8 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT public void testBig() throws Exception { GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - writeBig(out); + out.write(BIG); + out.reset(); assertEquals(4096, out.internalArray().length); } @@ -96,8 +82,10 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT 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 +96,58 @@ public class GridUnsafeDataOutputArraySizingSelfTest extends GridCommonAbstractT */ @SuppressWarnings("BusyWait") public void testChanged2() throws Exception { - GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - - for (int i = 0; i < 11; i++) { - Thread.sleep(100); - - writeSmall(out); - } - - assertEquals(256, out.internalArray().length); - - writeBig(out); - - assertEquals(4096, out.internalArray().length); + final GridUnsafeDataOutput out = new GridUnsafeDataOutput(512); - 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); - } - - /** - * @param out Output. - * @throws Exception If failed. - */ - private void writeSmall(GridUnsafeDataOutput out) throws Exception { - out.write(SMALL); - - out.reset(); + 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 writeBig(GridUnsafeDataOutput out) throws Exception { - out.write(BIG); + private static class WriteAndCheckPredicate implements GridAbsPredicate { + /** */ + final GridUnsafeDataOutput out; + + /** */ + final byte [] bytes; + + /** */ + final int len; + + /** + * @param out Out. + * @param bytes Bytes. + * @param len Length. + */ + WriteAndCheckPredicate(GridUnsafeDataOutput out, byte[] bytes, int len) { + this.out = out; + this.bytes = bytes; + this.len = len; + } - out.reset(); + /** + * {@inheritDoc} + */ + @Override public boolean apply() { + try { + out.write(bytes); + out.reset(); + + System.out.println("L=" + out.internalArray().length); + + return out.internalArray().length == len; + } + catch (Exception e) { + assertTrue("Unexpected exception: " + e.getMessage(), false); + return false; + } + } } } \ No newline at end of file