use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class IgniteCacheClientNodeChangingTopologyTest method findKeys.
/**
* Tries to find keys for two partitions: for one partition assignment should not change after node join,
* for another primary node should change.
*
* @param ignite Ignite.
* @param nodes Current nodes.
* @return Found keys.
*/
private IgniteBiTuple<Integer, Integer> findKeys(Ignite ignite, ClusterNode... nodes) {
ClusterNode newNode = new TcpDiscoveryNode();
GridTestUtils.setFieldValue(newNode, "consistentId", getTestIgniteInstanceName(4));
GridTestUtils.setFieldValue(newNode, "id", UUID.randomUUID());
List<ClusterNode> topNodes = new ArrayList<>();
Collections.addAll(topNodes, nodes);
topNodes.add(newNode);
DiscoveryEvent discoEvt = new DiscoveryEvent(newNode, "", EventType.EVT_NODE_JOINED, newNode);
final long topVer = ignite.cluster().topologyVersion();
GridAffinityFunctionContextImpl ctx = new GridAffinityFunctionContextImpl(topNodes, null, discoEvt, new AffinityTopologyVersion(topVer + 1), 1);
AffinityFunction affFunc = ignite.cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class).getAffinity();
List<List<ClusterNode>> newAff = affFunc.assignPartitions(ctx);
List<List<ClusterNode>> curAff = ((IgniteKernal) ignite).context().cache().internalCache(DEFAULT_CACHE_NAME).context().affinity().assignments(new AffinityTopologyVersion(topVer));
Integer key1 = null;
Integer key2 = null;
Affinity<Integer> aff = ignite.affinity(DEFAULT_CACHE_NAME);
for (int i = 0; i < curAff.size(); i++) {
if (key1 == null) {
List<ClusterNode> oldNodes = curAff.get(i);
List<ClusterNode> newNodes = newAff.get(i);
if (oldNodes.equals(newNodes))
key1 = findKey(aff, i);
}
if (key2 == null) {
ClusterNode oldPrimary = F.first(curAff.get(i));
ClusterNode newPrimary = F.first(newAff.get(i));
if (!oldPrimary.equals(newPrimary))
key2 = findKey(aff, i);
}
if (key1 != null && key2 != null)
break;
}
if (key1 == null || key2 == null)
fail("Failed to find nodes required for test.");
return new IgniteBiTuple<>(key1, key2);
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridEventConsumeSelfTest method testApi.
/**
* @throws Exception If failed.
*/
public void testApi() throws Exception {
try {
grid(0).events().stopRemoteListen(null);
} catch (NullPointerException ignored) {
// No-op.
}
grid(0).events().stopRemoteListen(UUID.randomUUID());
UUID consumeId = null;
try {
consumeId = grid(0).events().remoteListen(new P2<UUID, DiscoveryEvent>() {
@Override
public boolean apply(UUID uuid, DiscoveryEvent evt) {
return false;
}
}, new P1<DiscoveryEvent>() {
@Override
public boolean apply(DiscoveryEvent e) {
return false;
}
}, EVTS_DISCOVERY);
assertNotNull(consumeId);
} finally {
grid(0).events().stopRemoteListen(consumeId);
}
try {
consumeId = grid(0).events().remoteListen(new P2<UUID, DiscoveryEvent>() {
@Override
public boolean apply(UUID uuid, DiscoveryEvent evt) {
return false;
}
}, new P1<DiscoveryEvent>() {
@Override
public boolean apply(DiscoveryEvent e) {
return false;
}
});
assertNotNull(consumeId);
} finally {
grid(0).events().stopRemoteListen(consumeId);
}
try {
consumeId = grid(0).events().remoteListen(new P2<UUID, Event>() {
@Override
public boolean apply(UUID uuid, Event evt) {
return false;
}
}, new P1<Event>() {
@Override
public boolean apply(Event e) {
return false;
}
});
assertNotNull(consumeId);
} finally {
grid(0).events().stopRemoteListen(consumeId);
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridEventConsumeSelfTest method testApiAsyncOld.
/**
* @throws Exception If failed.
*/
public void testApiAsyncOld() throws Exception {
IgniteEvents evtAsync = grid(0).events().withAsync();
try {
evtAsync.stopRemoteListen(null);
evtAsync.future().get();
} catch (NullPointerException ignored) {
// No-op.
}
evtAsync.stopRemoteListen(UUID.randomUUID());
evtAsync.future().get();
UUID consumeId = null;
try {
evtAsync.remoteListen(new P2<UUID, DiscoveryEvent>() {
@Override
public boolean apply(UUID uuid, DiscoveryEvent evt) {
return false;
}
}, new P1<DiscoveryEvent>() {
@Override
public boolean apply(DiscoveryEvent e) {
return false;
}
}, EVTS_DISCOVERY);
consumeId = (UUID) evtAsync.future().get();
assertNotNull(consumeId);
} finally {
evtAsync.stopRemoteListen(consumeId);
evtAsync.future().get();
}
try {
evtAsync.remoteListen(new P2<UUID, DiscoveryEvent>() {
@Override
public boolean apply(UUID uuid, DiscoveryEvent evt) {
return false;
}
}, new P1<DiscoveryEvent>() {
@Override
public boolean apply(DiscoveryEvent e) {
return false;
}
});
consumeId = (UUID) evtAsync.future().get();
assertNotNull(consumeId);
} finally {
evtAsync.stopRemoteListen(consumeId);
evtAsync.future().get();
}
try {
evtAsync.remoteListen(new P2<UUID, Event>() {
@Override
public boolean apply(UUID uuid, Event evt) {
return false;
}
}, new P1<Event>() {
@Override
public boolean apply(Event e) {
return false;
}
});
consumeId = (UUID) evtAsync.future().get();
assertNotNull(consumeId);
} finally {
evtAsync.stopRemoteListen(consumeId);
evtAsync.future().get();
}
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class GridEventConsumeSelfTest method testMasterNodeLeaveNoAutoUnsubscribe.
/**
* @throws Exception If failed.
*/
public void testMasterNodeLeaveNoAutoUnsubscribe() throws Exception {
Ignite g = startGrid("anotherGrid");
final CountDownLatch discoLatch;
try {
final UUID nodeId = g.cluster().localNode().id();
discoLatch = new CountDownLatch(GRID_CNT);
for (int i = 0; i < GRID_CNT; i++) {
grid(0).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (nodeId.equals(((DiscoveryEvent) evt).eventNode().id()))
discoLatch.countDown();
return true;
}
}, EVT_NODE_LEFT);
}
consumeLatch = new CountDownLatch(GRID_CNT * 2 + 1);
consumeCnt = new AtomicInteger();
noAutoUnsubscribe = true;
g.events().remoteListen(1, 0, false, null, new P1<Event>() {
@Override
public boolean apply(Event evt) {
consumeLatch.countDown();
consumeCnt.incrementAndGet();
return true;
}
}, EVT_JOB_STARTED);
grid(0).compute().broadcast(F.noop());
} finally {
stopGrid("anotherGrid");
}
discoLatch.await(3000, MILLISECONDS);
grid(0).compute().broadcast(F.noop());
assert consumeLatch.await(2, SECONDS);
assertEquals(GRID_CNT * 2 + 1, consumeCnt.get());
}
use of org.apache.ignite.events.DiscoveryEvent in project ignite by apache.
the class TcpDiscoverySelfTest method testPingInterruptedOnNodeFailed.
/**
* @throws Exception If any error occurs.
*/
public void testPingInterruptedOnNodeFailed() throws Exception {
try {
final Ignite pingingNode = startGrid("testPingInterruptedOnNodeFailedPingingNode");
final Ignite failedNode = startGrid("testPingInterruptedOnNodeFailedFailingNode");
startGrid("testPingInterruptedOnNodeFailedSimpleNode");
((TestTcpDiscoverySpi) failedNode.configuration().getDiscoverySpi()).ignorePingResponse = true;
final UUID failedNodeId = failedNode.cluster().localNode().id();
final CountDownLatch pingLatch = new CountDownLatch(1);
final CountDownLatch eventLatch = new CountDownLatch(1);
final AtomicBoolean pingRes = new AtomicBoolean(true);
final AtomicBoolean failRes = new AtomicBoolean(false);
long startTs = System.currentTimeMillis();
pingingNode.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event event) {
if (((DiscoveryEvent) event).eventNode().id().equals(failedNodeId)) {
failRes.set(true);
eventLatch.countDown();
}
return true;
}
}, EventType.EVT_NODE_FAILED);
IgniteInternalFuture<?> pingFut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
pingLatch.countDown();
pingRes.set(pingingNode.configuration().getDiscoverySpi().pingNode(failedNodeId));
return null;
}
}, 1);
IgniteInternalFuture<?> failingFut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
pingLatch.await();
Thread.sleep(3000);
((TestTcpDiscoverySpi) failedNode.configuration().getDiscoverySpi()).simulateNodeFailure();
return null;
}
}, 1);
failingFut.get();
pingFut.get();
assertFalse(pingRes.get());
assertTrue(System.currentTimeMillis() - startTs < pingingNode.configuration().getFailureDetectionTimeout() / 2);
assertTrue(eventLatch.await(7, TimeUnit.SECONDS));
assertTrue(failRes.get());
} finally {
stopAllGrids();
}
}
Aggregations