Java Code Examples for org.apache.ignite.internal.IgniteEx#cache()

The following examples show how to use org.apache.ignite.internal.IgniteEx#cache() . 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: CacheMvccProcessorLazyStartTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testPreconfiguredCacheMvccNotStarted() throws Exception {
    CacheConfiguration ccfg = cacheConfiguration(CacheMode.PARTITIONED, CacheWriteSynchronizationMode.FULL_SYNC, 0, 1);
    ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);

    IgniteConfiguration cfg = getConfiguration();
    cfg.setCacheConfiguration(ccfg);
    IgniteConfiguration cfg2 = getConfiguration("node2");

    IgniteEx node1 = startGrid(cfg);
    IgniteEx node2 = startGrid(cfg2);

    IgniteCache cache = node1.cache(ccfg.getName());

    cache.put(1, 1);
    cache.put(1, 2);

    assertFalse(mvccEnabled(node1));
    assertFalse(mvccEnabled(node2));
}
 
Example 2
Source File: IgniteSqlKeyValueFieldsTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** Check that joins are working on keyFieldName, valueFieldName columns */
@Test
public void testJoinKeyValFields() throws Exception {
    IgniteEx client = grid(NODE_CLIENT);
    IgniteCache<Integer, Person> cache = client.cache(CACHE_PERSON);
    IgniteCache<Integer, Integer> cache2 = client.cache(CACHE_JOB);

    checkInsert(cache, "insert into Person (id, v) values (?, ?)", 1, new Person("Bob", 30));
    checkInsert(cache, "insert into Person (id, v) values (?, ?)", 2, new Person("David", 35));
    checkInsert(cache2, "insert into Integer (_key, _val) values (?, ?)", 100, 1);
    checkInsert(cache2, "insert into Integer (_key, _val) values (?, ?)", 200, 2);

    QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("select p.id, j._key from Person p, \"" + CACHE_JOB + "\".Integer j where p.id = j._val"));
    List<List<?>> results = cursor.getAll();
    assertEquals(2, results.size());
    assertEquals(1, results.get(0).get(0));
    assertEquals(100, results.get(0).get(1));
    assertEquals(2, results.get(1).get(0));
    assertEquals(200, results.get(1).get(1));
}
 
Example 3
Source File: IgniteSqlKeyValueFieldsTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** Check automatic addition of index for keyFieldName column */
@Test
public void testAutoKeyFieldIndex() throws Exception {
    IgniteEx client = grid(NODE_CLIENT);
    IgniteCache<Integer, Person> cache = client.cache(CACHE_PERSON);

    QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("explain select * from Person where id = 1"));
    List<List<?>> results = cursor.getAll();
    assertEquals(1, results.size());
    assertTrue(((String)results.get(0).get(0)).contains("\"_key_PK_proxy\""));

    cursor = cache.query(new SqlFieldsQuery("explain select * from Person where _key = 1"));
    results = cursor.getAll();
    assertEquals(1, results.size());
    assertTrue(((String)results.get(0).get(0)).contains("\"_key_PK\""));
}
 
Example 4
Source File: IgniteDbSingleNodeTinyPutGetTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
@Test
public void testPutGetTiny() {
    IgniteEx ig = grid(0);

    IgniteCache<Short, Byte> cache = ig.cache("tiny");

    for (short i = 0; i < 1000; i++)
        cache.put(i, (byte) i);

    for (short i = 0; i < 1000; i++)
        assertEquals((byte) i, cache.get(i).byteValue());
}
 
Example 5
Source File: TxLocalDhtMixedCacheModesTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@Test
public void testTxLocalDhtMixedCacheModes() throws Exception {
    try {
        IgniteEx g0 = startGrid(0);

        IgniteCache cache1 = g0.cache(DEFAULT_CACHE_NAME);
        IgniteCache cache2 = g0.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME + 1).
            setAtomicityMode(TRANSACTIONAL));

        cache1.put(1, 1);
        cache2.put(1, 2);

        // Commit.
        try (Transaction tx = g0.transactions().txStart()) {
            cache1.put(1, 10);
            cache2.put(1, 20);

            tx.commit();
        }

        assertEquals(10, cache1.get(1));
        assertEquals(20, cache2.get(1));

        // Rollback.
        try (Transaction tx = g0.transactions().txStart()) {
            cache1.put(1, 100);
            cache2.put(1, 200);
        }

        assertEquals(10, cache1.get(1));
        assertEquals(20, cache2.get(1));
    }
    finally {
        stopAllGrids();
    }
}
 
Example 6
Source File: IgniteBaselineAffinityTopologyActivationTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
private void checkDataInCache(IgniteEx srv) {
    IgniteCache<Object, Object> cache = srv.cache(DEFAULT_CACHE_NAME);

    for (int i = 0; i < ENTRIES_COUNT; i++) {
        TestValue testVal = (TestValue) cache.get(i);

        assertNotNull(testVal);

        assertEquals(i, testVal.id);
    }
}
 
Example 7
Source File: DmlInsideTransactionTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Run DML query and check that DML is not allowed or not inside transaction. Also checked that using DML will not
 * lead to rollback.
 *
 * @param query Query with DML operation to be run.
 * @param isAllowed true in case DML should work inside transaction, false otherwise.
 */
private void runDmlInTransactionTest(Query query, boolean isAllowed) {
    IgniteEx ignite = grid(0);

    IgniteCache<PersonKey, Person> cache = ignite.cache(CACHE_PERSON);

    cache.removeAll();

    assertEquals(0, cache.query(new SqlFieldsQuery("SELECT * FROM TEST.Person")).getAll().size());

    try (Transaction tx = ignite.transactions().txStart()) {
        cache.put(new PersonKey(1L), new Person("person", 2));

        if (isAllowed)
            cache.query(query);
        else {
            assertThrows(log, () -> {
                cache.query(query);

                return null;
            }, CacheException.class, "DML statements are not allowed inside a transaction over cache(s) with TRANSACTIONAL atomicity");
        }

        tx.commit();
    }

    assertTrue(!cache.query(new SqlFieldsQuery("SELECT * FROM TEST.Person")).getAll().isEmpty());
}
 
Example 8
Source File: IgnitePdsBinaryMetadataAsyncWritingTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @throws Exception If failed.
 */
@Test
public void testNodeIsStoppedOnExceptionDuringStoringMetadata() throws Exception {
    IgniteEx ig0 = startGrid(0);

    specialFileIOFactory = new FailingFileIOFactory(new RandomAccessFileIOFactory());

    setRootLoggerDebugLevel();

    IgniteEx ig1 = startGrid(1);

    ig0.cluster().active(true);

    int ig1Key = findAffinityKeyForNode(ig0.affinity(DEFAULT_CACHE_NAME), ig1.localNode());

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

    cache.put(ig1Key, new TestAddress(0, "USA", "NYC", "6th Ave"));

    waitForTopology(1);
}
 
Example 9
Source File: IgniteCrossCacheTxStoreSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testNonPersistentCache() throws Exception {
    IgniteEx grid = grid(0);

    TestStore firstStore = (TestStore)firstStores.get(grid.name());
    TestStore secondStore = (TestStore)secondStores.get(grid.name());

    assertNotNull(firstStore);
    assertNotNull(secondStore);

    Collection<String> firstStoreEvts = firstStore.events();
    Collection<String> secondStoreEvts = secondStore.events();

    try (Transaction tx = grid.transactions().txStart()) {
        IgniteCache<Object, Object> cacheA = grid.cache("cacheA");
        IgniteCache<Object, Object> cacheD = grid.cache("cacheD");

        cacheA.put("1", "1");
        cacheA.put("2", "2");
        cacheD.put("1", "1");
        cacheD.put("2", "2");

        cacheA.remove("3");
        cacheA.remove("4");
        cacheD.remove("3");
        cacheD.remove("4");

        cacheA.put("5", "5");
        cacheA.remove("6");

        cacheD.put("7", "7");

        tx.commit();
    }

    assertEqualsCollections(F.asList(
        "writeAll cacheA 2",
        "deleteAll cacheA 2",
        "write cacheA",
        "delete cacheA",
        "sessionEnd true"
        ),
        firstStoreEvts);

    assertEquals(0, secondStoreEvts.size());
}
 
Example 10
Source File: CacheGroupMetricsTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies metric for initialized local partitions.
 * It is incremented when partition is actually created on node and decremented when it is destroyed.
 *
 * @throws Exception If failed.
 */
@Test
public void testInitializedLocalPartitions() throws Exception {
    pds = true;

    cleanPersistenceDir();

    IgniteEx ignite = startGrid(0);

    ignite.cluster().active(true);

    MetricRegistry group1Metrics = cacheGroupMetrics(0, "group1").get2();

    AtomicLongMetric locPartsNum = group1Metrics.findMetric("InitializedLocalPartitionsNumber");

    assertEquals(0, locPartsNum.value());

    IgniteCache cache = ignite.cache("cache1");

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

    assertEquals(10, locPartsNum.value());
}
 
Example 11
Source File: IgniteAbstractWalIteratorInvalidCrcTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
    cleanPersistenceDir();

    ignite = (IgniteEx)startGrid();

    ignite.cluster().active(true);

    IgniteCache<Integer, byte[]> cache = ignite.cache(DEFAULT_CACHE_NAME);

    byte[] val = new byte[VALUE_SIZE];

    // Fill value with random data.
    random.nextBytes(val);

    // Amount of values that's enough to fill working dir at least twice.
    int insertingCnt = 2 * WAL_SEGMENT_SIZE * WAL_SEGMENTS / VALUE_SIZE;
    for (int i = 0; i < insertingCnt; i++)
        cache.put(i, val);

    ignite.cluster().active(false);
}
 
Example 12
Source File: IgniteStandByClusterTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception if fail.
 */
@Test
public void testSimple() throws Exception {
    IgniteEx ig = startGrid(0);

    ig.active(true);

    IgniteCache<Integer, String> cache0 = ig.getOrCreateCache("cache");

    cache0.put(1, "1");

    assertEquals("1", cache0.get(1));

    ig.active(false);

    assertTrue(!ig.active());

    ig.active(true);

    IgniteCache<Integer, String> cache = ig.cache("cache");

    assertEquals("1", cache.get(1));
}
 
Example 13
Source File: GridSpringCacheManagerMultiJvmSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testSyncCache() throws Exception {
    IgniteEx loc = startGrid(0);

    final int threads = 4;
    final int entries = 1000;
    final int remoteNum = 2;

    final CountDownLatch latch = new CountDownLatch(1);

    List<IgniteInternalFuture<Integer>> futures = new ArrayList<>(remoteNum);

    for (int i = 0; i < remoteNum; i++) {
        final int gridIdx = i + 1;

        final IgniteEx remote = startGrid(gridIdx);

        IgniteInternalFuture<Integer> calledCntFut = GridTestUtils.runAsync(new Callable<Integer>() {
            @Override public Integer call() throws Exception {
                latch.await();

                return executeRemotely((IgniteProcessProxy)remote, new TestIgniteCallable<Integer>() {
                    @Override public Integer call(Ignite ignite) throws Exception {
                        BeanFactory factory =
                            new ClassPathXmlApplicationContext(
                                "org/apache/ignite/cache/spring/spring-caching" + gridIdx + ".xml");

                        final GridSpringDynamicCacheTestService dynamicSvc =
                            (GridSpringDynamicCacheTestService)factory.getBean("dynamicTestService");

                        final CyclicBarrier barrier = new CyclicBarrier(threads);

                        GridTestUtils.runMultiThreaded(
                            new Callable() {
                                @Override public Object call() throws Exception {
                                    for (int i = 0; i < entries; i++) {
                                        barrier.await();

                                        assertEquals("value" + i, dynamicSvc.cacheableSync(i));
                                        assertEquals("value" + i, dynamicSvc.cacheableSync(i));
                                    }

                                    return null;
                                }
                            },
                            threads,
                            "get-sync");

                        return dynamicSvc.called();
                    }
                });

            }
        });

        futures.add(calledCntFut);
    }

    latch.countDown();

    int totalCalledCnt = 0;

    for (IgniteInternalFuture<Integer> future : futures)
        totalCalledCnt += future.get();

    IgniteCache<Object, Object> cache = loc.cache("dynamicCache");

    assertEquals(entries, cache.size());
    assertEquals(entries, totalCalledCnt);

    for (int i = 0; i < entries; i++)
        assertEquals("value" + i, cache.get(i));
}
 
Example 14
Source File: IgniteCacheGroupsWithRestartsTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testNodeRestartWith3rdPartyCacheStoreAndPersistenceEnabled() throws Exception {
    IgniteEx crd = startGrid(0);

    crd.cluster().state(ACTIVE);

    String cacheName = "test-cache-3rd-party-write-behind-and-ignite-persistence";
    CacheConfiguration ccfg = new CacheConfiguration(cacheName)
        .setWriteBehindEnabled(true)
        .setWriteThrough(true)
        .setReadThrough(true)
        .setCacheStoreFactory(new StoreFactory());

    IgniteCache cache = crd.getOrCreateCache(ccfg);

    cache.put(12, 42);

    stopGrid(0);

    crd = startGrid(0);

    crd.cluster().state(ACTIVE);

    cache = crd.cache(cacheName);

    assertEquals("Cache was not properly restored or required key is lost.", 42, cache.get(12));
}
 
Example 15
Source File: GridCacheRebalancingPartitionCountersTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Tests that after rebalancing all partition update counters have the same value on all nodes.
 */
@Test
public void test() throws Exception {
    IgniteEx ignite = (IgniteEx)startGrids(3);

    ignite.cluster().active(true);

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

    for (int i = 0; i < 256; i++)
        cache.put(i, i);

    final int problemNode = 2;

    IgniteEx node = (IgniteEx) ignite(problemNode);
    int[] primaryPartitions = node.affinity(CACHE_NAME).primaryPartitions(node.cluster().localNode());

    ignite.cluster().active(false);

    boolean primaryRemoved = false;
    for (int i = 0; i < PARTITIONS_CNT; i++) {
        String nodeName = getTestIgniteInstanceName(problemNode);

        Path dirPath = Paths.get(U.defaultWorkDirectory(), "db", nodeName.replace(".", "_"), CACHE_NAME + "-" + CACHE_NAME);

        info("Path: " + dirPath.toString());

        assertTrue(Files.exists(dirPath));

        for (File f : dirPath.toFile().listFiles()) {
            if (f.getName().equals("part-" + i + ".bin")) {
                if (contains(primaryPartitions, i)) {
                    info("Removing: " + f.getName());

                    primaryRemoved = true;

                    f.delete();
                }
            }
            else if ("index.bin".equals(f.getName())) {
                info("Removing: " + f.getName());

                f.delete();
            }
        }
    }

    assertTrue(primaryRemoved);

    ignite.cluster().active(true);

    awaitPartitionMapExchange();

    List<String> issues = new ArrayList<>();
    HashMap<Integer, Long> partMap = new HashMap<>();

    for (int i = 0; i < 3; i++)
        checkUpdCounter((IgniteEx)ignite(i), issues, partMap);

    for (String issue : issues)
        error(issue);

    assertTrue(issues.isEmpty());
}
 
Example 16
Source File: BasicIndexTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/** */
private void runEqualFieldsDynamicIndexes(boolean persistEnabled) throws Exception {
    isPersistenceEnabled = persistEnabled;

    indexes = Collections.singletonList(new QueryIndex("valStr"));

    inlineSize = 10;

    srvLog = new ListeningTestLogger(false, log);

    clientLog = new ListeningTestLogger(false, log);

    String msg1 = "Index with the given set or subset of columns already exists";

    LogListener lsnr = LogListener.matches(msg1).andMatches(Pattern.compile(".*newIndexName=idx[0-9]")).build();

    LogListener staticCachesLsnr = LogListener.matches(msg1).build();

    srvLog.registerListener(staticCachesLsnr);

    IgniteEx ig0 = startGrid(0);

    if (persistEnabled)
        ig0.cluster().active(true);

    IgniteCache<Key, Val> cache = grid(0).cache(DEFAULT_CACHE_NAME);

    populateCache();

    cache.query(new SqlFieldsQuery("create index \"idx0\" on Val(valStr)"));

    assertTrue(staticCachesLsnr.check());

    srvLog.unregisterListener(staticCachesLsnr);

    srvLog.registerListener(lsnr);

    cache.query(new SqlFieldsQuery("create index \"idx1\" on Val(valStr, valLong)"));

    cache.query(new SqlFieldsQuery("create index \"idx2\" on Val(valStr desc, valLong)"));

    assertFalse(lsnr.check());

    cache.query(new SqlFieldsQuery("create index \"idx3\" on Val(valStr, valLong)"));

    cache.query(new SqlFieldsQuery("create index \"idx4\" on Val(valLong)"));

    assertTrue(lsnr.check());

    srvLog.unregisterListener(lsnr);

    IgniteEx client = startClientGrid(CLIENT_NAME);

    cache = client.cache(DEFAULT_CACHE_NAME);

    LogListener lsnrIdx5 = LogListener.matches(msg1).andMatches("idx5").build();

    srvLog.registerListener(lsnrIdx5);

    cache.query(new SqlFieldsQuery("create index \"idx5\" on Val(valStr desc, valLong)"));

    assertTrue(lsnrIdx5.check());

    LogListener lsnrIdx7 = LogListener.matches(msg1).andMatches("idx7").build();

    srvLog.registerListener(lsnrIdx7);

    cache.query(new SqlFieldsQuery("create index \"idx6\" on Val(valLong)"));

    cache.query(new SqlFieldsQuery("create index \"idx7\" on Val(keyStr, keyLong, keyPojo, valLong)"));

    assertFalse(lsnrIdx7.check());
}
 
Example 17
Source File: CacheMvccTxFailoverTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @param rollBack If {@code True} then Tx will be rolled backup, committed otherwise.
 * @param recoverFromWAL If {@code True} then Tx recovery from WAL will be checked,
 *                       binary recovery from latest checkpoint otherwise.
 * @param omitTxFinish If {@code True} then unfinished Tx state will be restored as if node fails during commit.
 * @throws Exception If fails.
 */
public void checkSingleNodeRestart(boolean rollBack, boolean recoverFromWAL, boolean omitTxFinish) throws Exception {
    IgniteEx node = startGrid(0);

    node.cluster().active(true);

    IgniteCache<Integer, Integer> cache = node.getOrCreateCache(DEFAULT_CACHE_NAME);

    cache.put(1, 1);
    cache.put(2, 1);

    IgniteTransactions txs = node.transactions();

    IgniteWriteAheadLogManager wal = node.context().cache().context().wal();

    if (recoverFromWAL) {
        //Force checkpoint. See for details: https://issues.apache.org/jira/browse/IGNITE-10187
        node.context().cache().context().database().waitForCheckpoint(null);

        ((GridCacheDatabaseSharedManager)node.context().cache().context().database()).enableCheckpoints(false).get();
    }

    GridTimeoutProcessor.CancelableTask flushTask = GridTestUtils.getFieldValue(wal, FileWriteAheadLogManager.class, "backgroundFlushSchedule");
    WalStateManager.WALDisableContext wctx = GridTestUtils.getFieldValue(wal, FileWriteAheadLogManager.class, "walDisableContext");

    // Disable checkpoint and WAL flusher.
    node.context().timeout().removeTimeoutObject(flushTask);

    try (Transaction tx = txs.txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.REPEATABLE_READ)) {
        assertEquals((Integer)1, cache.get(1));
        cache.put(2, 2);

        flushTask.onTimeout(); // Flush WAL.

        if (!recoverFromWAL) {
            //Force checkpoint, then disable.
            node.context().cache().context().database().waitForCheckpoint(null);

            ((GridCacheDatabaseSharedManager)node.context().cache().context().database()).enableCheckpoints(false).get();
        }

        if (omitTxFinish)
            GridTestUtils.setFieldValue(wctx, "disableWal", true); // Disable wal.

        if (rollBack)
            tx.rollback();
        else
            tx.commit();
    }

    stopGrid(0);

    node = startGrid(0);

    node.cluster().active(true);

    cache = node.cache(DEFAULT_CACHE_NAME);

    assertEquals((Integer)1, cache.get(1));

    if (omitTxFinish || rollBack)
        assertEquals((Integer) 1, cache.get(2)); // Commit\rollback marker were saved neither in WAL nor in checkpoint.
    else
        assertEquals((Integer) 2, cache.get(2));

    cache.put(2, 3);

    assertEquals((Integer)3, cache.get(2));
}
 
Example 18
Source File: SchemaExchangeSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Make sure that new metadata can be propagated after destroy.
 *
 * @throws Exception If failed.
 */
@Test
public void testDynamicRestarts() throws Exception {
    IgniteEx node1 = start(1, KeyClass.class, ValueClass.class);
    IgniteEx node2 = startNoCache(2);
    IgniteEx node3 = startClientNoCache(3);
    IgniteEx node4 = startClientNoCache(4);

    assertTypes(node1, ValueClass.class);
    assertTypes(node2, ValueClass.class);
    assertCacheStarted(CACHE_NAME, node1, node2);

    assertTypes(node3, ValueClass.class);
    assertCacheNotStarted(CACHE_NAME, node3);

    node3.cache(CACHE_NAME);
    assertCacheStarted(CACHE_NAME, node3);

    // Check restarts from the first node.
    destroySqlCache(node1);

    node1.getOrCreateCache(cacheConfiguration());

    assertTypes(node1);
    assertTypes(node2);
    assertTypes(node3);

    node1.destroyCache(CACHE_NAME);

    node1.getOrCreateCache(cacheConfiguration(KeyClass.class, ValueClass.class,
        KeyClass2.class, ValueClass2.class));

    assertTypes(node1, ValueClass.class, ValueClass2.class);
    assertTypes(node2, ValueClass.class, ValueClass2.class);
    assertTypes(node3, ValueClass.class, ValueClass2.class);

    assertCacheStarted(CACHE_NAME, node1, node2);

    assertCacheNotStarted(CACHE_NAME, node3);

    node3.cache(CACHE_NAME);
    assertCacheStarted(CACHE_NAME, node3);

    // Check restarts from the second node.
    node2.destroyCache(CACHE_NAME);

    node2.getOrCreateCache(cacheConfiguration());

    assertTypes(node1);
    assertTypes(node2);
    assertTypes(node3);

    node2.destroyCache(CACHE_NAME);

    node2.getOrCreateCache(cacheConfiguration(KeyClass.class, ValueClass.class,
        KeyClass2.class, ValueClass2.class));

    assertTypes(node1, ValueClass.class, ValueClass2.class);
    assertTypes(node2, ValueClass.class, ValueClass2.class);
    assertTypes(node3, ValueClass.class, ValueClass2.class);
    assertTypes(node4, ValueClass.class, ValueClass2.class);

    assertCacheStarted(CACHE_NAME, node1, node2);

    assertCacheNotStarted(CACHE_NAME, node3);

    node3.cache(CACHE_NAME);
    assertCacheStarted(CACHE_NAME, node3);

    assertCacheNotStarted(CACHE_NAME, node4);

    node4.cache(CACHE_NAME);
    assertCacheStarted(CACHE_NAME, node4);

    // Make sure that joining node observes correct state.
    assertTypes(start(5), ValueClass.class, ValueClass2.class);
    assertTypes(startNoCache(6), ValueClass.class, ValueClass2.class);

    assertTypes(startClient(7), ValueClass.class, ValueClass2.class);

    IgniteEx node8 = startClientNoCache(8);

    assertTypes(node8, ValueClass.class, ValueClass2.class);

    assertCacheNotStarted(CACHE_NAME, node8);

    node8.cache(CACHE_NAME);

    assertCacheStarted(CACHE_NAME, node8);
}
 
Example 19
Source File: BasicIndexTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/** */
@Test
@WithSystemProperty(key = IGNITE_THROTTLE_INLINE_SIZE_CALCULATION, value = "1")
public void testInlineSizeChange() throws Exception {
    isPersistenceEnabled = true;

    indexes = Collections.singletonList(new QueryIndex("valStr"));

    inlineSize = 33;

    srvLog = new ListeningTestLogger(false, log);

    String msg1 = "curSize=1";
    String msg2 = "curSize=2";
    String msg3 = "curSize=3";

    LogListener lstn1 = LogListener.matches(msg1).build();
    LogListener lstn2 = LogListener.matches(msg2).build();
    LogListener lstn3 = LogListener.matches(msg3).build();

    srvLog.registerListener(lstn1);
    srvLog.registerListener(lstn2);
    srvLog.registerListener(lstn3);

    IgniteEx ig0 = startGrid(0);

    ig0.cluster().active(true);

    populateCache();

    IgniteCache<Key, Val> cache = grid(0).cache(DEFAULT_CACHE_NAME);

    execSql(cache, "create index \"idx1\" on Val(valLong) INLINE_SIZE 1 PARALLEL 28");

    List<List<?>> res = execSql(cache, "explain select * from Val where valLong > ?", 10);

    log.info("exp: " + res.get(0).get(0));

    assertTrue(lstn1.check());

    execSql(cache, "drop index \"idx1\"");
    execSql(cache, "create index \"idx1\" on Val(valLong) INLINE_SIZE 2 PARALLEL 28");
    execSql(cache, "explain select * from Val where valLong > ?", 10);

    assertTrue(lstn2.check());

    execSql(cache, "drop index \"idx1\"");

    stopAllGrids();

    ig0 = startGrid(0);

    ig0.cluster().active(true);

    cache = ig0.cache(DEFAULT_CACHE_NAME);

    execSql(cache, "create index \"idx1\" on Val(valLong) INLINE_SIZE 3 PARALLEL 28");
    execSql(cache, "explain select * from Val where valLong > ?", 10);

    assertTrue(lstn3.check());

    stopAllGrids();

    cleanPersistenceDir();
}
 
Example 20
Source File: CacheMvccProcessorLazyStartTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testMvccRestartedWithDynamicCache() throws Exception {
    persistence = true;

    IgniteEx node1 = startGrid(1);
    IgniteEx node2 = startGrid(2);

    assertFalse(mvccEnabled(node1));
    assertFalse(mvccEnabled(node2));

    node1.cluster().active(true);

    assertFalse(mvccEnabled(node1));
    assertFalse(mvccEnabled(node2));

    CacheConfiguration ccfg = cacheConfiguration(CacheMode.PARTITIONED, CacheWriteSynchronizationMode.FULL_SYNC, 0, 1);

    IgniteCache cache = node1.createCache(ccfg);

    cache.put(1, 1);
    cache.put(1, 2);

    assertTrue(mvccEnabled(node1));
    assertTrue(mvccEnabled(node2));

    stopGrid(1);
    stopGrid(2);

    node1 = startGrid(1);
    node2 = startGrid(2);

    node1.cluster().active(true);

    assertTrue(mvccEnabled(node1));
    assertTrue(mvccEnabled(node2));

    cache = node1.cache(ccfg.getName());

    cache.put(1, 1);
    cache.put(1, 2);

    assertTrue(mvccEnabled(node1));
    assertTrue(mvccEnabled(node2));
}