org.apache.ignite.Ignite Java Examples

The following examples show how to use org.apache.ignite.Ignite. 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: CacheMvccConfigurationValidationTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@SuppressWarnings("ThrowableNotThrown")
@Test
public void testMvccModeMismatchForGroup2() throws Exception {
    final Ignite node = startGrid(0);

    node.createCache(
        new CacheConfiguration("cache1").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL_SNAPSHOT));

    GridTestUtils.assertThrows(log, new Callable<Void>() {
        @Override public Void call() {
            node.createCache(new CacheConfiguration("cache2").setGroupName("grp1").setAtomicityMode(ATOMIC));

            return null;
        }
    }, CacheException.class, null);

    node.createCache(
        new CacheConfiguration("cache2").setGroupName("grp1").setAtomicityMode(TRANSACTIONAL_SNAPSHOT));
}
 
Example #2
Source File: GridCacheClearLocallySelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Startup routine.
 *
 * @throws Exception If failed.
 */
private void startUp() throws Exception {
    cachesLoc = (IgniteCache<Integer, Integer>[])Array.newInstance(IgniteCache.class, GRID_CNT);
    cachesPartitioned = (IgniteCache<Integer, Integer>[])Array.newInstance(IgniteCache.class, GRID_CNT);
    cachesColocated = (IgniteCache<Integer, Integer>[])Array.newInstance(IgniteCache.class, GRID_CNT);
    cachesReplicated = (IgniteCache<Integer, Integer>[])Array.newInstance(IgniteCache.class, GRID_CNT);

    for (int i = 0; i < GRID_CNT; i++) {
        Ignite ignite = startGrid(i);

        if (i == 1) {
            NearCacheConfiguration nearCfg = new NearCacheConfiguration();

            ignite.createNearCache(CACHE_PARTITIONED, nearCfg);
        }

        if (i == 2)
            ignite.cache(CACHE_PARTITIONED);

        cachesLoc[i] = ignite.cache(CACHE_LOCAL);
        cachesPartitioned[i] = ignite.cache(CACHE_PARTITIONED);
        cachesColocated[i] = ignite.cache(CACHE_COLOCATED);
        cachesReplicated[i] = ignite.cache(CACHE_REPLICATED);
    }
}
 
Example #3
Source File: IgniteWalReaderTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and fills cache with data.
 *
 * @param ig Ignite instance.
 * @param mode Cache Atomicity Mode.
 */
private void createCache2(Ignite ig, CacheAtomicityMode mode) {
    if (log.isInfoEnabled())
        log.info("Populating the cache...");

    final CacheConfiguration<Integer, Organization> cfg = new CacheConfiguration<>("Org" + "11");
    cfg.setAtomicityMode(mode);
    final IgniteCache<Integer, Organization> cache = ig.getOrCreateCache(cfg).withKeepBinary()
        .withAllowAtomicOpsInTx();

    try (Transaction tx = ig.transactions().txStart()) {
        for (int i = 0; i < 10; i++) {

            cache.put(i, new Organization(i, "Organization-" + i));

            if (i % 2 == 0)
                cache.put(i, new Organization(i, "Organization-updated-" + i));

            if (i % 5 == 0)
                cache.remove(i);
        }
        tx.commit();
    }

}
 
Example #4
Source File: ClosureServiceClientsNodesTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testClientClosure() throws Exception {
    for (int i = 0; i < NODES_CNT; i++) {
        log.info("Iteration: " + i);

        Ignite ignite = grid(i);

        Collection<String> res = ignite.compute(ignite.cluster().forClients()).
            broadcast(new IgniteCallable<String>() {
                @IgniteInstanceResource
                Ignite ignite;

                @Override public String call() throws Exception {
                    assertTrue(ignite.configuration().isClientMode());

                    return ignite.name();
                }
            });

        assertEquals(1, res.size());

        assertEquals(getTestIgniteInstanceName(CLIENT_IDX), F.first(res));
    }
}
 
Example #5
Source File: CacheOperationPermissionCreateDestroyCheckTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
@Test
public void testDestroyCacheWithSystemPermissions() throws Exception {
    SecurityPermissionSet secPermSet = builder()
        .appendSystemPermissions(CACHE_DESTROY)
        .build();

    grid(SRV).createCache(CACHE_NAME);

    try (Ignite node = startGrid(TEST_NODE, secPermSet, clientMode)) {
        assertThrowsWithCause(() -> forbidden(clientMode).destroyCache(CACHE_NAME), SecurityException.class);

        node.destroyCache(CACHE_NAME);

        assertNull(grid(SRV).cache(CACHE_NAME));
    }
}
 
Example #6
Source File: CacheMvccTransactionsTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception if failed.
 */
@Test
public void testEmptyTx() throws Exception {
    Ignite node = startGrids(2);

    IgniteCache cache = node.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, DFLT_PARTITION_COUNT));

    cache.putAll(Collections.emptyMap());

    IgniteTransactions txs = node.transactions();
    try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
        tx.commit();
    }
    finally {
        stopAllGrids();
    }
}
 
Example #7
Source File: IgniteCacheMessageRecoveryAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param ignite Node.
 * @throws Exception If failed.
 * @return {@code True} if closed at least one session.
 */
static boolean closeSessions(Ignite ignite) throws Exception {
    TcpCommunicationSpi commSpi = (TcpCommunicationSpi)ignite.configuration().getCommunicationSpi();

    Map<UUID, GridCommunicationClient[]> clients = U.field(commSpi, "clients");

    boolean closed = false;

    for (GridCommunicationClient[] clients0 : clients.values()) {
        for (GridCommunicationClient client : clients0) {
            if (client != null) {
                GridTcpNioCommunicationClient client0 = (GridTcpNioCommunicationClient)client;

                GridNioSession ses = client0.session();

                ses.close();

                closed = true;
            }
        }
    }

    return closed;
}
 
Example #8
Source File: IgnitePersistentStoreTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
@Test
public void pojoStrategyTransactionTest() {
    CassandraHelper.dropTestKeyspaces();

    Ignition.stopAll(true);

    try (Ignite ignite = Ignition.start("org/apache/ignite/tests/persistence/pojo/ignite-config.xml")) {
        pojoStrategyTransactionTest(ignite, TransactionConcurrency.OPTIMISTIC, TransactionIsolation.READ_COMMITTED);
        pojoStrategyTransactionTest(ignite, TransactionConcurrency.OPTIMISTIC, TransactionIsolation.REPEATABLE_READ);
        pojoStrategyTransactionTest(ignite, TransactionConcurrency.OPTIMISTIC, TransactionIsolation.SERIALIZABLE);
        pojoStrategyTransactionTest(ignite, TransactionConcurrency.PESSIMISTIC, TransactionIsolation.READ_COMMITTED);
        pojoStrategyTransactionTest(ignite, TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ);
        pojoStrategyTransactionTest(ignite, TransactionConcurrency.PESSIMISTIC, TransactionIsolation.SERIALIZABLE);
    }
}
 
Example #9
Source File: GridContinuousJobAnnotationSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param jobCls Job class.
 * @throws Exception If test failed.
 */
public void testContinuousJobAnnotation(Class<?> jobCls) throws Exception {
    try {
        Ignite ignite = startGrid(0);
        startGrid(1);

        fail.set(true);

        ignite.compute().execute(TestTask.class, jobCls);

        Exception e = err.get();

        if (e != null)
            throw e;
    }
    finally {
        stopGrid(0);
        stopGrid(1);
    }

    assertEquals(2, afterSendCnt.getAndSet(0));
    assertEquals(1, beforeFailoverCnt.getAndSet(0));
}
 
Example #10
Source File: HelloIgniteSpring.java    From ignite-book-code-samples with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
    // Start Ignite cluster
    Ignite ignite = Ignition.start("default-config.xml");

    // get or create cache
    IgniteCache<Integer, Person> cache =  ignite.getOrCreateCache("testCache");
    Person p1 = new Person(37, "Shamim");
    Person p2 = new Person(2, "Mishel");
    Person p3 = new Person(55, "scott");
    Person p4 = new Person(5, "Tiger");

    cache.put(1, p1);
    cache.put(2, p2);
    cache.put(3, p3);
    cache.put(4, p4);

    System.out.println("Enter crtl-x to quite the application!!!");

}
 
Example #11
Source File: TcpDiscoveryWithWrongServerTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Some simple sanity check with the Server and Client
 * It is expected that both client and server could successfully perform Discovery Procedure when there is
 * unknown (test) server in the ipFinder list.
 */
private void simpleTest() {
    try {
        Ignite srv = startGrid("server");
        Ignite client = startClientGrid("client");

        awaitPartitionMapExchange();

        assertEquals(2, srv.cluster().nodes().size());
        assertEquals(2, client.cluster().nodes().size());
        assertTrue(connCnt.get() >= 2);

        srv.getOrCreateCache(DEFAULT_CACHE_NAME).put(1, 1);

        assertEquals(1, client.getOrCreateCache(DEFAULT_CACHE_NAME).get(1));
    }
    catch (Exception e) {
        fail("Failed with unexpected exception: " + e.getMessage());
    }
}
 
Example #12
Source File: AttributeNodeFilterSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testClusterGroup() throws Exception {
    Ignite group1 = startGridsMultiThreaded(3);

    attrs = F.asMap("group", "data");

    Ignite group2 = startGridsMultiThreaded(3, 2);

    assertEquals(2, group1.cluster().forPredicate(new AttributeNodeFilter("group", "data")).nodes().size());
    assertEquals(2, group2.cluster().forPredicate(new AttributeNodeFilter("group", "data")).nodes().size());

    assertEquals(3, group1.cluster().forPredicate(new AttributeNodeFilter("group", null)).nodes().size());
    assertEquals(3, group2.cluster().forPredicate(new AttributeNodeFilter("group", null)).nodes().size());

    assertEquals(0, group1.cluster().forPredicate(new AttributeNodeFilter("group", "wrong")).nodes().size());
    assertEquals(0, group2.cluster().forPredicate(new AttributeNodeFilter("group", "wrong")).nodes().size());
}
 
Example #13
Source File: IgniteCacheConfigurationTemplateTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param nodes Nodes number.
 */
private void checkNoTemplateCaches(int nodes) {
    for (int i = 0; i < nodes; i++) {
        final Ignite ignite = grid(i);

        GridTestUtils.assertThrows(log, new Callable<Void>() {
            @Override public Void call() throws Exception {
                ignite.cache(GridCacheUtils.UTILITY_CACHE_NAME);

                return null;
            }
        }, IllegalStateException.class, null);

        assertNull(ignite.cache(TEMPLATE1));
        assertNull(ignite.cache(TEMPLATE2));
        assertNull(ignite.cache(TEMPLATE3));
    }
}
 
Example #14
Source File: IgniteStartCacheInTransactionSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testGetOrCreateCache() throws Exception {
    final Ignite ignite = grid(0);

    final String key = "key";
    final String val = "val";

    IgniteCache<String, String> cache = ignite.cache(DEFAULT_CACHE_NAME).withAllowAtomicOpsInTx();

    try (Transaction tx = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        cache.put(key, val);

        GridTestUtils.assertThrows(log, new Callable<Object>() {
            @Override public Object call() throws Exception {
                ignite.getOrCreateCache("NEW_CACHE");

                return null;
            }
        }, IgniteException.class, EXPECTED_MSG);

        tx.commit();
    }
}
 
Example #15
Source File: EventsExample.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Listen to events that happen only on local node.
 *
 * @throws IgniteException If failed.
 */
private static void localListen() throws IgniteException {
    System.out.println();
    System.out.println(">>> Local event listener example.");

    Ignite ignite = Ignition.ignite();

    IgnitePredicate<TaskEvent> lsnr = evt -> {
        System.out.println("Received task event [evt=" + evt.name() + ", taskName=" + evt.taskName() + ']');

        return true; // Return true to continue listening.
    };

    // Register event listener for all local task execution events.
    ignite.events().localListen(lsnr, EVTS_TASK_EXECUTION);

    // Generate task events.
    ignite.compute().withName("example-event-task").run(() -> System.out.println("Executing sample job."));

    // Unsubscribe local task event listener.
    ignite.events().stopLocalListen(lsnr);
}
 
Example #16
Source File: SqlStatisticsAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Start the cache with a test table and test data.
 */
protected IgniteCache createCacheFrom(Ignite node) {
    CacheConfiguration<Integer, String> ccfg = new CacheConfiguration<Integer, String>(DEFAULT_CACHE_NAME)
        .setSqlFunctionClasses(SuspendQuerySqlFunctions.class)
        .setQueryEntities(Collections.singleton(
            new QueryEntity(Integer.class.getName(), String.class.getName())
                .setTableName("TAB")
                .addQueryField("id", Integer.class.getName(), null)
                .addQueryField("name", String.class.getName(), null)
                .setKeyFieldName("id")
                .setValueFieldName("name")
        ));

    IgniteCache<Integer, String> cache = node.createCache(ccfg);

    try (IgniteDataStreamer<Object, Object> ds = node.dataStreamer(DEFAULT_CACHE_NAME)) {
        for (int i = 0; i < TABLE_SIZE; i++)
            ds.addData(i, UUID.randomUUID().toString());
    }

    return cache;
}
 
Example #17
Source File: IgnitePdsPageReplacementDuringPartitionClearTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param ig Ignite instance.
 * @param stopFlag Stop flag.
 * @param start Load key start index.
 * @return Completion future.
 */
private IgniteInternalFuture<?> loadAsync(Ignite ig, AtomicBoolean stopFlag, int start) {
    AtomicInteger generator = new AtomicInteger(start);

    return GridTestUtils.runMultiThreadedAsync(new GridPlainRunnable() {
        @Override public void run() {
            IgniteCache<Integer, TestValue> cache = ig.cache(CACHE_NAME);

            while (!stopFlag.get()) {
                int idx = generator.getAndAdd(100);

                Map<Integer, TestValue> putMap = new HashMap<>(100, 1.f);

                for (int i = 0; i < 100; i++)
                    putMap.put(idx + i, new TestValue(idx + i));

                cache.putAll(putMap);
            }
        }
    }, Runtime.getRuntime().availableProcessors(), "load-runner");
}
 
Example #18
Source File: CacheMvccStreamingInsertTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
    super.beforeTest();

    Ignite ignite = startGrid(0);
    sqlNexus = ignite.getOrCreateCache(new CacheConfiguration<>("sqlNexus").setSqlSchema("PUBLIC"));
    sqlNexus.query(q("" +
        "create table person(" +
        "  id int not null primary key," +
        "  name varchar not null" +
        ") with \"atomicity=transactional_snapshot\""
    ));

    Properties props = new Properties();
    props.setProperty(IgniteJdbcDriver.PROP_STREAMING, "true");
    conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1", props);
}
 
Example #19
Source File: IgniteComputeConfigVariationsFullApiTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testMultiCacheAffinityRunAsync() throws Exception {
    runTest(runnableFactories, new ComputeTest() {
        @Override public void test(Factory factory, Ignite ignite) throws Exception {
            ignite.getOrCreateCache("test0");
            ignite.getOrCreateCache("test1");

            final IgniteCompute comp = ignite.compute();

            for (int i = 0; i < MAX_JOB_COUNT; ++i) {
                IgniteRunnable job = (IgniteRunnable)factory.create();

                IgniteFuture<Void> fut = comp.affinityRunAsync(Arrays.asList("test0", "test1"), key(0), job);

                fut.get();
            }
        }
    });
}
 
Example #20
Source File: CacheExchangeMergeTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param crd Exchange coordinator.
 * @param topVer Exchange topology version.
 */
private void blockExchangeFinish(Ignite crd, long topVer) {
    final AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(topVer);

    TestRecordingCommunicationSpi.spi(crd).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
        @Override public boolean apply(ClusterNode node, Message msg) {
            if (msg instanceof GridDhtPartitionsFullMessage) {
                GridDhtPartitionsFullMessage msg0 = (GridDhtPartitionsFullMessage)msg;

                return msg0.exchangeId() != null && msg0.exchangeId().topologyVersion().equals(topVer0);
            }

            return false;
        }
    });
}
 
Example #21
Source File: GridCacheReloadSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Actual test logic.
 *
 * @throws Exception If error occurs.
 */
private void doTest() throws Exception {
    Ignite ignite = startGrid();

    try {
        IgniteCache<Integer, Integer> cache = ignite.cache(CACHE_NAME);

        for (int i = 0; i < N_ENTRIES; i++)
            load(cache, i, true);

        assertEquals(MAX_CACHE_ENTRIES, cache.size(CachePeekMode.ONHEAP));
    }
    finally {
        stopGrid();
    }
}
 
Example #22
Source File: GridCacheAbstractLocalStoreSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testEvict() throws Exception {
    Ignite ignite1 = startGrid(1);

    IgniteCache<Object, Object> cache = ignite1.cache(DEFAULT_CACHE_NAME).withExpiryPolicy(new CreatedExpiryPolicy(
        new Duration(TimeUnit.MILLISECONDS, 100L)));

    // Putting entry.
    for (int i = 0; i < KEYS; i++)
        cache.put(i, i);

    // Wait when entry
    U.sleep(200);

    // Check that entry is evicted from cache, but local store does contain it.
    for (int i = 0; i < KEYS; i++) {
        cache.localEvict(Arrays.asList(i));

        assertNull(cache.localPeek(i));

        assertEquals(i, (int)LOCAL_STORE_1.load(i).get1());

        assertEquals(i, cache.get(i));
    }
}
 
Example #23
Source File: SecuritySubjectPermissionsTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** */
@Test
public void test() throws Exception {
    Ignite srv = startGrid("srv", ALLOW_ALL, false);

    Permissions perms = new Permissions();
    // Permission that Ignite and subject do have.
    perms.add(new TestPermission("common"));
    // Permission that Ignite does not have.
    perms.add(new TestPermission("only_subject"));

    Ignite clnt = startGrid("clnt", ALLOW_ALL, perms, true);

    srv.cluster().active(true);

    clnt.compute().broadcast(() -> securityManager().checkPermission(new TestPermission("common")));

    assertThrowsWithCause(() -> clnt.compute().broadcast(
        () -> {
            securityManager().checkPermission(new TestPermission("only_subject"));

            fail();
        }),
        AccessControlException.class);
}
 
Example #24
Source File: GridFactorySelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Tests named grid
 */
@Test
public void testNamedGridGetOrStart() throws Exception {
    IgniteConfiguration cfg = getConfiguration("test");
    try (Ignite ignite = Ignition.getOrStart(cfg)) {
        try {
            Ignition.start(cfg);

            fail("Expected exception after grid started");
        }
        catch (IgniteException ignored) {
            // No-op.
        }

        Ignite ignite2 = Ignition.getOrStart(cfg);

        assertEquals("Must return same instance", ignite, ignite2);
    }

    assertTrue(G.allGrids().isEmpty());
}
 
Example #25
Source File: ForkJoinWithCheckpointComputation.java    From ignite-book-code-samples with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {

        try (Ignite ignite = Ignition.start(CLIENT_CONFIG)) {
            IgniteCompute compute = ignite.compute();
            CacheConfiguration cacheConfiguration = new CacheConfiguration("checkpoints");
            // explicitly uses of checkpoint
            CacheCheckpointSpi cacheCheckpointSpi = new CacheCheckpointSpi();
            cacheCheckpointSpi.setCacheName("checkpointCache");
            //cacheConfiguration.setC
            ignite.configuration().setCheckpointSpi(cacheCheckpointSpi)
                                  .setFailoverSpi(new AlwaysFailoverSpi());
            // create or get cache
            ignite.getOrCreateCache(cacheConfiguration);

            ValidateMessage[] validateMessages = TestDataGenerator.getValidateMessages();

            Boolean result = compute.execute(new ForkJoinWithCheckpointComputation(), validateMessages);
            System.out.println("final result=" + result);
        }
    }
 
Example #26
Source File: GridCacheReplicatedPreloadStartStopEventsSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testStartStopEvents() throws Exception {
    Ignite ignite = startGrid(0);

    final AtomicInteger preloadStartCnt = new AtomicInteger();
    final AtomicInteger preloadStopCnt = new AtomicInteger();

    ignite.events().localListen(new IgnitePredicate<Event>() {
        @Override public boolean apply(Event e) {
            if (e.type() == EVT_CACHE_REBALANCE_STARTED)
                preloadStartCnt.incrementAndGet();
            else if (e.type() == EVT_CACHE_REBALANCE_STOPPED)
                preloadStopCnt.incrementAndGet();
            else
                fail("Unexpected event type: " + e.type());

            return true;
        }
    }, EVT_CACHE_REBALANCE_STARTED, EVT_CACHE_REBALANCE_STOPPED);

    startGrid(1);

    startGrid(2);

    startGrid(3);

    assertTrue("Unexpected start count: " + preloadStartCnt.get(), preloadStartCnt.get() <= 1);
    assertTrue("Unexpected stop count: " + preloadStopCnt.get(), preloadStopCnt.get() <= 1);
}
 
Example #27
Source File: IgniteCacheCommitDelayTxRecoveryTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override public Void process(MutableEntry<Integer, Integer> entry, Object... args) {
    Ignite ignite = entry.unwrap(Ignite.class);

    System.out.println(Thread.currentThread().getName() + " process [node=" + ignite.name() +
        ", commit=" + commit + ", skipFirst=" + skipFirst + ']');

    boolean skip = false;

    if (commit && ignite.name().equals(skipFirst)) {
        skipFirst = null;

        skip = true;
    }

    if (!skip && commit && nodeNames.contains(ignite.name())) {
        try {
            System.out.println(Thread.currentThread().getName() + " start process invoke.");

            assertTrue(commitStartedLatch != null && commitStartedLatch.getCount() > 0);

            commitStartedLatch.countDown();

            assertTrue(commitFinishLatch.await(10, SECONDS));

            System.out.println(Thread.currentThread().getName() + " end process invoke.");
        }
        catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    else
        System.out.println(Thread.currentThread().getName() + " invoke set value.");

    entry.setValue(1);

    return null;
}
 
Example #28
Source File: CacheGetRemoveSkipStoreTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception if failed.
 */
private void checkNoNullReads(Ignite client, CacheConfiguration<Integer, Integer> ccfg) throws Exception {
    client.getOrCreateCache(ccfg);

    try {
        checkNoNullReads(client.cache(ccfg.getName()), 0);
        checkNoNullReads(grid(0).cache(ccfg.getName()), primaryKey(grid(0).cache(ccfg.getName())));

        if (ccfg.getBackups() > 0)
            checkNoNullReads(grid(0).cache(ccfg.getName()), backupKey(grid(0).cache(ccfg.getName())));
    }
    finally {
        client.destroyCache(ccfg.getName());
    }
}
 
Example #29
Source File: GridCacheColocatedDebugTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testWriteThrough() throws Exception {
    storeEnabled = true;

    startGridsMultiThreaded(3);

    Ignite g0 = grid(0);
    Ignite g1 = grid(1);
    Ignite g2 = grid(2);

    try {
        // Check local commit.
        int k0 = forPrimary(g0);
        int k1 = forPrimary(g0, k0);
        int k2 = forPrimary(g0, k1);

        checkStoreWithValues(F.asMap(k0, String.valueOf(k0), k1, String.valueOf(k1), k2, String.valueOf(k2)));

        // Reassign keys.
        k1 = forPrimary(g1);
        k2 = forPrimary(g2);

        checkStoreWithValues(F.asMap(k0, String.valueOf(k0), k1, String.valueOf(k1), k2, String.valueOf(k2)));

        // Check remote only.

        checkStoreWithValues(F.asMap(k1, String.valueOf(k1), k2, String.valueOf(k2)));
    }
    finally {
        stopAllGrids();
    }
}
 
Example #30
Source File: GridCommonAbstractTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Get or create instance of cache specified by K,V types;
 * new instance of cache is created
 *
 * @param ig Ignite.
 * @param ccfg Cache configuration.
 * @param name Cache name.
 * @return cache instance
 */
@SuppressWarnings("unchecked")
protected <K, V> IgniteCache<K, V> jcache(Ignite ig,
    CacheConfiguration ccfg,
    @NotNull String name) {
    CacheConfiguration<K, V> cc = new CacheConfiguration<>(ccfg);
    cc.setName(name);

    return ig.getOrCreateCache(cc);
}