use of org.apache.ignite.events.Event in project ignite by apache.
the class GridDiscoveryEventSelfTest method testDaemonNodeJoin.
/**
* @throws Exception If failed.
*/
@Test
public void testDaemonNodeJoin() throws Exception {
try {
startGridsMultiThreaded(3);
final AtomicReference<IgniteCheckedException> err = new AtomicReference<>();
for (int i = 0; i < 3; i++) {
Ignite g = grid(i);
g.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
if (discoEvt.topologyNodes().size() != 3)
err.compareAndSet(null, new IgniteCheckedException("Invalid discovery event [evt=" + discoEvt + ", nodes=" + discoEvt.topologyNodes() + ']'));
return true;
}
}, EventType.EVT_NODE_JOINED);
}
daemon = true;
IgniteKernal daemon = (IgniteKernal) startGrid(3);
DiscoveryEvent join = daemon.context().discovery().localJoinEvent();
assertEquals(3, join.topologyNodes().size());
U.sleep(100);
if (err.get() != null)
throw err.get();
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridEventStorageCheckAllEventsSelfTest method testTaskUndeployEvents.
/**
* @throws Exception If test failed.
*/
@Test
public void testTaskUndeployEvents() throws Exception {
final long tstamp = startTimestamp();
generateEvents(null, new GridAllEventsSuccessTestJob()).get();
// TODO: IGNITE-3099 (hotfix the test to check the event order in common case).
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
List<Event> evts = pullEvents(tstamp, 10);
return evts.get(evts.size() - 1).type() == EVT_JOB_FINISHED;
} catch (Exception ignored) {
return false;
}
}
}, 500);
ignite.compute().undeployTask(GridAllEventsTestTask.class.getName());
ignite.compute().localDeployTask(GridAllEventsTestTask.class, GridAllEventsTestTask.class.getClassLoader());
List<Event> evts = pullEvents(tstamp, 12);
assertEvent(evts.get(0).type(), EVT_TASK_STARTED, evts);
assertEvent(evts.get(1).type(), EVT_JOB_MAPPED, evts);
assertEvent(evts.get(2).type(), EVT_JOB_QUEUED, evts);
assertEvent(evts.get(3).type(), EVT_JOB_STARTED, evts);
assertEvent(evts.get(4).type(), EVT_CHECKPOINT_SAVED, evts);
assertEvent(evts.get(5).type(), EVT_CHECKPOINT_REMOVED, evts);
assertEvent(evts.get(6).type(), EVT_JOB_RESULTED, evts);
assertEvent(evts.get(7).type(), EVT_TASK_REDUCED, evts);
assertEvent(evts.get(8).type(), EVT_TASK_FINISHED, evts);
assertEvent(evts.get(9).type(), EVT_JOB_FINISHED, evts);
assertEvent(evts.get(10).type(), EVT_TASK_UNDEPLOYED, evts);
assertEvent(evts.get(11).type(), EVT_TASK_DEPLOYED, evts);
assertNotNull(((JobEvent) evts.get(6)).resultPolicy());
assertEquals(WAIT, ((JobEvent) evts.get(6)).resultPolicy());
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridEventStorageRuntimeConfigurationSelfTest method testEnableWithDefaults.
/**
* @throws Exception If failed.
*/
@Test
public void testEnableWithDefaults() throws Exception {
inclEvtTypes = null;
try {
Ignite g = startGrid();
final AtomicInteger cnt = new AtomicInteger();
g.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
cnt.incrementAndGet();
return true;
}
}, EVT_TASK_STARTED);
g.compute().run(F.noop());
assertEquals(0, cnt.get());
g.events().enableLocal(EVT_TASK_STARTED);
g.compute().run(F.noop());
assertEquals(1, cnt.get());
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridMultipleVersionsDeploymentSelfTest method testMultipleVersionsP2PDeploy.
/**
* @throws Exception If test failed.
*/
@Test
public void testMultipleVersionsP2PDeploy() throws Exception {
try {
Ignite g1 = startGrid(1);
Ignite g2 = startGrid(2);
final CountDownLatch latch = new CountDownLatch(2);
g2.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
info("Received event: " + evt);
latch.countDown();
return true;
}
}, EVT_TASK_UNDEPLOYED);
ClassLoader ldr1 = new GridTestClassLoader(Collections.singletonMap("testResource", "1"), getClass().getClassLoader(), EXCLUDE_CLASSES);
ClassLoader ldr2 = new GridTestClassLoader(Collections.singletonMap("testResource", "2"), getClass().getClassLoader(), EXCLUDE_CLASSES);
Class<? extends ComputeTask<?, ?>> taskCls1 = (Class<? extends ComputeTask<?, ?>>) ldr1.loadClass(GridDeploymentTestTask.class.getName());
Class<? extends ComputeTask<?, ?>> taskCls2 = (Class<? extends ComputeTask<?, ?>>) ldr2.loadClass(GridDeploymentTestTask.class.getName());
g1.compute().localDeployTask(taskCls1, ldr1);
// Task will wait for the signal.
ComputeTaskFuture fut1 = executeAsync(g1.compute(), "GridDeploymentTestTask", null);
assert checkDeployed(g1, "GridDeploymentTestTask");
// We should wait here when to be sure that job has been started.
// Since we loader task/job classes with different class loaders we cannot
// use any kind of mutex because of the illegal state exception.
// We have to use timer here. DO NOT CHANGE 2 seconds here.
Thread.sleep(1000);
// Deploy new one - this should move first task to the obsolete list.
g1.compute().localDeployTask(taskCls2, ldr2);
// Task will wait for the signal.
ComputeTaskFuture fut2 = executeAsync(g1.compute(), "GridDeploymentTestTask", null);
boolean deployed = checkDeployed(g1, "GridDeploymentTestTask");
Object res1 = fut1.get();
Object res2 = fut2.get();
g1.compute().undeployTask("GridDeploymentTestTask");
// New one should be deployed.
assert deployed;
// Wait for the execution.
assert res1.equals(1);
assert res2.equals(2);
stopGrid(1);
assert latch.await(3000, MILLISECONDS);
assert !checkDeployed(g2, "GridDeploymentTestTask");
} finally {
stopGrid(2);
stopGrid(1);
}
}
use of org.apache.ignite.events.Event in project ignite by apache.
the class GridLocalEventListenerSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
int idx = getTestIgniteInstanceIndex(igniteInstanceName);
if (idx == 0) {
Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();
lsnrs.put(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
fired.countDown();
return true;
}
}, new int[] { EventType.EVT_NODE_JOINED });
cfg.setLocalEventListeners(lsnrs);
}
return cfg;
}
Aggregations