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 2016/05/05 13:56:32 UTC
ignite git commit: Fixed tests.
Repository: ignite
Updated Branches:
refs/heads/master 764c97b90 -> b646b5491
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/master
Commit: b646b5491284765addf1b3bb0ea2cc6fc020a67f
Parents: 764c97b
Author: sboikov <sb...@gridgain.com>
Authored: Thu May 5 16:56:21 2016 +0300
Committer: sboikov <sb...@gridgain.com>
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<UUID, Object> {
- /** */
- 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<Object> {
- /** */
- 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