Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
daradurvs committed Sep 19, 2017
1 parent 49de49f commit 9e21c89
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ public void testNodeStartByOldVersionPersistenceData() throws Exception {
try {
startGrid(1, "2.1.0", new PostConfigurationClosure(), new PostActionClosure());

stopAllGrids();

IgniteEx ignite = startGrid(0);

assertEquals(1, ignite.context().discovery().topologyVersion());

ignite.active(true);

IgniteCache<Integer, String> cache = ignite.getOrCreateCache(TEST_CACHE_NAME);

for (int i = 0; i < 10; i++)
assertEquals("data" + i, cache.get(i));
// stopAllGrids();
//
// IgniteEx ignite = startGrid(0);
//
// assertEquals(1, ignite.context().discovery().topologyVersion());
//
// ignite.active(true);
//
// IgniteCache<Integer, String> cache = ignite.getOrCreateCache(TEST_CACHE_NAME);

// for (int i = 0; i < 10; i++)
// assertEquals("data" + i, cache.get(i));
}
finally {
stopAllGrids();
Expand All @@ -89,18 +89,18 @@ public void testNodeStartByOldVersionPersistenceData() throws Exception {
private static class PostActionClosure implements IgniteInClosure<Ignite> {
/** {@inheritDoc} */
@Override public void apply(Ignite ignite) {
ignite.active(true);

CacheConfiguration<Integer, String> cacheCfg = new CacheConfiguration<>();
cacheCfg.setName(TEST_CACHE_NAME);
cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
cacheCfg.setBackups(1);
cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

IgniteCache<Integer, String> cache = ignite.createCache(cacheCfg);

for (int i = 0; i < 10; i++)
cache.put(i, "data" + i);
// ignite.active(true);
//
// CacheConfiguration<Integer, String> cacheCfg = new CacheConfiguration<>();
// cacheCfg.setName(TEST_CACHE_NAME);
// cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
// cacheCfg.setBackups(1);
// cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
//
// IgniteCache<Integer, String> cache = ignite.createCache(cacheCfg);
//
// for (int i = 0; i < 10; i++)
// cache.put(i, "data" + i);
}
}

Expand All @@ -117,7 +117,7 @@ private static class PostConfigurationClosure implements IgniteInClosure<IgniteC

cfg.setPeerClassLoadingEnabled(false);

cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration());
// cfg.setPersistentStoreConfiguration(new PersistentStoreConfiguration());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,23 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
import org.apache.ignite.compatibility.testframework.plugins.TestCompatibilityPluginProvider;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.events.DiscoveryEvent;
import org.apache.ignite.events.Event;
import org.apache.ignite.events.EventType;
import org.apache.ignite.internal.util.GridJavaProcess;
import org.apache.ignite.internal.util.typedef.X;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteInClosure;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.testframework.GridTestUtils;
import org.apache.ignite.testframework.junits.multijvm.IgniteNodeRunner;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -71,13 +79,22 @@ public static void main(String[] args) throws Exception {

cfgClos.apply(cfg);

UUID id = UUID.fromString(args[2]);

// Ignite instance name and id must be set according to arguments
// it's used for nodes managing: start, stop etc.
cfg.setIgniteInstanceName(args[1]);
cfg.setNodeId(UUID.fromString(args[2]));
cfg.setNodeId(id);

final CountDownLatch nodeStartedLatch = getNodeStartedLatch(cfg);

Ignite ignite = Ignition.start(cfg);

if (nodeStartedLatch.await(20, TimeUnit.SECONDS))
X.println("Remote node has joined [id=" + id + "]");
else
X.println("Remote node has not joined [id=" + id + "]");

// it needs to set private static field 'ignite' of the IgniteNodeRunner class via reflection
GridTestUtils.setFieldValue(new IgniteNodeRunner(), "ignite", ignite);

Expand All @@ -86,6 +103,31 @@ public static void main(String[] args) throws Exception {

iClos.apply(ignite);
}

X.println("Remote node has prepared [id=" + id + "]");
}

private static CountDownLatch getNodeStartedLatch(IgniteConfiguration cfg) {
final CountDownLatch rmtNodeStartedLatch = new CountDownLatch(1);

Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();

lsnrs.put(new IgnitePredicate<Event>() {
@Override public boolean apply(Event evt) {

X.println("****" + evt);

rmtNodeStartedLatch.countDown();

return true;
}
}, EventType.EVTS_ALL);

cfg.setLocalEventListeners(lsnrs);

cfg.setDiscoverySpi().

return rmtNodeStartedLatch;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -311,21 +313,22 @@ protected static class LoggedJoinNodeClosure implements IgniteInClosure<String>
/** Node joined latch. */
private CountDownLatch nodeJoinedLatch;

/** Pattern for comparing. */
private String pattern;
/** Patterns for comparing. */
private Set<String> patterns = new HashSet<>();

/**
* @param nodeJoinedLatch Node joined latch.
* @param nodeId Expected node id.
*/
public LoggedJoinNodeClosure(CountDownLatch nodeJoinedLatch, UUID nodeId) {
this.nodeJoinedLatch = nodeJoinedLatch;
this.pattern = "evt=NODE_JOINED, node=" + nodeId;
this.patterns.add("Remote node has joined [id=" + nodeId + "]");
this.patterns.add("Remote node has prepared [id=" + nodeId + "]");
}

/** {@inheritDoc} */
@Override public void apply(String s) {
if (s.contains(pattern) && nodeJoinedLatch.getCount() > 0)
if (nodeJoinedLatch.getCount() > 0 && patterns.contains(s))
nodeJoinedLatch.countDown();
}
}
Expand Down

0 comments on commit 9e21c89

Please sign in to comment.