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

The following examples show how to use org.apache.ignite.Ignite#createCache() . 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: 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 2
Source File: BinaryTypeMismatchLoggingTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception In case of an error.
 */
@Test
public void testValueWriteQueryEntities() throws Exception {
    Ignite ignite = startGridWithLogCapture();

    LinkedHashMap<String, String> fields = new LinkedHashMap<>();
    fields.put("id", "java.lang.Integer");
    fields.put("str", "java.lang.String");

    IgniteCache<Integer, Object> binary = ignite.createCache(new CacheConfiguration<Integer, Object>()
        .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity()
            .setKeyFieldName("id").setValueType("Payload").setFields(fields).setTableName("binary"))));

    binary.put(1, new Payload("foo"));
    binary.put(2, new IdKey(2));

    assertEquals(0, countRows(binary));

    assertContainsExactlyOnce(capture.toString(), MESSAGE_PAYLOAD_VALUE);
    assertContainsExactlyOnce(capture.toString(),
        "expValType=Payload, actualValType=o.a.i.i.processors.cache.BinaryTypeMismatchLoggingTest$IdKey");
}
 
Example 3
Source File: BinaryTypeMismatchLoggingTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception In case of an error.
 */
@Test
public void testValueReadCreateTable() throws Exception {
    Ignite ignite = startGrid(0);

    IgniteCache def = ignite.createCache("default");

    def.query(new SqlFieldsQuery("CREATE TABLE binary (id INT PRIMARY KEY, str VARCHAR) " +
        "WITH \"cache_name=binary, value_type=Payload\"").setSchema("PUBLIC"));

    def.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (1, 'foo');").setSchema("PUBLIC"));
    def.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (2, 'bar');").setSchema("PUBLIC"));

    GridTestUtils.assertThrowsAnyCause(
        log,
        new Callable<Object>() {
            @Override public Object call() {
                return ignite.cache("binary").get(1);
            }
        },
        BinaryInvalidTypeException.class,
        "Payload");
}
 
Example 4
Source File: CacheMvccSqlQueriesAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
     * @throws Exception If failed.
     */
    @Test
    public void testSqlQueriesWithMvcc() throws Exception {
        Ignite srv0 = startGrid(0);

        IgniteCache<Integer, MvccTestSqlIndexValue> cache = (IgniteCache)srv0.createCache(
            cacheConfiguration(cacheMode(), FULL_SYNC, 0, DFLT_PARTITION_COUNT).
                setIndexedTypes(Integer.class, MvccTestSqlIndexValue.class));

        for (int i = 0; i < 10; i++)
            cache.put(i, new MvccTestSqlIndexValue(i));

        sqlQueriesWithMvcc(cache, true);

        sqlQueriesWithMvcc(cache, false);

        // TODO IGNITE-8031
//        startGrid(1);
//
//        awaitPartitionMapExchange();
//
//        sqlQueriesWithMvcc(cache, false);
    }
 
Example 5
Source File: CacheSerializableTransactionsTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testTxCommitReadWriteTwoNodes() throws Exception {
    Ignite ignite0 = ignite(0);

    final IgniteTransactions txs = ignite0.transactions();

    for (CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) {
        logCacheInfo(ccfg);

        try {
            IgniteCache<Integer, Integer> cache = ignite0.createCache(ccfg);

            Integer key0 = primaryKey(ignite(0).cache(DEFAULT_CACHE_NAME));
            Integer key1 = primaryKey(ignite(1).cache(DEFAULT_CACHE_NAME));

            try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) {
                cache.put(key0, key0);

                cache.get(key1);

                tx.commit();
            }
        }
        finally {
            destroyCache(ccfg.getName());
        }
    }
}
 
Example 6
Source File: CrossCacheTxRandomOperationsTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param cacheMode Cache mode.
 * @param writeSync Write synchronization mode.
 * @param nearCache Near cache flag.
 * @param ignite Node to use.
 * @param name Cache name.
 */
protected void createCache(CacheMode cacheMode,
    CacheWriteSynchronizationMode writeSync,
    boolean nearCache,
    Ignite ignite,
    String name) {
    ignite.createCache(cacheConfiguration(name, cacheMode, writeSync, nearCache));
}
 
Example 7
Source File: CacheOffheapBatchIndexingMultiTypeTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param iterations Number of iterations.
 * @param entitiesCnt Number of entities to put.
 * @param entityClasses Entity classes.
 * @param preloadInStreamer Data preload flag.
 */
private void doStreamerBatchTest(int iterations,
    int entitiesCnt,
    Class<?>[] entityClasses,
    boolean preloadInStreamer) {
    Ignite ignite = grid(0);

    final IgniteCache<Object, Object> cache =
        ignite.createCache(cacheConfiguration(entityClasses));

    try {
        if (preloadInStreamer)
            preload(cache.getName());

        while (iterations-- >= 0) {
            Map<Integer, Person> putMap1 = new TreeMap<>();

            for (int i = 0; i < entitiesCnt; i++)
                putMap1.put(i, new Person(i, i + 1, String.valueOf(i), String.valueOf(i + 1), salary(i)));

            cache.putAll(putMap1);

            Map<Integer, Organization> putMap2 = new TreeMap<>();

            for (int i = entitiesCnt / 2; i < entitiesCnt * 3 / 2; i++) {
                cache.remove(i);

                putMap2.put(i, new Organization(i, String.valueOf(i)));
            }

            cache.putAll(putMap2);
        }
    }
    finally {
        cache.destroy();
    }
}
 
Example 8
Source File: ANNClassificationExample.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Fills cache with data and returns it.
 *
 * @param ignite Ignite instance.
 * @return Filled Ignite Cache.
 */
private static IgniteCache<Integer, double[]> getTestCache(Ignite ignite) {
    CacheConfiguration<Integer, double[]> cacheConfiguration = new CacheConfiguration<>();
    cacheConfiguration.setName("TEST_" + UUID.randomUUID());
    cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 10));

    IgniteCache<Integer, double[]> cache = ignite.createCache(cacheConfiguration);

    for (int k = 0; k < 10; k++) { // multiplies the Iris dataset k times.
        for (int i = 0; i < data.length; i++)
            cache.put(k * 10000 + i, mutate(data[i], k));
    }

    return cache;
}
 
Example 9
Source File: BinaryTypeMismatchLoggingTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception In case of an error.
 */
@Test
public void testEntryReadQueryEntities() throws Exception {
    Ignite ignite = startGrid(0);

    LinkedHashMap<String, String> fields = new LinkedHashMap<>();
    fields.put("id", "java.lang.Integer");
    fields.put("str", "java.lang.String");

    IgniteCache binary = ignite.createCache(new CacheConfiguration<>()
        .setName("binary").setQueryEntities(Collections.singleton(new QueryEntity()
            .setKeyType("IdKey").setKeyFields(Collections.singleton("id"))
            .setValueType("Payload").setFields(fields).setTableName("binary"))));

    binary.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (1, 'foo');"));
    binary.query(new SqlFieldsQuery("INSERT INTO binary (id, str) VALUES (2, 'bar');"));

    GridTestUtils.assertThrowsAnyCause(
        log,
        new Callable<Object>() {
            @Override public Object call() {
                return ignite.cache("binary").iterator().next();
            }
        },
        BinaryInvalidTypeException.class,
        "IdKey");
}
 
Example 10
Source File: IgniteDbDynamicCacheSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testCreate() throws Exception {
    int iterations = 200;

    startGrids(3);

    Ignite ignite = ignite(0);

    ignite.active(true);

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setName("cache1");
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setAffinity(new RendezvousAffinityFunction(false, 32));

    if (MvccFeatureChecker.forcedMvcc())
        ccfg.setRebalanceDelay(Long.MAX_VALUE);
    else
        ccfg.setRebalanceMode(CacheRebalanceMode.NONE);

    for (int k = 0; k < iterations; k++) {
        System.out.println("Iteration: " + k);

        IgniteCache cache = ignite.createCache(ccfg);

        awaitPartitionMapExchange();

        ignite.destroyCache(ccfg.getName());

        awaitPartitionMapExchange();
    }
}
 
Example 11
Source File: IgnitePdsNodeJoinWithCachesStopping.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Test
public void test() throws Exception {
    final Ignite ig = startGridsMultiThreaded(2);

    for (int i = 0; i < 100; i++)
        ig.createCache(new CacheConfiguration<>("test0" + i).setBackups(0));

    IgniteInternalFuture<Boolean> gridStartFut = GridTestUtils.runAsync(() ->
    {
        try {
            startGrid(2);
        }
        catch (Exception e) {
            return false;
        }

        return true;
    }, "new-server-start-thread");

    for (int k = 0; k < 5; k++) {
        final int l = k;
        GridTestUtils.runAsync(() -> {
            for (int m = l * 20; m < (l + 1) * 20; m++)
                ig.destroyCache("test0" + m);

        }, "cache-destroy-thread");
    }

    assertTrue(gridStartFut.get());
}
 
Example 12
Source File: GridCommandHandlerTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Launches cluster deactivation. Works via control.sh when a non-persistent cache involved.
 *
 *  @param cmd Certain command to deactivate cluster.
 */
private void checkDeactivateNonPersistent(String... cmd) throws Exception {
    dataRegionConfiguration = new DataRegionConfiguration()
        .setName("non-persistent-dataRegion")
        .setPersistenceEnabled(false);

    Ignite ignite = startGrids(1);

    ignite.cluster().state(ACTIVE);

    assertTrue(ignite.cluster().active());
    assertEquals(ACTIVE, ignite.cluster().state());

    ignite.createCache(new CacheConfiguration<>("non-persistent-cache")
        .setDataRegionName("non-persistent-dataRegion"));

    injectTestSystemOut();

    assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute(cmd));

    assertTrue(ignite.cluster().active());
    assertEquals(ACTIVE, ignite.cluster().state());
    assertContains(log, testOut.toString(), GridClusterStateProcessor.DATA_LOST_ON_DEACTIVATION_WARNING);

    List<String> forceCmd = new ArrayList<>(Arrays.asList(cmd));
    forceCmd.add("--force");

    assertEquals(EXIT_CODE_OK, execute(forceCmd));

    assertFalse(ignite.cluster().active());
    assertEquals(INACTIVE, ignite.cluster().state());
}
 
Example 13
Source File: BasicJavaTypesIndexTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Executes test scenario: <ul>
 * <li>Create cache</li>
 * <li>Populate cache with random data</li>
 * <li>Verify range query on created table</li>
 * <li>Verify that table stores the same data as the generated dataset</li>
 * <li>Destroy cache</li>
 * </ul>
 *
 * @param idxCls Index type class.
 * @param comp Comparator to sort data set to perform range check.
 * If {@code null} range check will not be performed.
 * @param keyCls Key type class. Will be used to generate KEY object
 * for cache operations. If {@code null} idxCls will be used.
 * @param <Key> Type of the key in terms of the cache.
 * @param <Idx> Type of the indexed field.
 */
private <Key extends ClassWrapper, Idx> void createPopulateAndVerify(Class<Idx> idxCls,
    @Nullable Comparator<Idx> comp, @Nullable Class<Key> keyCls) {
    Ignite ign = grid(0);

    String tblName = idxCls.getSimpleName().toUpperCase() + "_TBL" + TBL_ID.incrementAndGet();

    try {
        // Create cache
        LinkedHashMap<String, String> fields = new LinkedHashMap<>(2);

        fields.put("idxVal", idxCls.getName());
        fields.put("val", Integer.class.getName());

        QueryEntity qe = new QueryEntity(keyCls == null ? idxCls.getName() : keyCls.getName(), Integer.class.getName())
            .setTableName(tblName)
            .setValueFieldName("val")
            .setFields(fields);

        String idxName;
        String idxFieldName;

        if (keyCls == null) {
            qe.setKeyFieldName("idxVal");

            idxName = PK_IDX_NAME;
            idxFieldName = KEY_FIELD_NAME;
        }
        else {
            idxFieldName = "idxVal";

            qe.setKeyFields(Collections.singleton(idxFieldName));

            if (keyCls.equals(TestKeyWithAff.class))
                idxName = AFFINITY_KEY_IDX_NAME;
            else {
                idxName = "IDXVAL_IDX";

                qe.setIndexes(Collections.singleton(new QueryIndex(idxFieldName, true, idxName)));
            }
        }

        IgniteCache<Object, Integer> cache = ign.createCache(
            new CacheConfiguration<Object, Integer>(tblName + "_CACHE")
                .setKeyConfiguration(new CacheKeyConfiguration((keyCls != null ? keyCls : idxCls).getName(), "idxVal"))
                .setQueryEntities(Collections.singletonList(qe)).setSqlSchema("PUBLIC"));

        // Then populate it with random data
        Map<Idx, Integer> data = new TreeMap<>(comp);

        if (keyCls == null)
            populateTable(data, cache, idxCls);
        else
            populateTable(data, cache, keyCls, idxCls);

        // Perform necessary verifications
        if (comp != null)
            verifyRange(data, tblName, idxFieldName, idxName, comp);

        verifyEach(data, tblName, idxFieldName, idxName);
    }
    finally {
        // Destroy cache
        ign.destroyCache(tblName + "_CACHE");
    }
}
 
Example 14
Source File: GridCacheContinuousQueryMultiNodesFilteringTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** */
private Ignite startGrid(final int idx, boolean isClientMode) throws Exception {
    String igniteInstanceName = getTestIgniteInstanceName(idx);

    IgniteConfiguration cfg = optimize(getConfiguration(igniteInstanceName)).setClientMode(isClientMode);

    cfg.setUserAttributes(Collections.singletonMap("idx", idx));

    Ignite node = startGrid(igniteInstanceName, cfg);

    IgnitePredicate<ClusterNode> nodeFilter = new NodeFilter(idx);

    String partCacheName = "part" + idx;

    IgniteCache partCache = node.createCache(defaultCacheConfiguration().setName("part" + idx)
        .setCacheMode(PARTITIONED).setBackups(1).setNodeFilter(nodeFilter));

    opCounts.put(partCacheName + "_ins", new AtomicInteger());
    opCounts.put(partCacheName + "_upd", new AtomicInteger());
    opCounts.put(partCacheName + "_rmv", new AtomicInteger());

    partCache.registerCacheEntryListener(new ListenerConfiguration(partCacheName, ListenerConfiguration.Op.INSERT));
    partCache.registerCacheEntryListener(new ListenerConfiguration(partCacheName, ListenerConfiguration.Op.UPDATE));
    partCache.registerCacheEntryListener(new ListenerConfiguration(partCacheName, ListenerConfiguration.Op.REMOVE));

    String replCacheName = "repl" + idx;

    IgniteCache replCache = node.createCache(defaultCacheConfiguration().setName("repl" + idx)
        .setCacheMode(REPLICATED).setNodeFilter(nodeFilter));

    opCounts.put(replCacheName + "_ins", new AtomicInteger());
    opCounts.put(replCacheName + "_upd", new AtomicInteger());
    opCounts.put(replCacheName + "_rmv", new AtomicInteger());

    replCache.registerCacheEntryListener(new ListenerConfiguration(replCacheName, ListenerConfiguration.Op.INSERT));
    replCache.registerCacheEntryListener(new ListenerConfiguration(replCacheName, ListenerConfiguration.Op.UPDATE));
    replCache.registerCacheEntryListener(new ListenerConfiguration(replCacheName, ListenerConfiguration.Op.REMOVE));

    opCounts.put("qry" + idx + "_total", new AtomicInteger());

    ContinuousQuery qry = new ContinuousQuery();
    qry.setRemoteFilterFactory(new EntryEventFilterFactory(idx));
    qry.setLocalListener(new CacheEntryUpdatedListener() {
        /** {@inheritDoc} */
        @Override public void onUpdated(Iterable evts) {
            opCounts.get("qry" + idx + "_total").incrementAndGet();
        }
    });

    partCache.query(qry);
    replCache.query(qry);

    return node;
}
 
Example 15
Source File: IgniteCacheAtomicProtocolTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testPutAllNearNodeFailure() throws Exception {
    final int SRVS = 4;

    startGrids(SRVS);

    Ignite clientNode = startClientGrid(SRVS);

    final IgniteCache<Integer, Integer> nearCache = clientNode.createCache(cacheConfiguration(1, FULL_SYNC));

    awaitPartitionMapExchange();

    for (int i = 0; i < SRVS; i++)
        testSpi(grid(i)).blockMessages(GridDhtAtomicNearResponse.class, clientNode.name());

    final Map<Integer, Integer> map = new HashMap<>();

    for (int i = 0; i < 100; i++)
        map.put(i, i);

    nearCache.putAllAsync(map);

    boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {
        @Override public boolean apply() {
            IgniteCache cache = ignite(0).cache(TEST_CACHE);

            for (Integer key : map.keySet()) {
                if (cache.get(key) == null)
                    return false;
            }

            return true;
        }
    }, 5000);

    assertTrue(wait);

    stopGrid(SRVS);

    GridTestUtils.waitForCondition(new GridAbsPredicate() {
        @Override public boolean apply() {
            for (int i = 0; i < SRVS; i++) {
                if (grid(i).context().cache().context().mvcc().atomicFuturesCount() != 0)
                    return false;
            }

            return true;
        }
    }, 5000);

    for (int i = 0; i < SRVS; i++)
        assertEquals(0, grid(i).context().cache().context().mvcc().atomicFuturesCount());

    checkData(map);
}
 
Example 16
Source File: IgniteDynamicCacheStartSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testNearNodesCache() throws Exception {
    try {
        testAttribute = false;

        Ignite ig = startGrid(nodeCount());

        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

        ccfg.setName(DYNAMIC_CACHE_NAME);
        ccfg.setCacheMode(CacheMode.PARTITIONED);
        ccfg.setNodeFilter(NODE_FILTER);

        IgniteCache cache = ig.createCache(ccfg, new NearCacheConfiguration());
        assertNotNull(cache);

        GridCacheAdapter<Object, Object> cacheAdapter =
            ((IgniteKernal)ig).internalCache(DYNAMIC_CACHE_NAME);

        assertNotNull(cacheAdapter);
        assertFalse(cacheAdapter.context().affinityNode());
        assertTrue(cacheAdapter.context().isNear());

        try {
            IgniteEx grid = startGrid(nodeCount() + 1);

            // Check that new node sees near node.
            GridDiscoveryManager disco = grid.context().discovery();

            assertTrue(disco.cacheNearNode(disco.node(ig.cluster().localNode().id()),
                DYNAMIC_CACHE_NAME));
        }
        finally {
            cache.destroy();

            stopGrid(nodeCount() + 1);
        }
    }
    finally {
        stopGrid(nodeCount());
    }
}
 
Example 17
Source File: CacheSerializableTransactionsTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testNearCacheReaderUpdate() throws Exception {
    Ignite ignite0 = ignite(0);

    IgniteCache<Integer, Integer> cache0 =
        ignite0.createCache(cacheConfiguration(PARTITIONED, FULL_SYNC, 1, false, false));

    final String cacheName = cache0.getName();

    try {
        Ignite client1 = ignite(SRVS);
        Ignite client2 = ignite(SRVS + 1);

        IgniteCache<Integer, Integer> cache1 = client1.createNearCache(cacheName,
            new NearCacheConfiguration<Integer, Integer>());
        IgniteCache<Integer, Integer> cache2 = client2.createNearCache(cacheName,
            new NearCacheConfiguration<Integer, Integer>());

        Integer key = primaryKey(ignite(0).cache(cacheName));

        try (Transaction tx = client1.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
            assertNull(cache1.get(key));
            cache1.put(key, 1);

            tx.commit();
        }

        try (Transaction tx = client2.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
            assertEquals(1, (Object)cache2.get(key));
            cache2.put(key, 2);

            tx.commit();
        }

        try (Transaction tx = client1.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
            assertEquals(2, (Object)cache1.get(key));
            cache1.put(key, 3);

            tx.commit();
        }
    }
    finally {
        destroyCache(cacheName);
    }
}
 
Example 18
Source File: IgniteCacheBinaryEntryProcessorSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param cacheMode Cache mode to test.
 * @param atomicityMode Atomicity mode to test.
 * @throws Exception
 */
private void checkInvokeBinaryObject(CacheMode cacheMode, CacheAtomicityMode atomicityMode) throws Exception {
    Ignite client = ignite(SRV_CNT);

    IgniteCache<Integer, TestValue> clientCache = client.createCache(cacheConfiguration(cacheMode, atomicityMode));

    try {
        IgniteBinary binary = client.binary();

        for (int i = 0; i < 100; i++) {
            clientCache.put(i, new TestValue(i, "value-" + i));

            BinaryObjectBuilder bldr = binary.builder("NoClass");

            bldr.setField("val", i);
            bldr.setField("strVal", "value-" + i);

            clientCache.withKeepBinary().put(-(i + 1), bldr.build());
        }

        IgniteCache<Integer, BinaryObject> binaryClientCache = clientCache.withKeepBinary();

        for (int i = 0; i < 100; i++) {
            binaryClientCache.invoke(i, new TestEntryProcessor());
            binaryClientCache.invoke(-(i + 1), new TestEntryProcessor());
        }

        for (int g = 0; g < NODES; g++) {
            IgniteCache<Integer, TestValue> nodeCache = ignite(g).cache(DEFAULT_CACHE_NAME);
            IgniteCache<Integer, BinaryObject> nodeBinaryCache = nodeCache.withKeepBinary();

            for (int i = 0; i < 100; i++) {
                TestValue updated = nodeCache.get(i);

                assertEquals((Integer)(i + 1), updated.value());
                assertEquals("updated-" + i, updated.stringValue());

                BinaryObject updatedBinary = nodeBinaryCache.get(i);
                assertEquals(new Integer(i + 1), updatedBinary.field("val"));
                assertEquals("updated-" + i, updatedBinary.field("strVal"));

                updatedBinary = nodeBinaryCache.get(-(i + 1));
                assertEquals(new Integer(i + 1), updatedBinary.field("val"));
                assertEquals("updated-" + i, updatedBinary.field("strVal"));
            }
        }
    }
    finally {
        client.destroyCache(DEFAULT_CACHE_NAME);
    }
}
 
Example 19
Source File: IgniteCacheGroupsTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testCloseCache1() throws Exception {
    startGrid(0);

    Ignite client = startClientGrid(1);

    IgniteCache c1 = client.createCache(cacheConfiguration(GROUP1, "c1", PARTITIONED, ATOMIC, 0, false));

    checkCacheGroup(0, GROUP1, true);
    checkCacheGroup(0, GROUP1, true);

    checkCache(0, "c1", 10);
    checkCache(1, "c1", 10);

    c1.close();

    checkCacheGroup(0, GROUP1, true);
    checkCacheGroup(1, GROUP1, false);

    checkCache(0, "c1", 10);

    assertNotNull(client.cache("c1"));

    checkCacheGroup(0, GROUP1, true);
    checkCacheGroup(1, GROUP1, true);

    checkCache(0, "c1", 10);
    checkCache(1, "c1", 10);
}
 
Example 20
Source File: CacheMvccVacuumTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testStartStopVacuumPersistence() throws Exception {
    persistence = true;

    Ignite node0 = startGrid(0);
    Ignite node1 = startGrid(1);

    ensureNoVacuum(node0);
    ensureNoVacuum(node1);

    node1.cluster().active(true);

    ensureNoVacuum(node0);
    ensureNoVacuum(node1);

    node1.createCache(new CacheConfiguration<>("test1")
        .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));

    ensureNoVacuum(node0);
    ensureNoVacuum(node1);

    IgniteCache<Object, Object> cache = node1.createCache(new CacheConfiguration<>("test2")
        .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT));

    cache.put(primaryKey(cache), 0);
    cache.put(primaryKey(node0.cache("test2")), 0);

    ensureVacuum(node0);
    ensureVacuum(node1);

    node1.cluster().active(false);

    ensureNoVacuum(node0);
    ensureNoVacuum(node1);

    node1.cluster().active(true);

    ensureVacuum(node0);
    ensureVacuum(node1);

    stopGrid(0);

    ensureNoVacuum(node0);
    ensureVacuum(node1);

    stopGrid(1);

    ensureNoVacuum(node0);
    ensureNoVacuum(node1);

    node0 = startGrid(0);
    node1 = startGrid(1);

    node1.cluster().active(true);

    ensureVacuum(node0);
    ensureVacuum(node1);
}