Java Code Examples for org.apache.ignite.Ignite#events()

The following examples show how to use org.apache.ignite.Ignite#events() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TcpDiscoveryNodeAttributesUpdateOnReconnectTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testReconnect() throws Exception {
    Ignite srv = startGrid("server");

    IgniteEvents evts = srv.events();

    evts.enableLocal(EventType.EVTS_DISCOVERY_ALL);
    evts.localListen(new IgnitePredicate<Event>() {
        @Override public boolean apply(Event evt) {
            ClusterNode node = ((DiscoveryEvent)evt).eventNode();

            rejoinAttr = node.attribute("test");

            return true;
        }
    }, EventType.EVT_NODE_JOINED);

    Ignite client = startClientGrid("client");

    reconnectClientNode(log, client, srv, null);

    assertEquals("2", rejoinAttr);
}
 
Example 2
Source File: GridEventStorageRuntimeConfigurationSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testEnableDisable() throws Exception {
    inclEvtTypes = null;

    try {
        Ignite g = startGrid();

        IgniteEvents evts = g.events();

        evts.enableLocal(EVT_CACHE_OBJECT_PUT);

        evts.disableLocal(EVT_CACHE_OBJECT_PUT);

        for (int evtType : evts.enabledEvents())
            assertFalse(evtType == EVT_CACHE_OBJECT_PUT);
    }
    finally {
        stopAllGrids();
    }
}
 
Example 3
Source File: GridCacheAbstractFullApiSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param ignite Node.
 * @param cache Cache.
 * @param async Use async API.
 * @param oldAsync Use old async API.
 * @throws Exception If failed.
 */
private void doTransformResourceInjection(Ignite ignite, IgniteCache<String, Integer> cache, boolean async,
    boolean oldAsync) throws Exception {
    final Collection<ResourceType> required = Arrays.asList(ResourceType.IGNITE_INSTANCE,
        ResourceType.CACHE_NAME,
        ResourceType.LOGGER);

    final CacheEventListener lsnr = new CacheEventListener();

    IgniteEvents evts = ignite.events(ignite.cluster());

    UUID opId = evts.remoteListen(lsnr, null, EVT_CACHE_OBJECT_READ);

    try {
        checkResourceInjectionOnInvoke(cache, required, async, oldAsync);

        checkResourceInjectionOnInvokeAll(cache, required, async, oldAsync);

        checkResourceInjectionOnInvokeAllMap(cache, required, async, oldAsync);
    }
    finally {
        evts.stopRemoteListen(opId);
    }
}
 
Example 4
Source File: IgniteWalReaderTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Tests time out based WAL segment archiving.
 *
 * @throws Exception if failure occurs.
 */
@Test
public void testArchiveIncompleteSegmentAfterInactivity() throws Exception {
    AtomicBoolean waitingForEvt = new AtomicBoolean();

    CountDownLatch archiveSegmentForInactivity = new CountDownLatch(1);

    archiveIncompleteSegmentAfterInactivityMs = 1000;

    Ignite ignite = startGrid();

    ignite.cluster().active(true);

    IgniteEvents evts = ignite.events();

    evts.localListen(e -> {
        WalSegmentArchivedEvent archComplEvt = (WalSegmentArchivedEvent)e;

        long idx = archComplEvt.getAbsWalSegmentIdx();

        log.info("Finished archive for segment [" + idx + ", " +
            archComplEvt.getArchiveFile() + "]: [" + e + ']');

        if (waitingForEvt.get())
            archiveSegmentForInactivity.countDown();

        return true;
    }, EVT_WAL_SEGMENT_ARCHIVED);

    putDummyRecords(ignite, 100);

    waitingForEvt.set(true); // Flag for skipping regular log() and rollOver().

    log.info("Wait for archiving segment for inactive grid started");

    boolean recordedAfterSleep = archiveSegmentForInactivity.await(
        archiveIncompleteSegmentAfterInactivityMs + 1001, TimeUnit.MILLISECONDS);

    stopGrid();

    assertTrue(recordedAfterSleep);
}
 
Example 5
Source File: IgniteWalReaderTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Tests archive completed event is fired.
 *
 * @throws Exception if failed.
 */
@Test
public void testFillWalForExactSegmentsCount() throws Exception {
    customWalMode = WALMode.FSYNC;

    CountDownLatch reqSegments = new CountDownLatch(15);

    Ignite ignite = startGrid();

    ignite.cluster().active(true);

    final IgniteEvents evts = ignite.events();

    if (!evts.isEnabled(EVT_WAL_SEGMENT_ARCHIVED))
        fail("nothing to test");

    evts.localListen(e -> {
        WalSegmentArchivedEvent archComplEvt = (WalSegmentArchivedEvent)e;

        long idx = archComplEvt.getAbsWalSegmentIdx();

        log.info("Finished archive for segment [" + idx + ", " +
            archComplEvt.getArchiveFile() + "]: [" + e + "]");

        reqSegments.countDown();

        return true;
    }, EVT_WAL_SEGMENT_ARCHIVED);

    int totalEntries = 0;

    while (reqSegments.getCount() > 0) {
        int write = 500;

        putAllDummyRecords(ignite, write);

        totalEntries += write;

        Assert.assertTrue("Too much entries generated, but segments was not become available",
            totalEntries < 10000);
    }

    String subfolderName = genDbSubfolderName(ignite, 0);

    stopGrid();

    String workDir = U.defaultWorkDirectory();

    IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log);

    IteratorParametersBuilder iterParametersBuilder = createIteratorParametersBuilder(workDir, subfolderName);

    iterParametersBuilder.filesOrDirs(workDir);

    scanIterateAndCount(
        factory,
        iterParametersBuilder,
        totalEntries,
        0,
        null,
        null
    );
}