use of org.apache.ignite.spi.systemview.view.SystemView in project ignite by apache.
the class FunctionalTest method testTransactionsWithLabel.
/**
* Test transactions with label.
*/
@Test
public void testTransactionsWithLabel() throws Exception {
try (IgniteEx ignite = (IgniteEx) Ignition.start(Config.getServerConfiguration());
IgniteClient client = Ignition.startClient(getClientConfiguration())) {
ClientCache<Integer, String> cache = client.createCache(new ClientCacheConfiguration().setName("cache").setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL));
SystemView<TransactionView> txsView = ignite.context().systemView().view(TXS_MON_LIST);
cache.put(0, "value1");
try (ClientTransaction tx = client.transactions().withLabel("label").txStart()) {
cache.put(0, "value2");
assertEquals(1, F.size(txsView.iterator()));
TransactionView txv = txsView.iterator().next();
assertEquals("label", txv.label());
assertEquals("value2", cache.get(0));
}
assertEquals("value1", cache.get(0));
try (ClientTransaction tx = client.transactions().withLabel("label1").withLabel("label2").txStart()) {
cache.put(0, "value2");
assertEquals(1, F.size(txsView.iterator()));
TransactionView txv = txsView.iterator().next();
assertEquals("label2", txv.label());
tx.commit();
}
assertEquals("value2", cache.get(0));
// Test concurrent with label and without label transactions.
try (ClientTransaction tx = client.transactions().withLabel("label").txStart(PESSIMISTIC, READ_COMMITTED)) {
CyclicBarrier barrier = new CyclicBarrier(2);
cache.put(0, "value3");
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
try (ClientTransaction tx1 = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
cache.put(1, "value3");
barrier.await();
assertEquals("value2", cache.get(0));
barrier.await();
} catch (InterruptedException | BrokenBarrierException ignore) {
// No-op.
}
});
barrier.await();
assertNull(cache.get(1));
assertEquals(1, F.size(txsView.iterator(), txv -> txv.label() == null));
assertEquals(1, F.size(txsView.iterator(), txv -> "label".equals(txv.label())));
barrier.await();
fut.get();
}
// Test nested transactions is not possible.
try (ClientTransaction tx = client.transactions().withLabel("label1").txStart()) {
try (ClientTransaction tx1 = client.transactions().txStart()) {
fail();
} catch (ClientException expected) {
// No-op.
}
try (ClientTransaction tx1 = client.transactions().withLabel("label2").txStart()) {
fail();
} catch (ClientException expected) {
// No-op.
}
}
}
}
use of org.apache.ignite.spi.systemview.view.SystemView in project ignite by apache.
the class SystemViewSelfTest method testDistributedMetastorage.
/**
*/
@Test
public void testDistributedMetastorage() throws Exception {
cleanPersistenceDir();
try (IgniteEx ignite = startGrid(getConfiguration().setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true))))) {
ignite.cluster().state(ClusterState.ACTIVE);
DistributedMetaStorage dms = ignite.context().distributedMetastorage();
SystemView<MetastorageView> metaStoreView = ignite.context().systemView().view(DISTRIBUTED_METASTORE_VIEW);
assertNotNull(metaStoreView);
String name = "test-distributed-key";
String val = "test-distributed-value";
dms.write(name, val);
MetastorageView testKey = F.find(metaStoreView, null, (IgnitePredicate<? super MetastorageView>) view -> name.equals(view.name()) && val.equals(view.value()));
assertNotNull(testKey);
}
}
use of org.apache.ignite.spi.systemview.view.SystemView in project ignite by apache.
the class SystemViewSelfTest method testCacheGroupIo.
/**
*/
@Test
public void testCacheGroupIo() throws Exception {
cleanPersistenceDir();
try (IgniteEx ignite = startGrid(getConfiguration().setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true))))) {
ignite.cluster().state(ClusterState.ACTIVE);
IgniteCache<Object, Object> cache = ignite.createCache("cache");
cache.put(0, 0);
cache.get(0);
SystemView<CacheGroupIoView> view = ignite.context().systemView().view(CACHE_GRP_IO_VIEW);
CacheGroupIoView row = F.find(view, null, (IgnitePredicate<CacheGroupIoView>) r -> "cache".equals(r.cacheGroupName()));
assertNotNull(row);
assertTrue(row.logicalReads() > 0);
}
}
use of org.apache.ignite.spi.systemview.view.SystemView in project ignite by apache.
the class SystemViewSelfTest method testBaselineNodeAttributes.
/**
*/
@Test
public void testBaselineNodeAttributes() throws Exception {
cleanPersistenceDir();
try (IgniteEx ignite = startGrid(getConfiguration().setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setName("pds").setPersistenceEnabled(true))).setUserAttributes(F.asMap("name", "val")).setConsistentId("consId"))) {
ignite.cluster().state(ClusterState.ACTIVE);
SystemView<BaselineNodeAttributeView> view = ignite.context().systemView().view(BASELINE_NODE_ATTRIBUTES_SYS_VIEW);
assertEquals(ignite.cluster().localNode().attributes().size(), view.size());
assertEquals(1, F.size(view.iterator(), row -> "consId".equals(row.nodeConsistentId()) && "name".equals(row.name()) && "val".equals(row.value())));
// Test filtering.
assertTrue(view instanceof FiltrableSystemView);
Iterator<BaselineNodeAttributeView> iter = ((FiltrableSystemView<BaselineNodeAttributeView>) view).iterator(F.asMap(BaselineNodeAttributeViewWalker.NODE_CONSISTENT_ID_FILTER, "consId", BaselineNodeAttributeViewWalker.NAME_FILTER, "name"));
assertEquals(1, F.size(iter));
iter = ((FiltrableSystemView<BaselineNodeAttributeView>) view).iterator(F.asMap(BaselineNodeAttributeViewWalker.NODE_CONSISTENT_ID_FILTER, "consId"));
assertEquals(1, F.size(iter, row -> "name".equals(row.name())));
iter = ((FiltrableSystemView<BaselineNodeAttributeView>) view).iterator(F.asMap(BaselineNodeAttributeViewWalker.NAME_FILTER, "name"));
assertEquals(1, F.size(iter));
}
}
use of org.apache.ignite.spi.systemview.view.SystemView in project ignite by apache.
the class SystemViewSelfTest method testNodeMetrics.
/**
*/
@Test
public void testNodeMetrics() throws Exception {
long ts = U.currentTimeMillis();
try (IgniteEx ignite0 = startGrid(0);
IgniteEx ignite1 = startGrid(1)) {
awaitPartitionMapExchange();
SystemView<NodeMetricsView> view = ignite0.context().systemView().view(NODE_METRICS_SYS_VIEW);
assertEquals(2, view.size());
assertEquals(1, F.size(view.iterator(), row -> row.nodeId().equals(ignite0.cluster().localNode().id())));
assertEquals(1, F.size(view.iterator(), row -> row.nodeId().equals(ignite1.cluster().localNode().id())));
assertEquals(2, F.size(view.iterator(), row -> row.lastUpdateTime().getTime() >= ts));
}
}
Aggregations