Search in sources :

Example 56 with Member

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

the class QuorumTest method testCustomQuorumFunctionFailsThenSuccess.

@Test
public void testCustomQuorumFunctionFailsThenSuccess() {
    final AtomicInteger count = new AtomicInteger(1);
    String mapName = randomMapName();
    String quorumName = randomString();
    MapConfig mapConfig = new MapConfig(mapName).setQuorumName(quorumName);
    QuorumConfig quorumConfig = new QuorumConfig().setName(quorumName).setEnabled(true).setQuorumFunctionImplementation(new QuorumFunction() {

        @Override
        public boolean apply(Collection<Member> members) {
            if (count.get() == 1) {
                count.incrementAndGet();
                return false;
            } else {
                return true;
            }
        }
    });
    Config config = new Config().addMapConfig(mapConfig).addQuorumConfig(quorumConfig);
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(2);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance(config);
    IMap<Object, Object> map = hazelcastInstance.getMap(mapName);
    try {
        map.put("1", "1");
        fail();
    } catch (Exception e) {
        e.printStackTrace();
    }
    factory.newHazelcastInstance(config);
    map.put("1", "1");
    factory.shutdownAll();
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapConfig(com.hazelcast.config.MapConfig) Member(com.hazelcast.core.Member) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 57 with Member

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

the class QuorumTest method testCustomQuorumFunctionFails.

@Test(expected = QuorumException.class)
public void testCustomQuorumFunctionFails() {
    String mapName = randomMapName();
    String quorumName = randomString();
    MapConfig mapConfig = new MapConfig(mapName).setQuorumName(quorumName);
    QuorumConfig quorumConfig = new QuorumConfig().setName(quorumName).setEnabled(true).setQuorumFunctionImplementation(new QuorumFunction() {

        @Override
        public boolean apply(Collection<Member> members) {
            return false;
        }
    });
    Config config = new Config().addQuorumConfig(quorumConfig).addMapConfig(mapConfig);
    HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
    IMap<Object, Object> map = hazelcastInstance.getMap(mapName);
    map.put("1", "1");
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 58 with Member

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

the class BaseQuorumListenerTest method testCustomResolverFiresQuorumFailureEvent.

@Test
public void testCustomResolverFiresQuorumFailureEvent() {
    CountDownLatch quorumNotPresent = new CountDownLatch(1);
    QuorumListenerConfig listenerConfig = new QuorumListenerConfig(quorumListener(null, quorumNotPresent));
    String distributedObjectName = randomString();
    String quorumName = randomString();
    QuorumConfig quorumConfig = new QuorumConfig().setName(quorumName).setEnabled(true).addListenerConfig(listenerConfig).setQuorumFunctionImplementation(new QuorumFunction() {

        @Override
        public boolean apply(Collection<Member> members) {
            return false;
        }
    });
    Config config = new Config().addQuorumConfig(quorumConfig);
    addQuorumConfig(config, distributedObjectName, quorumName);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    factory.newHazelcastInstance(config);
    factory.newHazelcastInstance();
    assertOpenEventually(quorumNotPresent, 15);
}
Also used : QuorumConfig(com.hazelcast.config.QuorumConfig) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) Config(com.hazelcast.config.Config) QuorumListenerConfig(com.hazelcast.config.QuorumListenerConfig) QuorumConfig(com.hazelcast.config.QuorumConfig) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.core.Member) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 59 with Member

use of com.hazelcast.core.Member in project Payara by payara.

the class ListHazelcastMembers method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    if (hazelcast.isEnabled()) {
        HazelcastInstance instance = hazelcast.getInstance();
        if (instance != null) {
            StringBuilder builder = new StringBuilder();
            builder.append("{ ");
            for (Member member : instance.getCluster().getMembers()) {
                String memberName = member.getStringAttribute(HazelcastCore.INSTANCE_ATTRIBUTE);
                if (memberName != null) {
                    builder.append(memberName).append("-");
                }
                String groupName = member.getStringAttribute(HazelcastCore.INSTANCE_GROUP_ATTRIBUTE);
                if (groupName != null) {
                    builder.append(groupName).append("-");
                }
                builder.append(member.getSocketAddress().toString());
                if (member.localMember()) {
                    builder.append("-this");
                }
                if (member.isLiteMember()) {
                    builder.append("-LITE");
                }
                builder.append(" ");
            }
            builder.append('}');
            actionReport.setMessage(builder.toString());
            // build extra message
            Properties extraProps = new Properties();
            StringBuilder extraBuilder = new StringBuilder(actionReport.getMessage());
            extraBuilder.append("<br/>");
            for (ActionReport subReport : actionReport.getSubActionsReport()) {
                extraBuilder.append(subReport.getMessage()).append("<br/>");
            }
            extraProps.put("Members", extraBuilder.toString());
            actionReport.setExtraProperties(extraProps);
        }
    } else {
        Properties extraProps = new Properties();
        extraProps.put("Members", "Hazelcast is not enabled");
        actionReport.setExtraProperties(extraProps);
        actionReport.setMessage("Hazelcast is not enabled");
    }
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) Member(com.hazelcast.core.Member)

Example 60 with Member

use of com.hazelcast.core.Member in project Payara by payara.

the class ClusterExecutionService method runCallable.

/**
 * Runs a Callable object on the specified Member
 * @param <T> Type of the Callable Result
 * @param memberUUID The member to run the Callable on
 * @param callable The Callable object
 * @return Future for the result
 */
public <T extends Serializable> Future<T> runCallable(String memberUUID, Callable<T> callable) {
    Future<T> result = null;
    if (hzCore.isEnabled()) {
        Member toSubmitTo = selectMember(memberUUID);
        result = hzCore.getInstance().getExecutorService(HazelcastCore.CLUSTER_EXECUTOR_SERVICE_NAME).submitToMember(callable, toSubmitTo);
    }
    return result;
}
Also used : Member(com.hazelcast.core.Member)

Aggregations

Member (com.hazelcast.core.Member)167 Test (org.junit.Test)43 Address (com.hazelcast.nio.Address)39 HazelcastInstance (com.hazelcast.core.HazelcastInstance)37 QuickTest (com.hazelcast.test.annotation.QuickTest)30 ParallelTest (com.hazelcast.test.annotation.ParallelTest)26 HashMap (java.util.HashMap)21 ArrayList (java.util.ArrayList)20 Config (com.hazelcast.config.Config)18 HashSet (java.util.HashSet)18 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)17 Future (java.util.concurrent.Future)17 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