Java Code Examples for org.apache.ignite.configuration.CacheConfiguration#setNodeFilter()

The following examples show how to use org.apache.ignite.configuration.CacheConfiguration#setNodeFilter() . 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: GridProjectionForCachesSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cacheName Cache name.
 * @return Cache configuration.
 */
private CacheConfiguration cacheConfiguration(
    @NotNull String cacheName,
    IgnitePredicate<ClusterNode> nodeFilter,
    boolean nearEnabled
) {
    CacheConfiguration cfg = defaultCacheConfiguration();

    cfg.setName(cacheName);
    cfg.setCacheMode(PARTITIONED);

    if (nearEnabled)
        cfg.setNearConfiguration(new NearCacheConfiguration());

    cfg.setNodeFilter(nodeFilter);

    cfg.setBackups(1);

    return cfg;
}
 
Example 2
Source File: AffinityClientNodeSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration ccfg1 = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg1.setBackups(1);
    ccfg1.setName(CACHE1);
    ccfg1.setAffinity(new RendezvousAffinityFunction());
    ccfg1.setNodeFilter(new TestNodesFilter());

    CacheConfiguration ccfg2 = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg2.setBackups(1);
    ccfg2.setName(CACHE2);
    ccfg2.setAffinity(new RendezvousAffinityFunction());

    CacheConfiguration ccfg4 = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg4.setCacheMode(REPLICATED);
    ccfg4.setName(CACHE4);
    ccfg4.setNodeFilter(new TestNodesFilter());

    CacheConfiguration ccfg5 = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg5.setBackups(1);
    ccfg5.setName(CACHE5);

    if (igniteInstanceName.equals(getTestIgniteInstanceName(NODE_CNT - 1)))
        cfg.setCacheConfiguration(ccfg5);
    else
        cfg.setCacheConfiguration(ccfg1, ccfg2, ccfg4);

    return cfg;
}
 
Example 3
Source File: GridCacheReplicatedPreloadSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param cacheCfg Configuration.
 */
private void loadExternalClassesToCfg(CacheConfiguration cacheCfg) {
    try {
        Object sf = getExternalClassLoader().
            loadClass("org.apache.ignite.tests.p2p.CacheDeploymentTestStoreFactory").newInstance();

        cacheCfg.setCacheStoreFactory((Factory)sf);

        Object sslf = getExternalClassLoader().
            loadClass("org.apache.ignite.tests.p2p.CacheDeploymentStoreSessionListenerFactory").newInstance();

        cacheCfg.setCacheStoreSessionListenerFactories((Factory)sslf);

        Object cpc = getExternalClassLoader().
            loadClass("org.apache.ignite.tests.p2p.CacheDeploymentCachePluginConfiguration").newInstance();

        cacheCfg.setPluginConfigurations((CachePluginConfiguration)cpc);

        Object akm = getExternalClassLoader().
            loadClass("org.apache.ignite.tests.p2p.CacheDeploymentAffinityKeyMapper").newInstance();

        cacheCfg.setAffinityMapper((AffinityKeyMapper)akm);

        Object pred = getExternalClassLoader().
            loadClass("org.apache.ignite.tests.p2p.CacheDeploymentAlwaysTruePredicate2").newInstance();

        cacheCfg.setNodeFilter((IgnitePredicate)pred);
    }
    catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Source File: AffinityClientNodeSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testClientNodeNotInAffinity() throws Exception {
    checkCache(CACHE1, 2);

    checkCache(CACHE2, 2);

    checkCache(CACHE4, 3);

    checkCache(CACHE5, 2);

    Ignite client = ignite(NODE_CNT - 1);

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setBackups(0);

    ccfg.setNodeFilter(new TestNodesFilter());

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

    try {
        checkCache(DEFAULT_CACHE_NAME, 1);
    }
    finally {
        cache.destroy();
    }

    cache = client.createCache(ccfg, new NearCacheConfiguration());

    try {
        checkCache(DEFAULT_CACHE_NAME, 1);
    }
    finally {
        cache.destroy();
    }
}
 
Example 5
Source File: WalModeChangeCommonAbstractSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Create cache configuration.
 *
 * @param name Name.
 * @param mode Mode.
 * @param atomicityMode Atomicity mode.
 * @return Cache configuration.
 */
protected CacheConfiguration cacheConfig(String name, CacheMode mode, CacheAtomicityMode atomicityMode) {
    CacheConfiguration ccfg = new CacheConfiguration();

    ccfg.setName(name);
    ccfg.setCacheMode(mode);
    ccfg.setAtomicityMode(atomicityMode);

    ccfg.setNodeFilter(FILTER);

    return ccfg;
}
 
Example 6
Source File: SchemaExchangeSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Get cache configuration.
 *
 * @param clss QUery classes.
 * @return Configuration.
 */
@SuppressWarnings("unchecked")
private static CacheConfiguration cacheConfiguration(Class... clss) {
    CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME).setIndexedTypes(clss);

    if (filterNodeName != null) {
        ccfg.setNodeFilter(new IgnitePredicate<ClusterNode>() {
            @Override public boolean apply(ClusterNode node) {
                return node.attribute("AFF_NODE") != null;
            }
        });
    }

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

        startGrid(nodeCount());

        final IgniteEx kernal = grid(0);

        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

        ccfg.setName(DYNAMIC_CACHE_NAME);

        ccfg.setNodeFilter(NODE_FILTER);

        kernal.createCache(ccfg);

        GridTestUtils.assertThrows(log, new Callable<Object>() {
            @Override public Object call() throws Exception {
                IgniteKernal ignite = (IgniteKernal)grid(nodeCount());

                return ignite.getCache(DYNAMIC_CACHE_NAME);
            }
        }, IllegalArgumentException.class, null);

        // Should obtain client cache on new node.
        IgniteCache<Object, Object> clientCache = ignite(nodeCount()).cache(DYNAMIC_CACHE_NAME);

        clientCache.put("1", "1");

        for (int g = 0; g < nodeCount() + 1; g++)
            assertEquals("1", ignite(g).cache(DYNAMIC_CACHE_NAME).get("1"));

        kernal.destroyCache(DYNAMIC_CACHE_NAME);
    }
    finally {
        stopGrid(nodeCount());
    }
}
 
Example 8
Source File: IgniteDynamicCacheStartNoExchangeTimeoutTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testOldestChanged2() throws Exception {
    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setNodeFilter(new TestFilterIncludeNode(ignite(2).cluster().localNode().consistentId()));

    assertNotNull(ignite(1).getOrCreateCache(ccfg));

    stopGrid(0);

    IgniteEx ingite1 = grid(1);

    assertNotNull(ingite1.getOrCreateCache(DEFAULT_CACHE_NAME));

    awaitPartitionMapExchange();

    checkCache(DEFAULT_CACHE_NAME);
}
 
Example 9
Source File: IgniteDynamicCacheStartNoExchangeTimeoutTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @param ccfg Cache configuration.
 * @throws Exception If failed.
 */
private void notAffinityNode1(final CacheConfiguration ccfg) throws Exception {
    log.info("Test with cache: " + ccfg.getName());

    IgniteEx ignite = grid(1);

    ccfg.setNodeFilter(new TestFilterExcludeNode(ignite.localNode().consistentId()));

    assertNotNull(ignite.getOrCreateCache(ccfg));

    awaitPartitionMapExchange();

    checkCache(ccfg.getName());

    ccfg.setNodeFilter(null);
}
 
Example 10
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 11
Source File: IgniteDynamicCacheStartNoExchangeTimeoutTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testOldestChanged1() throws Exception {
    IgniteEx ignite0 = grid(0);

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setNodeFilter(new TestFilterExcludeNode(ignite0.localNode().consistentId()));

    assertNotNull(ignite(1).getOrCreateCache(ccfg));

    stopGrid(0);

    IgniteEx client = grid(NODES - 1);

    assertTrue(client.configuration().isClientMode());

    assertNotNull(client.getOrCreateCache(DEFAULT_CACHE_NAME));

    awaitPartitionMapExchange();

    checkCache(DEFAULT_CACHE_NAME);
}
 
Example 12
Source File: CacheDataRegionConfigurationTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Verifies that warning message is printed to the logs if user tries to start a dynamic cache in data region which
 * overhead (e.g. metapages for partitions) occupies more space of the region than a defined threshold.
 *
 * @throws Exception If failed.
 */
@Test
public void testWarningIfDynamicCacheOverheadExceedsThreshold() throws Exception {
    String filteredSrvName = "srv2";
    int numOfPartitions = 512;
    int partitionsMetaMemoryChunk = U.sizeInMegabytes(512 * DFLT_PAGE_SIZE);

    DataRegionConfiguration smallRegionCfg = new DataRegionConfiguration();

    smallRegionCfg.setName("smallRegion");
    smallRegionCfg.setInitialSize(DFLT_MEM_PLC_SIZE);
    smallRegionCfg.setMaxSize(DFLT_MEM_PLC_SIZE);
    smallRegionCfg.setPersistenceEnabled(true);

    //explicit default data region configuration to test possible NPE case
    DataRegionConfiguration defaultRegionCfg = new DataRegionConfiguration();
    defaultRegionCfg.setName("defaultRegion");
    defaultRegionCfg.setInitialSize(DFLT_MEM_PLC_SIZE);
    defaultRegionCfg.setMaxSize(DFLT_MEM_PLC_SIZE);
    defaultRegionCfg.setPersistenceEnabled(true);

    memCfg = new DataStorageConfiguration();
    memCfg.setDefaultDataRegionConfiguration(defaultRegionCfg);
    memCfg.setDataRegionConfigurations(smallRegionCfg);
    //one hour to guarantee that checkpoint will be triggered by 'dirty pages amount' trigger
    memCfg.setCheckpointFrequency(60 * 60 * 1000);

    ListeningTestLogger srv0Logger = new ListeningTestLogger(false, null);
    LogListener cacheGrpLsnr0 = matches("Cache group 'default' brings high overhead").build();
    LogListener dataRegLsnr0 = matches("metainformation in data region 'defaultRegion'").build();
    LogListener partsInfoLsnr0 = matches(numOfPartitions + " partitions, " +
        DFLT_PAGE_SIZE +
        " bytes per partition, " + partitionsMetaMemoryChunk + " MBs total").build();
    srv0Logger.registerAllListeners(cacheGrpLsnr0, dataRegLsnr0, partsInfoLsnr0);
    logger = srv0Logger;

    IgniteEx ignite0 = startGrid("srv0");

    ListeningTestLogger srv1Logger = new ListeningTestLogger(false, null);
    LogListener cacheGrpLsnr1 = matches("Cache group 'default' brings high overhead").build();
    LogListener dataRegLsnr1 = matches("metainformation in data region 'defaultRegion'").build();
    LogListener partsInfoLsnr1 = matches(numOfPartitions + " partitions, " +
        DFLT_PAGE_SIZE +
        " bytes per partition, " + partitionsMetaMemoryChunk + " MBs total").build();
    srv1Logger.registerAllListeners(cacheGrpLsnr1, dataRegLsnr1, partsInfoLsnr1);
    logger = srv1Logger;

    startGrid("srv1");

    ListeningTestLogger srv2Logger = new ListeningTestLogger(false, null);
    LogListener cacheGrpLsnr2 = matches("Cache group 'default' brings high overhead").build();
    srv2Logger.registerListener(cacheGrpLsnr2);
    logger = srv2Logger;

    startGrid("srv2");

    ignite0.cluster().active(true);

    IgniteEx cl = startGrid("client01");

    CacheConfiguration<Object, Object> manyPartitionsCache = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    manyPartitionsCache.setAffinity(new RendezvousAffinityFunction(false, numOfPartitions));
    manyPartitionsCache.setNodeFilter(new NodeNameNodeFilter(filteredSrvName));
    manyPartitionsCache.setBackups(1);

    cl.createCache(manyPartitionsCache);

    //srv0 and srv1 print warning into the log as the threshold for cache in default cache group is broken
    assertTrue(cacheGrpLsnr0.check());
    assertTrue(dataRegLsnr0.check());
    assertTrue(partsInfoLsnr0.check());

    assertTrue(cacheGrpLsnr1.check());
    assertTrue(dataRegLsnr1.check());
    assertTrue(partsInfoLsnr1.check());

    //srv2 doesn't print the warning as it is filtered by node filter from affinity nodes
    assertFalse(cacheGrpLsnr2.check());
}
 
Example 13
Source File: IgniteDynamicCacheStartSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testDeployFilter() throws Exception {
    try {
        testAttribute = false;

        startGrid(nodeCount());

        final IgniteEx kernal = grid(0);

        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

        ccfg.setName(DYNAMIC_CACHE_NAME);

        ccfg.setNodeFilter(NODE_FILTER);

        kernal.createCache(ccfg);

        startGrid(nodeCount() + 1);

        for (int i = 0; i < 100; i++)
            grid(0).cache(DYNAMIC_CACHE_NAME).put(i, i);

        for (int i = 0; i < 100; i++)
            assertEquals(i, grid(1).cache(DYNAMIC_CACHE_NAME).get(i));

        info("Affinity nodes: " + grid(0).affinity(DYNAMIC_CACHE_NAME).mapKeyToPrimaryAndBackups(0));

        for (int g = 0; g < nodeCount(); g++) {
            for (int i = 0; i < 100; i++) {
                assertFalse(grid(g).affinity(DYNAMIC_CACHE_NAME).mapKeyToPrimaryAndBackups(i)
                    .contains(grid(nodeCount()).cluster().localNode()));

                assertFalse(grid(g).affinity(DYNAMIC_CACHE_NAME).mapKeyToPrimaryAndBackups(i)
                    .contains(grid(nodeCount() + 1).cluster().localNode()));
            }
        }

        awaitPartitionMapExchange();

        // Check that cache is not deployed on new node after undeploy.
        for (int g = 0; g < nodeCount() + 2; g++) {
            final IgniteKernal kernal0 = (IgniteKernal)grid(g);

            if (g < nodeCount())
                assertNotNull(grid(g).cache(DYNAMIC_CACHE_NAME));
            else
                GridTestUtils.assertThrows(log, new Callable<Object>() {
                    @Override public Object call() throws Exception {
                        return kernal0.getCache(DYNAMIC_CACHE_NAME);
                    }
                }, IllegalArgumentException.class, null);
        }

        kernal.destroyCache(DYNAMIC_CACHE_NAME);

        stopGrid(nodeCount() + 1);
        stopGrid(nodeCount());
    }
    finally {
        testAttribute = true;
    }
}
 
Example 14
Source File: IgniteDynamicCacheStartNoExchangeTimeoutTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testOldestChanged3() throws Exception {
    IgniteEx ignite0 = grid(0);

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setNodeFilter(new TestFilterIncludeNode(ignite(2).cluster().localNode().consistentId()));

    assertNotNull(ignite(1).getOrCreateCache(ccfg));

    stopGrid(0);

    IgniteEx client = grid(NODES - 1);

    assertTrue(client.configuration().isClientMode());

    assertNotNull(client.getOrCreateCache(DEFAULT_CACHE_NAME));

    awaitPartitionMapExchange();

    checkCache(DEFAULT_CACHE_NAME);
}
 
Example 15
Source File: ContinuousQueryRemoteFilterMissingInClassPathSelfTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    CacheConfiguration<Object, Object> cacheCfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);

    cacheCfg.setCacheMode(CacheMode.PARTITIONED);

    cacheCfg.setNodeFilter(node -> node.attribute("filter") == null);

    cfg.setCacheConfiguration(cacheCfg);

    if (setExternalLoader)
        cfg.setClassLoader(extLdr);

    if (log != null)
        cfg.setGridLogger(log);

    if (setFilterAttr)
        cfg.setUserAttributes(U.map("filter", 1));

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

        startGrid(nodeCount());

        final IgniteEx kernal = grid(0);

        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
        ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);

        ccfg.setName(DYNAMIC_CACHE_NAME);

        ccfg.setNodeFilter(NODE_FILTER);

        final IgniteKernal started = (IgniteKernal)grid(nodeCount());

        started.createCache(ccfg);

        GridCacheAdapter<Object, Object> cache = started.internalCache(DYNAMIC_CACHE_NAME);

        assertNotNull(cache);
        assertFalse(cache.context().affinityNode());

        // Should obtain client cache on new node.
        IgniteCache<Object, Object> clientCache = ignite(nodeCount()).cache(DYNAMIC_CACHE_NAME);

        clientCache.put("1", "1");

        for (int g = 0; g < nodeCount() + 1; g++)
            assertEquals("1", ignite(g).cache(DYNAMIC_CACHE_NAME).get("1"));

        kernal.destroyCache(DYNAMIC_CACHE_NAME);
    }
    finally {
        stopGrid(nodeCount());
    }
}
 
Example 17
Source File: IgniteDynamicCacheStartNoExchangeTimeoutTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @param ccfg Cache configuration.
 * @throws Exception If failed.
 */
private void oldestNotAffinityNode1(final CacheConfiguration ccfg) throws Exception {
    log.info("Test with cache: " + ccfg.getName());

    IgniteEx ignite = grid(0);

    ccfg.setNodeFilter(new TestFilterExcludeNode(ignite.localNode().consistentId()));

    assertNotNull(ignite.getOrCreateCache(ccfg));

    awaitPartitionMapExchange();

    checkCache(ccfg.getName());
}
 
Example 18
Source File: DynamicIndexAbstractSelfTest.java    From ignite with Apache License 2.0 3 votes vote down vote up
/**
 * @return Default cache configuration.
 */
protected CacheConfiguration<KeyClass, ValueClass> cacheConfiguration() {
    CacheConfiguration ccfg = new CacheConfiguration().setName(CACHE_NAME);

    QueryEntity entity = new QueryEntity();

    entity.setKeyType(KeyClass.class.getName());
    entity.setValueType(ValueClass.class.getName());

    entity.setKeyFieldName(FIELD_KEY_ALIAS);
    entity.addQueryField(FIELD_KEY_ALIAS, entity.getKeyType(), null);

    entity.addQueryField(FIELD_KEY, Long.class.getName(), null);
    entity.addQueryField(FIELD_NAME_1_ESCAPED, Long.class.getName(), null);
    entity.addQueryField(FIELD_NAME_2_ESCAPED, Long.class.getName(), null);

    entity.setKeyFields(Collections.singleton(FIELD_KEY));

    entity.setAliases(Collections.singletonMap(FIELD_NAME_2_ESCAPED, alias(FIELD_NAME_2_ESCAPED)));

    ccfg.setQueryEntities(Collections.singletonList(entity));

    ccfg.setNodeFilter(new NodeFilter());

    ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    ccfg.setBackups(1);

    ccfg.setAffinity(new RendezvousAffinityFunction(false, 128));

    return ccfg;
}
 
Example 19
Source File: CachePartitionStateTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @param backups Number of backups.
 * @param crdAffNode If {@code false} cache is not created on coordinator.
 * @throws Exception If failed.
 */
private void partitionState1(int backups, boolean crdAffNode) throws Exception {
    startGrids(3);

    blockSupplySend(DEFAULT_CACHE_NAME);

    CacheConfiguration ccfg = cacheConfiguration(DEFAULT_CACHE_NAME, backups);

    if (!crdAffNode)
        ccfg.setNodeFilter(new TestCacheNodeExcludingFilter(getTestIgniteInstanceName(0)));

    ignite(1).createCache(ccfg);

    AffinityAssignment assign0 =
        grid(1).context().cache().internalCache(DEFAULT_CACHE_NAME).context().affinity().assignment(
            new AffinityTopologyVersion(3, 1));

    awaitPartitionMapExchange();

    checkPartitionsState(assign0, DEFAULT_CACHE_NAME, OWNING);

    checkRebalance(DEFAULT_CACHE_NAME, true);

    Ignite clientNode = startClientGrid(4);

    checkPartitionsState(assign0, DEFAULT_CACHE_NAME, OWNING);

    clientNode.cache(DEFAULT_CACHE_NAME);

    checkPartitionsState(assign0, DEFAULT_CACHE_NAME, OWNING);

    checkRebalance(DEFAULT_CACHE_NAME, true);

    startGrid(5);

    checkRebalance(DEFAULT_CACHE_NAME, false);

    for (int i = 0; i < 3; i++)
        checkNodePartitions(assign0, ignite(i).cluster().localNode(), DEFAULT_CACHE_NAME, OWNING);

    AffinityAssignment assign1 =
        grid(1).context().cache().internalCache(DEFAULT_CACHE_NAME).context().affinity().assignment(
            new AffinityTopologyVersion(5, 0));

    checkNodePartitions(assign1, ignite(5).cluster().localNode(), DEFAULT_CACHE_NAME, MOVING);

    stopBlock();

    awaitPartitionMapExchange();

    AffinityAssignment assign2 =
        grid(1).context().cache().internalCache(DEFAULT_CACHE_NAME).context().affinity().assignment(
            new AffinityTopologyVersion(5, 1));

    checkPartitionsState(assign2, DEFAULT_CACHE_NAME, OWNING);

    checkRebalance(DEFAULT_CACHE_NAME, true);

    if (!crdAffNode)
        ignite(0).cache(DEFAULT_CACHE_NAME);

    checkPartitionsState(assign2, DEFAULT_CACHE_NAME, OWNING);

    checkRebalance(DEFAULT_CACHE_NAME, true);

    startGrid(6);

    awaitPartitionMapExchange();

    AffinityAssignment assign3 =
        grid(1).context().cache().internalCache(DEFAULT_CACHE_NAME).context().affinity().assignment(
            new AffinityTopologyVersion(6, 1));

    checkPartitionsState(assign3, DEFAULT_CACHE_NAME, OWNING);

    checkRebalance(DEFAULT_CACHE_NAME, true);
}
 
Example 20
Source File: IgniteClientCacheStartFailoverTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * @param atomicityMode Cache atomicity mode.
 * @throws Exception If failed.
 */
private void clientStartLastServerFails(CacheAtomicityMode atomicityMode) throws Exception {
    startGrids(3);

    CacheConfiguration<Object, Object> cfg = cacheConfiguration(DEFAULT_CACHE_NAME, atomicityMode, 1);

    cfg.setNodeFilter(new TestNodeFilter(getTestIgniteInstanceName(1)));

    Ignite srv1 = ignite(1);

    srv1.createCache(cfg);

    final Ignite c = startClientGrid(3);

    TestRecordingCommunicationSpi.spi(srv1).blockMessages(GridDhtAffinityAssignmentResponse.class, c.name());

    IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
        @Override public Void call() throws Exception {
            c.cache(DEFAULT_CACHE_NAME);

            return null;
        }
    }, "start-cache");

    U.sleep(1000);

    assertFalse(fut.isDone());

    stopGrid(1);

    fut.get();

    final IgniteCache<Object, Object> clientCache = c.cache(DEFAULT_CACHE_NAME);

    for (int i = 0; i < 10; i++) {
        final int k = i;

        GridTestUtils.assertThrows(log, new Callable<Void>() {
            @Override public Void call() throws Exception {
                clientCache.get(k);

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

        GridTestUtils.assertThrows(log, new Callable<Void>() {
            @Override public Void call() throws Exception {
                clientCache.put(k, k);

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

        GridTestUtils.assertThrows(log, new Callable<Void>() {
            @Override public Void call() throws Exception {
                clientCache.remove(k);

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

    startGrid(1);

    awaitPartitionMapExchange();

    for (int i = 0; i < 100; i++) {
        assertNull(clientCache.get(i));

        clientCache.put(i, i);

        assertEquals(i, clientCache.get(i));
    }
}