use of com.hazelcast.core.Member in project neo4j by neo4j.
the class HazelcastClientTest method shouldNotReconnectWhileHazelcastRemainsAvailable.
@Test
public void shouldNotReconnectWhileHazelcastRemainsAvailable() throws Throwable {
// given
HazelcastConnector connector = mock(HazelcastConnector.class);
OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
HazelcastClient client = new HazelcastClient(connector, jobScheduler, NullLogProvider.getInstance(), config(), myself);
HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
when(connector.connectToHazelcast()).thenReturn(hazelcastInstance);
when(hazelcastInstance.getAtomicReference(anyString())).thenReturn(mock(IAtomicReference.class));
when(hazelcastInstance.getSet(anyString())).thenReturn(new HazelcastSet());
when(hazelcastInstance.getMultiMap(anyString())).thenReturn(new HazelcastMultiMap());
when(hazelcastInstance.getExecutorService(anyString())).thenReturn(new StubExecutorService());
com.hazelcast.core.Cluster cluster = mock(Cluster.class);
when(hazelcastInstance.getCluster()).thenReturn(cluster);
Set<Member> members = asSet(makeMember(1), makeMember(2));
when(cluster.getMembers()).thenReturn(members);
// when
client.start();
jobScheduler.runJob();
CoreTopology topology;
for (int i = 0; i < 5; i++) {
topology = client.coreServers();
assertEquals(members.size(), topology.members().size());
}
// then
verify(connector, times(1)).connectToHazelcast();
}
use of com.hazelcast.core.Member in project neo4j by neo4j.
the class HazelcastClusterTopologyTest method shouldLogAndExcludeMembersWithMissingAttributes.
@Test
public void shouldLogAndExcludeMembersWithMissingAttributes() throws Exception {
// given
Set<Member> hazelcastMembers = new HashSet<>();
List<MemberId> coreMembers = new ArrayList<>();
for (int i = 0; i < 4; i++) {
MemberId memberId = new MemberId(UUID.randomUUID());
coreMembers.add(memberId);
Config config = Config.defaults();
HashMap<String, String> settings = new HashMap<>();
settings.put(new BoltConnector("bolt").type.name(), "BOLT");
settings.put(new BoltConnector("bolt").enabled.name(), "true");
settings.put(new BoltConnector("bolt").advertised_address.name(), "bolt:" + (i + 1));
settings.put(new BoltConnector("http").type.name(), "HTTP");
settings.put(new BoltConnector("http").enabled.name(), "true");
settings.put(new BoltConnector("http").advertised_address.name(), "http:" + (i + 1));
config.augment(settings);
Map<String, Object> attributes = buildMemberAttributesForCore(memberId, config).getAttributes();
if (i == 2) {
attributes.remove(HazelcastClusterTopology.RAFT_SERVER);
}
hazelcastMembers.add(new MemberImpl(new Address("localhost", i), null, attributes, false));
}
// when
Map<MemberId, CoreServerInfo> map = toCoreMemberMap(hazelcastMembers, NullLog.getInstance(), hzInstance);
// then
assertThat(map.keySet(), hasItems(coreMembers.get(0), coreMembers.get(1), coreMembers.get(3)));
assertThat(map.keySet(), not(hasItems(coreMembers.get(2))));
}
use of com.hazelcast.core.Member in project neo4j by neo4j.
the class HazelcastClusterTopology method getCoreTopology.
static CoreTopology getCoreTopology(HazelcastInstance hazelcastInstance, Config config, Log log) {
Map<MemberId, CoreServerInfo> coreMembers = emptyMap();
boolean canBeBootstrapped = false;
ClusterId clusterId = null;
if (hazelcastInstance != null) {
Set<Member> hzMembers = hazelcastInstance.getCluster().getMembers();
canBeBootstrapped = canBeBootstrapped(hazelcastInstance, config);
coreMembers = toCoreMemberMap(hzMembers, log, hazelcastInstance);
clusterId = getClusterId(hazelcastInstance);
} else {
log.info("Cannot currently bind to distributed discovery service.");
}
return new CoreTopology(clusterId, canBeBootstrapped, coreMembers);
}
use of com.hazelcast.core.Member in project neo4j by neo4j.
the class HazelcastClusterTopology method toCoreMemberMap.
static Map<MemberId, CoreServerInfo> toCoreMemberMap(Set<Member> members, Log log, HazelcastInstance hazelcastInstance) {
Map<MemberId, CoreServerInfo> coreMembers = new HashMap<>();
MultiMap<String, String> serverGroupsMMap = hazelcastInstance.getMultiMap(SERVER_GROUPS_MULTIMAP_NAME);
for (Member member : members) {
try {
MemberId memberId = new MemberId(UUID.fromString(member.getStringAttribute(MEMBER_UUID)));
CoreServerInfo coreServerInfo = new CoreServerInfo(socketAddress(member.getStringAttribute(RAFT_SERVER), AdvertisedSocketAddress::new), socketAddress(member.getStringAttribute(TRANSACTION_SERVER), AdvertisedSocketAddress::new), ClientConnectorAddresses.fromString(member.getStringAttribute(CLIENT_CONNECTOR_ADDRESSES)), asSet(serverGroupsMMap.get(memberId.getUuid().toString())));
coreMembers.put(memberId, coreServerInfo);
} catch (IllegalArgumentException e) {
log.warn("Incomplete member attributes supplied from Hazelcast", e);
}
}
return coreMembers;
}
use of com.hazelcast.core.Member in project Openfire by igniterealtime.
the class ClusteredCacheFactory method getClusterNodeInfo.
public ClusterNodeInfo getClusterNodeInfo(byte[] nodeID) {
if (cluster == null) {
return null;
}
ClusterNodeInfo result = null;
Member member = getMember(nodeID);
if (member != null) {
result = new HazelcastClusterNodeInfo(member, cluster.getClusterTime());
}
return result;
}
Aggregations