Search in sources :

Example 1 with Member

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();
}
Also used : OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) Endpoint(com.hazelcast.core.Endpoint) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IAtomicReference(com.hazelcast.core.IAtomicReference) Cluster(com.hazelcast.core.Cluster) Member(com.hazelcast.core.Member) Test(org.junit.Test)

Example 2 with Member

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))));
}
Also used : Address(com.hazelcast.nio.Address) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress) HashMap(java.util.HashMap) BoltConnector(org.neo4j.kernel.configuration.BoltConnector) Config(org.neo4j.kernel.configuration.Config) MemberImpl(com.hazelcast.client.impl.MemberImpl) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) MemberId(org.neo4j.causalclustering.identity.MemberId) Member(com.hazelcast.core.Member) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Member

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);
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) ClusterId(org.neo4j.causalclustering.identity.ClusterId) Member(com.hazelcast.core.Member)

Example 4 with Member

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;
}
Also used : MemberId(org.neo4j.causalclustering.identity.MemberId) HashMap(java.util.HashMap) Member(com.hazelcast.core.Member)

Example 5 with Member

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;
}
Also used : HazelcastClusterNodeInfo(org.jivesoftware.openfire.plugin.util.cluster.HazelcastClusterNodeInfo) ClusterNodeInfo(org.jivesoftware.openfire.cluster.ClusterNodeInfo) Member(com.hazelcast.core.Member) HazelcastClusterNodeInfo(org.jivesoftware.openfire.plugin.util.cluster.HazelcastClusterNodeInfo)

Aggregations

Member (com.hazelcast.core.Member)159 Test (org.junit.Test)43 Address (com.hazelcast.nio.Address)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)35 QuickTest (com.hazelcast.test.annotation.QuickTest)30 ParallelTest (com.hazelcast.test.annotation.ParallelTest)26 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)20 Config (com.hazelcast.config.Config)18 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)17 HashSet (java.util.HashSet)17 Future (java.util.concurrent.Future)16 Data (com.hazelcast.nio.serialization.Data)13 Operation (com.hazelcast.spi.Operation)13 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)13 CacheEventData (com.hazelcast.cache.impl.CacheEventData)12 HeapData (com.hazelcast.internal.serialization.impl.HeapData)12 DefaultQueryCacheEventData (com.hazelcast.map.impl.querycache.event.DefaultQueryCacheEventData)12 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)12 OperationService (com.hazelcast.spi.OperationService)12