Search in sources :

Example 21 with MemberSelector

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

the class MemberSelectorsTest method testOrMemberSelector.

@Test
public void testOrMemberSelector() {
    when(member.localMember()).thenReturn(true);
    MemberSelector selector = MemberSelectors.or(LOCAL_MEMBER_SELECTOR, LITE_MEMBER_SELECTOR);
    assertTrue(selector.select(member));
    verify(member).localMember();
    verify(member, never()).isLiteMember();
}
Also used : MemberSelector(com.hazelcast.cluster.MemberSelector) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with MemberSelector

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

the class MemberSelectorsTest method testOrMemberSelector2.

@Test
public void testOrMemberSelector2() {
    MemberSelector selector = MemberSelectors.or(LOCAL_MEMBER_SELECTOR, LITE_MEMBER_SELECTOR);
    assertFalse(selector.select(member));
    verify(member).localMember();
    verify(member).isLiteMember();
}
Also used : MemberSelector(com.hazelcast.cluster.MemberSelector) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with MemberSelector

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

the class AbstractExecutorNullTest method testNullability.

@Test
public void testNullability() {
    Runnable sampleRunnable = (Runnable & Serializable) () -> {
    };
    Callable<Object> sampleCallable = (Callable & Serializable) () -> "";
    Member sampleMember = getDriver().getCluster().getMembers().iterator().next();
    Set<Member> sampleMembers = Collections.singleton(sampleMember);
    MemberSelector sampleSelector = member -> true;
    ExecutionCallback<Object> sampleCallback = new ExecutionCallback<Object>() {

        @Override
        public void onResponse(Object response) {
        }

        @Override
        public void onFailure(Throwable t) {
        }
    };
    MultiExecutionCallback sampleMultiExecutionCallback = new MultiExecutionCallback() {

        @Override
        public void onResponse(Member member, Object value) {
        }

        @Override
        public void onComplete(Map<Member, Object> values) {
        }
    };
    assertThrowsNPE(s -> s.execute((Runnable) null, sampleSelector));
    assertThrowsNPE(s -> s.execute(sampleRunnable, null));
    assertThrowsNPE(s -> s.executeOnKeyOwner(null, ""));
    assertThrowsNPE(s -> s.executeOnKeyOwner(sampleRunnable, null));
    assertThrowsNPE(s -> s.executeOnMember(null, sampleMember));
    assertThrowsNPE(s -> s.executeOnMember(sampleRunnable, null));
    assertThrowsNPE(s -> s.executeOnMembers(null, sampleMembers));
    assertThrowsNPE(s -> s.executeOnMembers(sampleRunnable, (Collection<Member>) null));
    assertThrowsNPE(s -> s.executeOnMembers(null, sampleSelector));
    assertThrowsNPE(s -> s.executeOnMembers(sampleRunnable, (MemberSelector) null));
    assertThrowsNPE(s -> s.executeOnAllMembers(null));
    System.out.println("------------1");
    assertThrowsNPE(s -> s.submit((Callable) null, sampleSelector));
    assertThrowsNPE(s -> s.submit(sampleCallable, (MemberSelector) null));
    assertThrowsNPE(s -> s.submitToKeyOwner((Callable) null, ""));
    assertThrowsNPE(s -> s.submitToKeyOwner(sampleCallable, null));
    assertThrowsNPE(s -> s.submitToMember((Callable) null, sampleMember));
    assertThrowsNPE(s -> s.submitToMember(sampleCallable, null));
    assertThrowsNPE(s -> s.submitToMembers((Callable) null, sampleMembers));
    assertThrowsNPE(s -> s.submitToMembers(sampleCallable, (Collection<Member>) null));
    assertThrowsNPE(s -> s.submitToMembers((Callable) null, sampleSelector));
    assertThrowsNPE(s -> s.submitToMembers(sampleCallable, (MemberSelector) null));
    assertThrowsNPE(s -> s.submitToAllMembers(null));
    System.out.println("------------2");
    assertThrowsNPE(s -> s.submit((Runnable) null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submit(sampleRunnable, (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submit((Runnable) null, sampleSelector, sampleCallback));
    assertThrowsNPE(s -> s.submit(sampleRunnable, (MemberSelector) null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submit(sampleRunnable, sampleSelector, (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submitToKeyOwner((Runnable) null, "", sampleCallback));
    assertThrowsNPE(s -> s.submitToKeyOwner(sampleRunnable, null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submitToKeyOwner(sampleRunnable, "", (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submitToMember((Runnable) null, sampleMember, sampleCallback));
    assertThrowsNPE(s -> s.submitToMember(sampleRunnable, null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submitToMember(sampleRunnable, sampleMember, (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submitToMembers((Runnable) null, sampleMembers, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleRunnable, (Collection) null, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleRunnable, sampleMembers, (MultiExecutionCallback) null));
    assertThrowsNPE(s -> s.submitToMembers((Runnable) null, sampleSelector, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleRunnable, (MemberSelector) null, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleRunnable, sampleSelector, (MultiExecutionCallback) null));
    assertThrowsNPE(s -> s.submitToAllMembers((Runnable) null, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToAllMembers(sampleRunnable, null));
    System.out.println("------------3");
    assertThrowsNPE(s -> s.submit((Callable<Object>) null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submit(sampleCallable, (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submit((Callable) null, sampleSelector, sampleCallback));
    assertThrowsNPE(s -> s.submit(sampleCallable, (MemberSelector) null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submit(sampleCallable, sampleSelector, (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submitToKeyOwner((Callable) null, "", sampleCallback));
    assertThrowsNPE(s -> s.submitToKeyOwner(sampleCallable, null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submitToKeyOwner(sampleCallable, "", (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submitToMember((Callable) null, sampleMember, sampleCallback));
    assertThrowsNPE(s -> s.submitToMember(sampleCallable, null, sampleCallback));
    getDriver().getExecutorService(RANDOM_NAME).submitToMember(sampleCallable, sampleMember, (ExecutionCallback) null);
    assertThrowsNPE(s -> s.submitToMembers((Callable) null, sampleMembers, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleCallable, (Collection) null, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleCallable, sampleMembers, (MultiExecutionCallback) null));
    assertThrowsNPE(s -> s.submitToMembers((Callable) null, sampleSelector, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleCallable, (MemberSelector) null, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToMembers(sampleCallable, sampleSelector, (MultiExecutionCallback) null));
    assertThrowsNPE(s -> s.submitToAllMembers((Callable) null, sampleMultiExecutionCallback));
    assertThrowsNPE(s -> s.submitToAllMembers(sampleCallable, null));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Member(com.hazelcast.cluster.Member) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) Collection(java.util.Collection) ExceptionUtil(com.hazelcast.internal.util.ExceptionUtil) Set(java.util.Set) Test(org.junit.Test) Callable(java.util.concurrent.Callable) Serializable(java.io.Serializable) MemberSelector(com.hazelcast.cluster.MemberSelector) Consumer(java.util.function.Consumer) IExecutorService(com.hazelcast.core.IExecutorService) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) ExecutionCallback(com.hazelcast.core.ExecutionCallback) Map(java.util.Map) Collections(java.util.Collections) Callable(java.util.concurrent.Callable) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) MemberSelector(com.hazelcast.cluster.MemberSelector) Collection(java.util.Collection) Member(com.hazelcast.cluster.Member) Map(java.util.Map) MultiExecutionCallback(com.hazelcast.core.MultiExecutionCallback) ExecutionCallback(com.hazelcast.core.ExecutionCallback) Test(org.junit.Test)

Aggregations

MemberSelector (com.hazelcast.cluster.MemberSelector)23 Test (org.junit.Test)20 QuickTest (com.hazelcast.test.annotation.QuickTest)17 IExecutorService (com.hazelcast.core.IExecutorService)11 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 SelectAllMembers (com.hazelcast.client.test.executor.tasks.SelectAllMembers)8 Member (com.hazelcast.cluster.Member)8 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)8 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)6 MultiExecutionCallback (com.hazelcast.core.MultiExecutionCallback)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 AppendCallable (com.hazelcast.client.test.executor.tasks.AppendCallable)3 ExecutionCallback (com.hazelcast.core.ExecutionCallback)3 IMap (com.hazelcast.map.IMap)3 Callable (java.util.concurrent.Callable)3 MapPutPartitionAwareRunnable (com.hazelcast.client.executor.tasks.MapPutPartitionAwareRunnable)2 MapPutPartitionAwareCallable (com.hazelcast.client.test.executor.tasks.MapPutPartitionAwareCallable)2 NullCallable (com.hazelcast.client.test.executor.tasks.NullCallable)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2