Search in sources :

Example 61 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class NodeQueryCacheEndToEndConstructor method createPublishersAndGetQueryResults.

private Collection<QueryResult> createPublishersAndGetQueryResults(AccumulatorInfo info) {
    InvokerWrapper invokerWrapper = context.getInvokerWrapper();
    Collection<Member> members = context.getMemberList();
    List<Future<QueryResult>> futures = new ArrayList<>(members.size());
    for (Member member : members) {
        Future future = invokerWrapper.invokeOnTarget(new PublisherCreateOperation(info), member);
        futures.add(future);
    }
    return returnWithDeadline(futures, OPERATION_WAIT_TIMEOUT_MINUTES, MINUTES);
}
Also used : InvokerWrapper(com.hazelcast.map.impl.querycache.InvokerWrapper) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Member(com.hazelcast.cluster.Member) PublisherCreateOperation(com.hazelcast.map.impl.querycache.subscriber.operation.PublisherCreateOperation)

Example 62 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class OperationRunnerImpl method ensureNoPartitionProblems.

private void ensureNoPartitionProblems(Operation op) {
    int partitionId = op.getPartitionId();
    if (partitionId < 0) {
        return;
    }
    if (partitionId != getPartitionId()) {
        throw new IllegalStateException("wrong partition, expected: " + getPartitionId() + " but found:" + partitionId);
    }
    if (internalPartition == null) {
        internalPartition = nodeEngine.getPartitionService().getPartition(partitionId);
    }
    if (!isAllowedToRetryDuringMigration(op) && internalPartition.isMigrating()) {
        throw new PartitionMigratingException(thisAddress, partitionId, op.getClass().getName(), op.getServiceName());
    }
    PartitionReplica owner = internalPartition.getReplica(op.getReplicaIndex());
    if (op.validatesTarget() && (owner == null || !owner.isIdentical(node.getLocalMember()))) {
        Member target = owner != null ? node.getClusterService().getMember(owner.address(), owner.uuid()) : null;
        throw new WrongTargetException(node.getLocalMember(), target, partitionId, op.getReplicaIndex(), op.getClass().getName(), op.getServiceName());
    }
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) Member(com.hazelcast.cluster.Member) WrongTargetException(com.hazelcast.spi.exception.WrongTargetException) PartitionMigratingException(com.hazelcast.spi.exception.PartitionMigratingException)

Example 63 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class CacheSerializationTest method testCachePartitionEventData.

@Test
public void testCachePartitionEventData() throws UnknownHostException {
    Address address = new Address("127.0.0.1", 5701);
    Member member = new MemberImpl(address, MemberVersion.UNKNOWN, true);
    CachePartitionEventData cachePartitionEventData = new CachePartitionEventData("test", 1, member);
    CachePartitionEventData deserialized = service.toObject(cachePartitionEventData);
    assertEquals(cachePartitionEventData, deserialized);
}
Also used : CachePartitionEventData(com.hazelcast.cache.impl.CachePartitionEventData) Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 64 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class ClientMemberAttributeTest method testConfigAttributes.

@Test(timeout = 120000)
public void testConfigAttributes() throws Exception {
    Config c = new Config();
    JoinConfig join = c.getNetworkConfig().getJoin();
    join.getTcpIpConfig().addMember("127.0.0.1").setEnabled(true);
    join.getMulticastConfig().setEnabled(false);
    MemberAttributeConfig memberAttributeConfig = c.getMemberAttributeConfig();
    memberAttributeConfig.setAttribute("Test", "123");
    HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(c);
    Member m1 = h1.getCluster().getLocalMember();
    assertEquals("123", m1.getAttribute("Test"));
    HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(c);
    Member m2 = h2.getCluster().getLocalMember();
    assertEquals("123", m2.getAttribute("Test"));
    assertClusterSize(2, h2);
    Member member = null;
    for (Member m : h2.getCluster().getMembers()) {
        if (m.equals(h2.getCluster().getLocalMember())) {
            continue;
        }
        member = m;
    }
    assertNotNull(member);
    assertEquals(m1, member);
    assertNotNull(member.getAttribute("Test"));
    assertEquals("123", member.getAttribute("Test"));
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    Collection<Member> members = client.getCluster().getMembers();
    for (Member m : members) {
        assertEquals("123", m.getAttribute("Test"));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) JoinConfig(com.hazelcast.config.JoinConfig) JoinConfig(com.hazelcast.config.JoinConfig) MemberAttributeConfig(com.hazelcast.config.MemberAttributeConfig) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 65 with Member

use of com.hazelcast.cluster.Member in project hazelcast by hazelcast.

the class ClientClusterRestartEventTest method testMultiMemberRestart.

@Test
public void testMultiMemberRestart() throws ExecutionException, InterruptedException {
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(newConfig());
    HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(newConfig());
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(newClientConfig());
    Member oldMember1 = instance1.getCluster().getLocalMember();
    Member oldMember2 = instance2.getCluster().getLocalMember();
    final CountDownLatch memberAdded = new CountDownLatch(2);
    final Set<Member> addedMembers = Collections.newSetFromMap(new ConcurrentHashMap<Member, Boolean>());
    final CountDownLatch memberRemoved = new CountDownLatch(2);
    final Set<Member> removedMembers = Collections.newSetFromMap(new ConcurrentHashMap<Member, Boolean>());
    client.getCluster().addMembershipListener(new MembershipListener() {

        @Override
        public void memberAdded(MembershipEvent membershipEvent) {
            addedMembers.add(membershipEvent.getMember());
            memberAdded.countDown();
        }

        @Override
        public void memberRemoved(MembershipEvent membershipEvent) {
            removedMembers.add(membershipEvent.getMember());
            memberRemoved.countDown();
        }
    });
    Cluster cluster = instance1.getCluster();
    assertTrueEventually(() -> {
        try {
            cluster.shutdown();
        } catch (Exception e) {
            throw new AssertionError(e);
        }
    });
    // Allow same addresses to be used to test hot restart correctly
    hazelcastFactory.cleanup();
    Future<HazelcastInstance> f1 = spawn(() -> hazelcastFactory.newHazelcastInstance(newConfig()));
    Future<HazelcastInstance> f2 = spawn(() -> hazelcastFactory.newHazelcastInstance(newConfig()));
    instance1 = f1.get();
    instance2 = f2.get();
    Member newMember1 = instance1.getCluster().getLocalMember();
    Member newMember2 = instance2.getCluster().getLocalMember();
    assertOpenEventually(memberRemoved);
    assertEquals(2, removedMembers.size());
    assertContains(removedMembers, oldMember1);
    assertContains(removedMembers, oldMember2);
    assertOpenEventually(memberAdded);
    assertEquals(2, addedMembers.size());
    assertContains(addedMembers, newMember1);
    assertContains(addedMembers, newMember2);
    Set<Member> members = client.getCluster().getMembers();
    assertContains(members, newMember1);
    assertContains(members, newMember2);
    assertEquals(2, members.size());
}
Also used : MembershipEvent(com.hazelcast.cluster.MembershipEvent) Cluster(com.hazelcast.cluster.Cluster) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutionException(java.util.concurrent.ExecutionException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MembershipListener(com.hazelcast.cluster.MembershipListener) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Member (com.hazelcast.cluster.Member)429 Test (org.junit.Test)210 QuickTest (com.hazelcast.test.annotation.QuickTest)191 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)164 HazelcastInstance (com.hazelcast.core.HazelcastInstance)116 IExecutorService (com.hazelcast.core.IExecutorService)73 Address (com.hazelcast.cluster.Address)62 ArrayList (java.util.ArrayList)55 Future (java.util.concurrent.Future)53 UUID (java.util.UUID)43 Config (com.hazelcast.config.Config)42 CountDownLatch (java.util.concurrent.CountDownLatch)38 Map (java.util.Map)33 HashMap (java.util.HashMap)31 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)28 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)25 List (java.util.List)25 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)24 Operation (com.hazelcast.spi.impl.operationservice.Operation)24 IMap (com.hazelcast.map.IMap)23