use of org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.NODE_ATTRIBUTES_SYS_VIEW 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));
}
}
Aggregations