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();
}
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");
}
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);
}
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);
}
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;
}
Aggregations