Search in sources :

Example 1 with ACTIVE_READ_ONLY

use of org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY in project ignite by apache.

the class ClusterReadOnlyModeSelfTest method testEnableReadOnlyModeInsideTransaction.

/**
 */
@Test
public void testEnableReadOnlyModeInsideTransaction() throws Exception {
    IgniteEx grid = startGrids(SERVER_NODES_COUNT);
    grid.cluster().state(ACTIVE);
    CacheConfiguration cfg = Stream.of(grid.configuration().getCacheConfiguration()).filter(c -> c.getAtomicityMode() == CacheAtomicityMode.TRANSACTIONAL).filter(c -> !CU.isSystemCache(c.getName())).findAny().get();
    final int key = 1;
    IgniteCache<Integer, Integer> cache = grid.cache(cfg.getName());
    cache.put(key, 0);
    CountDownLatch startTxLatch = new CountDownLatch(1);
    CountDownLatch clusterReadOnlyLatch = new CountDownLatch(1);
    Thread t = new Thread(() -> {
        try {
            startTxLatch.await();
            grid(1).cluster().state(ACTIVE_READ_ONLY);
            assertEquals(ACTIVE_READ_ONLY, grid(1).cluster().state());
            clusterReadOnlyLatch.countDown();
        } catch (InterruptedException e) {
            log.error("Thread interrupted", e);
            fail("Thread interrupted");
        }
    });
    t.start();
    Transaction tx = grid(0).transactions().txStart();
    try {
        cache.put(key, 1);
        startTxLatch.countDown();
        tx.commit();
    } catch (Exception e) {
        log.error("TX Failed", e);
        tx.rollback();
    }
    assertEquals(1, (int) cache.get(key));
    t.join();
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) ClusterReadOnlyModeTestUtils.cacheNames(org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTestUtils.cacheNames) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) GridCacheUtilityKey(org.apache.ignite.internal.processors.cache.GridCacheUtilityKey) HashSet(java.util.HashSet) ACTIVE_READ_ONLY(org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) CacheException(javax.cache.CacheException) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) ClusterReadOnlyModeTestUtils.assertDataStreamerReadOnlyMode(org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTestUtils.assertDataStreamerReadOnlyMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) ClusterReadOnlyModeTestUtils.assertCachesReadOnlyMode(org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTestUtils.assertCachesReadOnlyMode) MetaStorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage) Test(org.junit.Test) IgniteCache(org.apache.ignite.IgniteCache) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteClusterReadOnlyException(org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CU(org.apache.ignite.internal.util.typedef.internal.CU) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ClusterReadOnlyModeTestUtils.cacheConfigurations(org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTestUtils.cacheConfigurations) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) CountDownLatch(java.util.concurrent.CountDownLatch) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CacheException(javax.cache.CacheException) IgniteClusterReadOnlyException(org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with ACTIVE_READ_ONLY

use of org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY in project ignite by apache.

the class ClusterStateChangeEventTest method test.

/**
 */
@Test
public void test() throws Exception {
    IgniteEx crd = grid(0);
    crd.cluster().state(ACTIVE);
    Map<Integer, Integer> data = IntStream.range(0, 1000).boxed().collect(Collectors.toMap(i -> i, i -> i));
    crd.cache(DEFAULT_CACHE_NAME).putAll(data);
    for (Ignite node : G.allGrids()) assertEquals(node.name(), ACTIVE, node.cluster().state());
    // ACTIVE -> READ_ONLY
    changeStateAndCheckEvents(ACTIVE_READ_ONLY);
    // READ_ONLY -> ACTIVE
    changeStateAndCheckEvents(ACTIVE);
    // ACTIVE -> INACTIVE
    changeStateAndCheckEvents(INACTIVE);
    // INACTIVE -> READ_ONLY
    changeStateAndCheckEvents(ACTIVE_READ_ONLY);
    // READ_ONLY -> INACTIVE
    changeStateAndCheckEvents(INACTIVE);
    // INACTIVE -> ACTIVE
    changeStateAndCheckEvents(ACTIVE);
}
Also used : IntStream(java.util.stream.IntStream) ClusterState(org.apache.ignite.cluster.ClusterState) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) ACTIVE_READ_ONLY(org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY) Map(java.util.Map) Collectors.toSet(java.util.stream.Collectors.toSet) G(org.apache.ignite.internal.util.typedef.G) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) IgniteFuture(org.apache.ignite.lang.IgniteFuture) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) EventType(org.apache.ignite.events.EventType) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) Set(java.util.Set) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) EVT_CLUSTER_STATE_CHANGED(org.apache.ignite.events.EventType.EVT_CLUSTER_STATE_CHANGED) Collectors(java.util.stream.Collectors) BaselineNode(org.apache.ignite.cluster.BaselineNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClusterStateChangeEvent(org.apache.ignite.events.ClusterStateChangeEvent) Comparator.comparingLong(java.util.Comparator.comparingLong) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections.max(java.util.Collections.max) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ACTIVE (org.apache.ignite.cluster.ClusterState.ACTIVE)2 ACTIVE_READ_ONLY (org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 Collection (java.util.Collection)1 Collections.max (java.util.Collections.max)1 Comparator.comparingLong (java.util.Comparator.comparingLong)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Collectors (java.util.stream.Collectors)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 CacheException (javax.cache.CacheException)1