Java Code Examples for org.apache.ignite.lang.IgniteFuture#get()

The following examples show how to use org.apache.ignite.lang.IgniteFuture#get() . 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: GridCacheSetProxy.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public void close() {
    IgniteFuture<Boolean> destroyFut = null;

    gate.enter();

    try {
        delegate.close();

        if (delegate.separated()) {
            IgniteInternalFuture<Boolean> fut = cctx.kernalContext().cache().dynamicDestroyCache(
                cctx.cache().name(), false, true, false, null);

            ((GridFutureAdapter)fut).ignoreInterrupts();

            destroyFut = new IgniteFutureImpl<>(fut);
        }
    }
    finally {
        gate.leave();
    }

    if (destroyFut != null)
        destroyFut.get();
}
 
Example 2
Source File: IgniteClusterSnapshotSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** @throws Exception If fails. */
@Test
public void testConcurrentClusterSnapshotFromClient() throws Exception {
    IgniteEx grid = startGridsWithCache(2, dfltCacheCfg, CACHE_KEYS_RANGE);

    IgniteEx clnt = startClientGrid(2);

    IgniteSnapshotManager mgr = snp(grid);
    Function<String, SnapshotSender> old = mgr.localSnapshotSenderFactory();

    BlockingExecutor block = new BlockingExecutor(mgr.snapshotExecutorService());

    mgr.localSnapshotSenderFactory((snpName) ->
        new DelegateSnapshotSender(log, block, old.apply(snpName)));

    IgniteFuture<Void> fut = grid.snapshot().createSnapshot(SNAPSHOT_NAME);

    assertThrowsAnyCause(log,
        () -> clnt.snapshot().createSnapshot(SNAPSHOT_NAME).get(),
        IgniteException.class,
        "Snapshot has not been created");

    block.unblock();
    fut.get();
}
 
Example 3
Source File: IgniteComputeJobOneThreadTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testNoTimeout() throws Exception {
    Ignite ignite = ignite(0);

    IgniteFuture fut = null;

    for (int i = 0; i < 10000; i++) {
        fut = ignite.compute().runAsync(new IgniteRunnable() {
            @Override public void run() {

            }
        });
    }

    fut.get();

    assertTrue(true);
}
 
Example 4
Source File: IgniteCacheManyAsyncOperationsTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testManyAsyncOperations() throws Exception {
    try (Ignite client = startClientGrid(gridCount())) {
        assertTrue(client.configuration().isClientMode());

        IgniteCache<Object, Object> cache = client.cache(DEFAULT_CACHE_NAME);

        final int ASYNC_OPS = cache.getConfiguration(CacheConfiguration.class).getMaxConcurrentAsyncOperations();

        log.info("Number of async operations: " + ASYNC_OPS);

        Map<Integer, byte[]> map = new HashMap<>();

        for (int i = 0; i < 100; i++)
            map.put(i, new byte[128]);

        for (int iter = 0; iter < 3; iter++) {
            log.info("Iteration: " + iter);

            List<IgniteFuture<?>> futs = new ArrayList<>(ASYNC_OPS);

            for (int i = 0; i < ASYNC_OPS; i++) {
                futs.add(cache.putAllAsync(map));

                if (i % 50 == 0)
                    log.info("Created futures: " + (i + 1));
            }

            for (int i = 0; i < ASYNC_OPS; i++) {
                IgniteFuture<?> fut = futs.get(i);

                fut.get();

                if (i % 50 == 0)
                    log.info("Done: " + (i + 1));
            }
        }
    }
}
 
Example 5
Source File: CacheAsyncOperationsTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cache Cache.
 */
private void async1(IgniteCache<Integer, Integer> cache) {
    cache.put(1, 1);

    latch = new CountDownLatch(1);

    IgniteFuture<?> fut1 = cache.putAsync(0, 0);

    IgniteFuture<?> fut2 = cache.getAndPutAsync(1, 2);

    IgniteFuture<?> fut3 = cache.getAndPutAsync(1, 3);

    assertFalse(fut1.isDone());
    assertFalse(fut2.isDone());
    assertFalse(fut3.isDone());

    latch.countDown();

    try {
        fut1.get();

        fail();
    }
    catch (CacheException e) {
        log.info("Expected error: " + e);
    }

    assertEquals(1, fut2.get());
    assertEquals(2, fut3.get());

    assertNull(cache.get(0));
    assertEquals((Integer)3, cache.get(1));
}
 
Example 6
Source File: GridServiceProcessorBatchDeploySelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param client Client.
 * @param async If {@code true}, then async version of deploy method will be used.
 * @param cfgs Service configurations.
 * @param failingCfg Configuration of the failing service.
 * @throws Exception If failed.
 */
private void assertFailingDeploy(Ignite client, boolean async, List<ServiceConfiguration> cfgs,
    ServiceConfiguration failingCfg) throws Exception {

    IgniteFuture<Void> fut = null;

    if (async)
        fut = client.services().deployAllAsync(cfgs);

    try {
        if (async)
            fut.get();
        else
            client.services().deployAll(cfgs);

        fail("Should never reach here.");
    }
    catch (ServiceDeploymentException e) {
        info("Expected exception: " + e.getMessage());

        Collection<ServiceConfiguration> expFails = Collections.singleton(failingCfg);

        Collection<ServiceConfiguration> actFails = e.getFailedConfigurations();

        // Some cfgs may be lazy. Construct ServiceConfiguration from them for comparison.
        Collection<ServiceConfiguration> actFailsCp = new ArrayList<>(actFails.size());

        for (ServiceConfiguration cfg : actFails)
            actFailsCp.add(copyService(cfg));

        assertEqualsCollections(expFails, actFailsCp);
    }
}
 
Example 7
Source File: SnapshotMXBeanImpl.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public void createSnapshot(String snpName) {
    IgniteFuture<Void> fut = mgr.createSnapshot(snpName);

    if (fut.isDone())
        fut.get();
}
 
Example 8
Source File: GridServiceProcessorMultiNodeSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDeployOnEachNodeUpdateTopology() throws Exception {
    // Prestart client node.
    Ignite client = startClientGrid("client", getConfiguration("client"));

    try {
        final String name = "serviceOnEachNodeUpdateTopology";

        IgniteEx g = randomGrid();

        final int prestartedNodes = nodeCount() + 1;

        CountDownLatch latch = new CountDownLatch(prestartedNodes);

        DummyService.exeLatch(name, latch);

        ServiceConfiguration srvcCfg = new ServiceConfiguration();

        srvcCfg.setNodeFilter(new CacheConfiguration.IgniteAllNodesPredicate());
        srvcCfg.setName(name);
        srvcCfg.setMaxPerNodeCount(1);
        srvcCfg.setService(new DummyService());

        IgniteServices svcs = g.services();

        IgniteFuture<?> fut = svcs.deployAsync(srvcCfg);

        info("Deployed service: " + name);

        fut.get();

        info("Finished waiting for service future: " + name);

        latch.await();

        // Ensure service is deployed
        assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));

        assertEquals(name, prestartedNodes, DummyService.started(name));
        assertEquals(name, 0, DummyService.cancelled(name));

        int servers = 2;
        int clients = 2;

        int extraNodes = servers + clients;

        latch = new CountDownLatch(extraNodes);

        DummyService.exeLatch(name, latch);

        startExtraNodes(servers, clients);

        try {
            latch.await();

            waitForDeployment(name, prestartedNodes + extraNodes);

            // Since we start extra nodes, there may be extra start and cancel events,
            // so we check only the difference between start and cancel and
            // not start and cancel events individually.
            assertEquals(name, prestartedNodes + extraNodes,
                DummyService.started(name) - DummyService.cancelled(name));

            checkCount(name, g, prestartedNodes + extraNodes);
        }
        finally {
            stopExtraNodes(extraNodes);
        }
    }
    finally {
        stopGrid("client");
    }
}
 
Example 9
Source File: GridServiceProcessorAbstractSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDeployMultiple1() throws Exception {
    Ignite g = randomGrid();

    String name = "serviceMultiple1";

    CountDownLatch latch = new CountDownLatch(nodeCount() * 2);

    DummyService.exeLatch(name, latch);

    IgniteFuture<?> fut = g.services().deployMultipleAsync(name, new DummyService(), nodeCount() * 2, 3);

    info("Deployed service: " + name);

    fut.get();

    info("Finished waiting for service future: " + name);

    latch.await();

    assertEquals(name, nodeCount() * 2, DummyService.started(name));
    assertEquals(name, 0, DummyService.cancelled(name));

    checkCount(name, g.services().serviceDescriptors(), nodeCount() * 2);
}
 
Example 10
Source File: IgniteClusterSnapshotWithIndexesTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** @throws Exception If fails. */
@Test
public void testClusterSnapshotConsistentConfig() throws Exception {
    String tblName = "PersonCache";
    int grids = 3;

    IgniteEx ignite = startGridsWithoutCache(grids);

    executeSql(ignite, "CREATE TABLE " + tblName + " (id int, name varchar, age int, city varchar, " +
        "primary key (id, name)) WITH \"cache_name=" + tblName + "\"");
    executeSql(ignite, "CREATE INDEX SNP_IDX_0 ON " + tblName + "(age)");

    for (int i = 0; i < CACHE_KEYS_RANGE; i++)
        executeSql(ignite, "INSERT INTO " + tblName + " (id, name, age, city) VALUES(?, 'name', 3, 'city')", i);

    // Blocking configuration local snapshot sender.
    List<BlockingExecutor> execs = setBlockingSnapshotExecutor(G.allGrids());

    IgniteFuture<Void> fut = ignite.snapshot().createSnapshot(SNAPSHOT_NAME);

    List<String> idxNames = Arrays.asList("SNP_IDX_1", "SNP_IDX_2");

    executeSql(ignite, "CREATE INDEX " + idxNames.get(0) + " ON " + tblName + "(city)");
    executeSql(ignite, "CREATE INDEX " + idxNames.get(1) + " ON " + tblName + "(age, city)");

    for (BlockingExecutor exec : execs)
        exec.unblock();

    fut.get();

    stopAllGrids();

    IgniteEx snp = startGridsFromSnapshot(grids, SNAPSHOT_NAME);

    List<String> currIdxNames = executeSql(snp, "SELECT * FROM SYS.INDEXES").stream().
        map(l -> (String)l.get(0))
        .collect(Collectors.toList());

    assertTrue("Concurrently created indexes must not exist in the snapshot: " + currIdxNames,
        Collections.disjoint(idxNames, currIdxNames));

    List<List<?>> results = executeSql(snp, explainSQLStatement(tblName) + "age=2");
    assertUsingSecondaryIndex(results);
}
 
Example 11
Source File: MasterKeyChangeTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * Checks that the cache start will be rejected if group keys generated before the master key change.
 *
 * @throws Exception If failed.
 */
@Test
public void testRejectCacheStartOnClientDuringRotation() throws Exception {
    IgniteEx srv = startGrid(GRID_0);

    IgniteEx client = startClientGrid(getConfiguration("client"));

    srv.cluster().active(true);

    awaitPartitionMapExchange();

    TestRecordingCommunicationSpi commSpi = TestRecordingCommunicationSpi.spi(srv);

    commSpi.blockMessages((node, message) -> message instanceof GenerateEncryptionKeyResponse);

    String cacheName = "userCache";

    IgniteInternalFuture cacheStartFut = runAsync(() -> {
        client.getOrCreateCache(new CacheConfiguration<>(cacheName).setEncryptionEnabled(true));
    });

    commSpi.waitForBlocked();

    IgniteFuture<Void> fut = srv.encryption().changeMasterKey(MASTER_KEY_NAME_2);

    commSpi.stopBlock();

    assertThrowsWithCause(() -> cacheStartFut.get(), IgniteCheckedException.class);

    fut.get();

    assertTrue(checkMasterKeyName(MASTER_KEY_NAME_2));

    createEncryptedCache(srv, client, cacheName(), null);

    checkEncryptedCaches(srv, client);
}
 
Example 12
Source File: GridServiceProcessorAbstractSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testSameConfigurationOld() throws Exception {
    String name = "dupServiceOld";

    IgniteServices svcs1 = randomGrid().services().withAsync();
    IgniteServices svcs2 = randomGrid().services().withAsync();

    svcs1.deployClusterSingleton(name, new DummyService());

    IgniteFuture<?> fut1 = svcs1.future();

    svcs2.deployClusterSingleton(name, new DummyService());

    IgniteFuture<?> fut2 = svcs2.future();

    info("Deployed service: " + name);

    fut1.get();

    info("Finished waiting for service future1: " + name);

    // This must succeed without exception because configuration is the same.
    fut2.get();

    info("Finished waiting for service future2: " + name);
}
 
Example 13
Source File: GridServiceProcessorAbstractSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDeployOnEachNodeOld() throws Exception {
    Ignite g = randomGrid();

    String name = "serviceOnEachNodeOld";

    CountDownLatch latch = new CountDownLatch(nodeCount());

    DummyService.exeLatch(name, latch);

    IgniteServices svcs = g.services().withAsync();

    svcs.deployNodeSingleton(name, new DummyService());

    IgniteFuture<?> fut = svcs.future();

    info("Deployed service: " + name);

    fut.get();

    info("Finished waiting for service future: " + name);

    latch.await();

    assertEquals(name, nodeCount(), DummyService.started(name));
    assertEquals(name, 0, DummyService.cancelled(name));

    checkCount(name, g.services().serviceDescriptors(), nodeCount());
}
 
Example 14
Source File: MasterKeyChangeTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/** @throws Exception If failed. */
@Test
public void testRejectMasterKeyChangeDuringRotation() throws Exception {
    T2<IgniteEx, IgniteEx> grids = startTestGrids(true);

    createEncryptedCache(grids.get1(), grids.get2(), cacheName(), null);

    assertTrue(checkMasterKeyName(DEFAULT_MASTER_KEY_NAME));

    TestRecordingCommunicationSpi commSpi = TestRecordingCommunicationSpi.spi(grids.get2());

    commSpi.blockMessages((node, msg) -> msg instanceof SingleNodeMessage);

    IgniteFuture<Void> fut = grids.get1().encryption().changeMasterKey(MASTER_KEY_NAME_2);

    commSpi.waitForBlocked();

    // Stops block subsequent changes.
    commSpi.stopBlock(false, null, true, false);

    assertThrowsWithCause(() -> grids.get2().encryption().changeMasterKey(MASTER_KEY_NAME_3).get(),
        IgniteException.class);

    // Unblocks first change.
    commSpi.stopBlock();

    fut.get();

    assertTrue(checkMasterKeyName(MASTER_KEY_NAME_2));

    checkEncryptedCaches(grids.get1(), grids.get2());
}
 
Example 15
Source File: GridServiceProcessorBatchDeploySelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testClashingNamesFail() throws Exception {
    Ignite client = grid(CLIENT_NODE_NAME);

    List<ServiceConfiguration> cfgs = getConfigs(client.cluster().forServers().predicate(), NUM_SERVICES);

    int numDepSvcs = NUM_SERVICES - 1;

    CountDownLatch latch = new CountDownLatch(numDepSvcs);

    List<ServiceConfiguration> fstBatch = cfgs.subList(0, NUM_SERVICES / 2);
    List<ServiceConfiguration> sndBatch = cfgs.subList(NUM_SERVICES / 4, NUM_SERVICES);

    subscribeExeLatch(cfgs, latch);

    IgniteFuture<Void> fut = client.services().deployAllAsync(fstBatch);

    ServiceConfiguration failingCfg = cfgs.get(NUM_SERVICES - 1);

    failingCfg.setName(null);

    assertFailingDeploy(client, false, sndBatch, failingCfg);

    fut.get();

    assertTrue("Waiting for services deployment timed out.", latch.await(30, TimeUnit.SECONDS));

    assertDeployedServices(client, cfgs.subList(0, numDepSvcs));
}
 
Example 16
Source File: GridServiceProcessorAbstractSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDeployMultiple2() throws Exception {
    Ignite g = randomGrid();

    String name = "serviceMultiple2";

    int cnt = nodeCount() * 2 + 1;

    CountDownLatch latch = new CountDownLatch(cnt);

    DummyService.exeLatch(name, latch);

    IgniteFuture<?> fut = g.services().deployMultipleAsync(name, new DummyService(), cnt, 3);

    info("Deployed service: " + name);

    fut.get();

    info("Finished waiting for service future: " + name);

    latch.await();

    assertEquals(name, cnt, DummyService.started(name));
    assertEquals(name, 0, DummyService.cancelled(name));

    checkCount(name, g.services().serviceDescriptors(), cnt);
}
 
Example 17
Source File: GridServiceProcessorAbstractSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDifferentConfigurationOld() throws Exception {
    String name = "dupServiceOld";

    IgniteServices svcs1 = randomGrid().services().withAsync();
    IgniteServices svcs2 = randomGrid().services().withAsync();

    svcs1.deployClusterSingleton(name, new DummyService());

    IgniteFuture<?> fut1 = svcs1.future();

    svcs2.deployNodeSingleton(name, new DummyService());

    IgniteFuture<?> fut2 = svcs2.future();

    info("Deployed service: " + name);

    fut1.get();

    info("Finished waiting for service future: " + name);

    try {
        fut2.get();

        fail("Failed to receive mismatching configuration exception.");
    }
    catch (IgniteException e) {
        info("Received mismatching configuration exception: " + e.getMessage());
    }
}
 
Example 18
Source File: GridMessagingSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testAsync() throws Exception {
    final AtomicInteger msgCnt = new AtomicInteger();

    IgniteDiscoverySpi discoSpi = (IgniteDiscoverySpi)ignite2.configuration().getDiscoverySpi();

    DiscoverySpiTestListener lsnr = new DiscoverySpiTestListener();

    discoSpi.setInternalListener(lsnr);

    lsnr.blockCustomEvent(StartRoutineDiscoveryMessage.class, StartRoutineDiscoveryMessageV2.class);

    final String topic = "topic";

    IgniteFuture<UUID> starFut = ignite2.message().remoteListenAsync(topic, new P2<UUID, Object>() {
        @Override public boolean apply(UUID nodeId, Object msg) {
            System.out.println(Thread.currentThread().getName() +
                " Listener received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']');

            msgCnt.incrementAndGet();

            return true;
        }
    });

    Assert.assertNotNull(starFut);

    U.sleep(500);

    Assert.assertFalse(starFut.isDone());

    lsnr.stopBlockCustomEvents();

    UUID id = starFut.get();

    Assert.assertNotNull(id);

    Assert.assertTrue(starFut.isDone());

    lsnr.blockCustomEvent(StopRoutineDiscoveryMessage.class);

    message(ignite1.cluster().forRemotes()).send(topic, "msg1");

    GridTestUtils.waitForCondition(new PA() {
        @Override public boolean apply() {
            return msgCnt.get() > 0;
        }
    }, 5000);

    assertEquals(1, msgCnt.get());

    IgniteFuture<?> stopFut = ignite2.message().stopRemoteListenAsync(id);

    Assert.assertNotNull(stopFut);

    U.sleep(500);

    Assert.assertFalse(stopFut.isDone());

    lsnr.stopBlockCustomEvents();

    stopFut.get();

    Assert.assertTrue(stopFut.isDone());

    message(ignite1.cluster().forRemotes()).send(topic, "msg2");

    U.sleep(1000);

    assertEquals(1, msgCnt.get());
}
 
Example 19
Source File: GridServiceProcessorMultiNodeSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDeployOnEachNodeButClientUpdateTopology() throws Exception {
    // Prestart client node.
    Ignite client = startClientGrid("client", getConfiguration("client"));

    try {
        final String name = "serviceOnEachNodeButClientUpdateTopology";

        IgniteEx g = randomGrid();

        CountDownLatch latch = new CountDownLatch(nodeCount());

        DummyService.exeLatch(name, latch);

        IgniteServices svcs = g.services();

        IgniteFuture<?> fut = svcs.deployNodeSingletonAsync(name, new DummyService());

        info("Deployed service: " + name);

        fut.get();

        info("Finished waiting for service future: " + name);

        latch.await();

        // Ensure service is deployed
        assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));

        assertEquals(name, nodeCount(), DummyService.started(name));
        assertEquals(name, 0, DummyService.cancelled(name));

        int servers = 2;

        latch = new CountDownLatch(servers);

        DummyService.exeLatch(name, latch);

        int clients = 2;

        startExtraNodes(servers, clients);

        try {
            latch.await();

            waitForDeployment(name, servers);

            // Since we start extra nodes, there may be extra start and cancel events,
            // so we check only the difference between start and cancel and
            // not start and cancel events individually.
            assertEquals(name, nodeCount() + servers, DummyService.started(name) - DummyService.cancelled(name));

            checkCount(name, g, nodeCount() + servers);
        }
        finally {
            stopExtraNodes(servers + clients);
        }
    }
    finally {
        stopGrid("client");
    }
}
 
Example 20
Source File: GridServiceProcessorMultiNodeSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testSingletonUpdateTopology() throws Exception {
    String name = "serviceSingletonUpdateTopology";

    IgniteEx g = randomGrid();

    CountDownLatch latch = new CountDownLatch(1);

    DummyService.exeLatch(name, latch);

    IgniteServices svcs = g.services();

    IgniteFuture<?> fut = svcs.deployClusterSingletonAsync(name, new DummyService());

    info("Deployed service: " + name);

    fut.get();

    info("Finished waiting for service future: " + name);

    latch.await();

    Assert.assertEquals(name, 1, DummyService.started(name));
    Assert.assertEquals(name, 0, DummyService.cancelled(name));

    int nodeCnt = 2;

    startExtraNodes(nodeCnt);

    try {
        Assert.assertEquals(name, 1, DummyService.started(name));
        Assert.assertEquals(name, 0, DummyService.cancelled(name));

        info(">>> Passed checks.");

        checkCount(name, g, 1);
    }
    finally {
        stopExtraNodes(nodeCnt);
    }
}