use of org.apache.ignite.spi.systemview.view.SystemView in project ignite by apache.
the class SystemViewSelfTest method testNodeAttributes.
/**
*/
@Test
public void testNodeAttributes() throws Exception {
try (IgniteEx ignite0 = startGrid(getConfiguration(getTestIgniteInstanceName(0)).setUserAttributes(F.asMap("name", "val0")));
IgniteEx ignite1 = startGrid(getConfiguration(getTestIgniteInstanceName(1)).setUserAttributes(F.asMap("name", "val1")))) {
awaitPartitionMapExchange();
SystemView<NodeAttributeView> view = ignite0.context().systemView().view(NODE_ATTRIBUTES_SYS_VIEW);
assertEquals(ignite0.cluster().localNode().attributes().size() + ignite1.cluster().localNode().attributes().size(), view.size());
assertEquals(1, F.size(view.iterator(), row -> "name".equals(row.name()) && "val0".equals(row.value())));
assertEquals(1, F.size(view.iterator(), row -> "name".equals(row.name()) && "val1".equals(row.value())));
// Test filtering.
assertTrue(view instanceof FiltrableSystemView);
Iterator<NodeAttributeView> iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NODE_ID_FILTER, ignite0.cluster().localNode().id()));
assertEquals(1, F.size(iter, row -> "name".equals(row.name()) && "val0".equals(row.value())));
iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NODE_ID_FILTER, ignite1.cluster().localNode().id().toString()));
assertEquals(1, F.size(iter, row -> "name".equals(row.name()) && "val1".equals(row.value())));
iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NODE_ID_FILTER, "malformed-id"));
assertEquals(0, F.size(iter));
iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NAME_FILTER, "name"));
assertEquals(2, F.size(iter));
iter = ((FiltrableSystemView<NodeAttributeView>) view).iterator(F.asMap(NodeAttributeViewWalker.NODE_ID_FILTER, ignite0.cluster().localNode().id(), NodeAttributeViewWalker.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 checkScanQueryView.
/**
*/
private void checkScanQueryView(IgniteEx client1, IgniteEx client2, SystemView<ScanQueryView> qrySysView) throws Exception {
boolean res = waitForCondition(() -> qrySysView.size() > 1, 5_000);
assertTrue(res);
Consumer<ScanQueryView> cache1checker = view -> {
assertEquals(client1.localNode().id(), view.originNodeId());
assertTrue(view.queryId() != 0);
assertEquals("cache1", view.cacheName());
assertEquals(cacheId("cache1"), view.cacheId());
assertEquals(cacheGroupId("cache1", "group1"), view.cacheGroupId());
assertEquals("group1", view.cacheGroupName());
assertTrue(view.startTime() <= System.currentTimeMillis());
assertTrue(view.duration() >= 0);
assertFalse(view.canceled());
assertEquals(TEST_PREDICATE, view.filter());
assertFalse(view.local());
assertEquals(-1, view.partition());
assertEquals(toStringSafe(client1.context().discovery().topologyVersionEx()), view.topology());
assertEquals(TEST_TRANSFORMER, view.transformer());
assertFalse(view.keepBinary());
assertNull(view.subjectId());
assertNull(view.taskName());
assertEquals(10, view.pageSize());
};
Consumer<ScanQueryView> cache2checker = view -> {
assertEquals(client2.localNode().id(), view.originNodeId());
assertTrue(view.queryId() != 0);
assertEquals("cache2", view.cacheName());
assertEquals(cacheId("cache2"), view.cacheId());
assertEquals(cacheGroupId("cache2", null), view.cacheGroupId());
assertEquals("cache2", view.cacheGroupName());
assertTrue(view.startTime() <= System.currentTimeMillis());
assertTrue(view.duration() >= 0);
assertFalse(view.canceled());
assertNull(view.filter());
assertFalse(view.local());
assertEquals(-1, view.partition());
assertEquals(toStringSafe(client2.context().discovery().topologyVersionEx()), view.topology());
assertNull(view.transformer());
assertTrue(view.keepBinary());
assertNull(view.subjectId());
assertNull(view.taskName());
assertEquals(20, view.pageSize());
};
boolean found1 = false;
boolean found2 = false;
for (ScanQueryView view : qrySysView) {
if ("cache2".equals(view.cacheName())) {
cache2checker.accept(view);
found1 = true;
} else {
cache1checker.accept(view);
found2 = true;
}
}
assertTrue(found1 && found2);
}
Aggregations