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();
}
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);
}
Aggregations