use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class RemoteCQTransactionDUnitTest method initAccessorAndDataStoreWithInterestPolicy.
private void initAccessorAndDataStoreWithInterestPolicy(VM accessor, VM datastore1, VM datastore2, final int redundantCopies) {
datastore2.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
createRegion(false, /* accessor */
redundantCopies, InterestPolicy.ALL);
return null;
}
});
initAccessorAndDataStore(accessor, datastore1, redundantCopies);
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class CliUtilDUnitTest method testCliUtilMethods.
@SuppressWarnings("serial")
@Test
public void testCliUtilMethods() {
setupMembersWithIdsAndGroups();
final VM vm1 = Host.getHost(0).getVM(0);
LogWriterUtils.getLogWriter().info("testFor - findMembersOrThrow");
vm1.invoke(new SerializableRunnable() {
@Override
public void run() {
verifyFindAllMatchingMembers();
}
});
final String id = (String) vm1.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
InternalCache cache = getCache();
return cache.getDistributedSystem().getDistributedMember().getId();
}
});
LogWriterUtils.getLogWriter().info("testFor - getDistributedMemberByNameOrId");
vm1.invoke(new SerializableRunnable() {
@Override
public void run() {
getDistributedMemberByNameOrId(MEMBER_1_GROUP1, id);
}
});
LogWriterUtils.getLogWriter().info("testFor - executeFunction");
vm1.invoke(new SerializableRunnable() {
@Override
public void run() {
verifyExecuteFunction();
}
});
LogWriterUtils.getLogWriter().info("testFor - getRegionAssociatedMembers");
vm1.invoke(new SerializableRunnable() {
@Override
public void run() {
getRegionAssociatedMembers();
}
});
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class ClientMembershipDUnitTest method testClientMembershipEventsInServer.
/**
* Tests notification of events in server process. Bridge servers detect client joins when the
* client connects to the server.
*/
@Test
public void testClientMembershipEventsInServer() throws Exception {
final boolean[] fired = new boolean[3];
final DistributedMember[] member = new DistributedMember[3];
final String[] memberId = new String[3];
final boolean[] isClient = new boolean[3];
// create and register ClientMembershipListener in controller vm...
ClientMembershipListener listener = new ClientMembershipListener() {
public void memberJoined(ClientMembershipEvent event) {
System.out.println("[testClientMembershipEventsInServer] memberJoined: " + event);
fired[JOINED] = true;
member[JOINED] = event.getMember();
memberId[JOINED] = event.getMemberId();
isClient[JOINED] = event.isClient();
assertFalse(fired[LEFT] || fired[CRASHED]);
}
public void memberLeft(ClientMembershipEvent event) {
System.out.println("[testClientMembershipEventsInServer] memberLeft: " + event);
fired[LEFT] = true;
member[LEFT] = event.getMember();
memberId[LEFT] = event.getMemberId();
isClient[LEFT] = event.isClient();
assertFalse(fired[JOINED] || fired[CRASHED]);
}
public void memberCrashed(ClientMembershipEvent event) {
System.out.println("[testClientMembershipEventsInServer] memberCrashed: " + event);
fired[CRASHED] = true;
member[CRASHED] = event.getMember();
memberId[CRASHED] = event.getMemberId();
isClient[CRASHED] = event.isClient();
assertFalse(fired[JOINED] || fired[LEFT]);
}
};
ClientMembership.registerClientMembershipListener(listener);
final VM vm0 = Host.getHost(0).getVM(0);
final String name = this.getUniqueName();
final int[] ports = new int[1];
// create BridgeServer in controller vm...
System.out.println("[testClientMembershipEventsInServer] Create BridgeServer");
getSystem();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
Region region = createRegion(name, factory.create());
assertNotNull(region);
assertNotNull(getRootRegion().getSubregion(name));
ports[0] = startBridgeServer(0);
assertTrue(ports[0] != 0);
DistributedMember serverMember = getMemberId();
String serverMemberId = serverMember.toString();
System.out.println("[testClientMembershipEventsInServer] ports[0]=" + ports[0]);
System.out.println("[testClientMembershipEventsInServer] serverMemberId=" + serverMemberId);
System.out.println("[testClientMembershipEventsInServer] serverMember=" + serverMember);
assertFalse(fired[JOINED]);
assertNull(member[JOINED]);
assertNull(memberId[JOINED]);
assertFalse(isClient[JOINED]);
assertFalse(fired[LEFT]);
assertNull(member[LEFT]);
assertNull(memberId[LEFT]);
assertFalse(isClient[LEFT]);
assertFalse(fired[CRASHED]);
assertNull(member[CRASHED]);
assertNull(memberId[CRASHED]);
assertFalse(isClient[CRASHED]);
// sanity check...
System.out.println("[testClientMembershipEventsInServer] sanity check");
DistributedMember test = new TestDistributedMember("test");
InternalClientMembership.notifyClientJoined(test);
Awaitility.await().pollInterval(100, TimeUnit.MILLISECONDS).pollDelay(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> {
return fired[JOINED] || fired[LEFT] || fired[CRASHED];
});
assertTrue(fired[JOINED]);
assertEquals(test, member[JOINED]);
assertEquals(test.getId(), memberId[JOINED]);
assertTrue(isClient[JOINED]);
assertFalse(fired[LEFT]);
assertNull(member[LEFT]);
assertNull(memberId[LEFT]);
assertFalse(isClient[LEFT]);
assertFalse(fired[CRASHED]);
assertNull(member[CRASHED]);
assertNull(memberId[CRASHED]);
assertFalse(isClient[CRASHED]);
resetArraysForTesting(fired, member, memberId, isClient);
final Host host = Host.getHost(0);
SerializableCallable createConnectionPool = new SerializableCallable("Create connectionPool") {
public Object call() {
System.out.println("[testClientMembershipEventsInServer] create bridge client");
Properties config = new Properties();
config.setProperty(MCAST_PORT, "0");
config.setProperty(LOCATORS, "");
config.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "false");
properties = config;
DistributedSystem s = getSystem(config);
AttributesFactory factory = new AttributesFactory();
Pool pool = ClientServerTestCase.configureConnectionPool(factory, NetworkUtils.getServerHostName(host), ports, true, -1, 2, null);
createRegion(name, factory.create());
assertNotNull(getRootRegion().getSubregion(name));
// see geode-1078
assertTrue(s == basicGetSystem());
return getMemberId();
}
};
// create bridge client in vm0...
DistributedMember clientMember = (DistributedMember) vm0.invoke(createConnectionPool);
String clientMemberId = clientMember.toString();
Awaitility.await().pollInterval(100, TimeUnit.MILLISECONDS).pollDelay(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> {
return fired[JOINED] || fired[LEFT] || fired[CRASHED];
});
System.out.println("[testClientMembershipEventsInServer] assert server detected client join");
assertTrue(fired[JOINED]);
assertEquals(member[JOINED] + " should equal " + clientMember, clientMember, member[JOINED]);
assertEquals(memberId[JOINED] + " should equal " + clientMemberId, clientMemberId, memberId[JOINED]);
assertTrue(isClient[JOINED]);
assertFalse(fired[LEFT]);
assertNull(member[LEFT]);
assertNull(memberId[LEFT]);
assertFalse(isClient[LEFT]);
assertFalse(fired[CRASHED]);
assertNull(member[CRASHED]);
assertNull(memberId[CRASHED]);
assertFalse(isClient[CRASHED]);
resetArraysForTesting(fired, member, memberId, isClient);
pauseForClientToJoin();
vm0.invoke(new SerializableRunnable("Stop bridge client") {
public void run() {
System.out.println("[testClientMembershipEventsInServer] Stop bridge client");
getRootRegion().getSubregion(name).close();
Map m = PoolManager.getAll();
Iterator mit = m.values().iterator();
while (mit.hasNext()) {
Pool p = (Pool) mit.next();
p.destroy();
}
}
});
Awaitility.await().pollInterval(100, TimeUnit.MILLISECONDS).pollDelay(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> {
return fired[JOINED] || fired[LEFT] || fired[CRASHED];
});
System.out.println("[testClientMembershipEventsInServer] assert server detected client left");
assertFalse(fired[JOINED]);
assertNull(member[JOINED]);
assertNull(memberId[JOINED]);
assertFalse(isClient[JOINED]);
assertTrue(fired[LEFT]);
assertEquals(clientMember, member[LEFT]);
assertEquals(clientMemberId, memberId[LEFT]);
assertTrue(isClient[LEFT]);
assertFalse(fired[CRASHED]);
assertNull(member[CRASHED]);
assertNull(memberId[CRASHED]);
assertFalse(isClient[CRASHED]);
resetArraysForTesting(fired, member, memberId, isClient);
// reconnect bridge client to test for crashed event
clientMemberId = vm0.invoke(createConnectionPool).toString();
Awaitility.await().pollInterval(100, TimeUnit.MILLISECONDS).pollDelay(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> {
return fired[JOINED] || fired[LEFT] || fired[CRASHED];
});
System.out.println("[testClientMembershipEventsInServer] assert server detected client re-join");
assertTrue(fired[JOINED]);
assertEquals(clientMember, member[JOINED]);
assertEquals(clientMemberId, memberId[JOINED]);
assertTrue(isClient[JOINED]);
assertFalse(fired[LEFT]);
assertNull(member[LEFT]);
assertNull(memberId[LEFT]);
assertFalse(isClient[LEFT]);
assertFalse(fired[CRASHED]);
assertNull(member[CRASHED]);
assertNull(memberId[CRASHED]);
assertFalse(isClient[CRASHED]);
resetArraysForTesting(fired, member, memberId, isClient);
pauseForClientToJoin();
ServerConnection.setForceClientCrashEvent(true);
try {
vm0.invoke(new SerializableRunnable("Stop bridge client") {
public void run() {
System.out.println("[testClientMembershipEventsInServer] Stop bridge client");
getRootRegion().getSubregion(name).close();
Map m = PoolManager.getAll();
Iterator mit = m.values().iterator();
while (mit.hasNext()) {
Pool p = (Pool) mit.next();
p.destroy();
}
}
});
Awaitility.await().pollInterval(100, TimeUnit.MILLISECONDS).pollDelay(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> {
return fired[JOINED] || fired[LEFT] || fired[CRASHED];
});
System.out.println("[testClientMembershipEventsInServer] assert server detected client crashed");
assertFalse(fired[JOINED]);
assertNull(member[JOINED]);
assertNull(memberId[JOINED]);
assertFalse(isClient[JOINED]);
assertFalse(fired[LEFT]);
assertNull(member[LEFT]);
assertNull(memberId[LEFT]);
assertFalse(isClient[LEFT]);
assertTrue(fired[CRASHED]);
assertEquals(clientMember, member[CRASHED]);
assertEquals(clientMemberId, memberId[CRASHED]);
assertTrue(isClient[CRASHED]);
} finally {
ServerConnection.setForceClientCrashEvent(false);
}
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class HostedLocatorsDUnitTest method testGetAllHostedLocatorsUsingPortZero.
@Test
public void testGetAllHostedLocatorsUsingPortZero() throws Exception {
final InternalDistributedSystem system = getSystem();
final String dunitLocator = system.getConfig().getLocators();
assertNotNull(dunitLocator);
assertFalse(dunitLocator.isEmpty());
// This will eventually contain the ports used by locators
final int[] ports = new int[] { 0, 0, 0, 0 };
final String uniqueName = getUniqueName();
for (int i = 0; i < 4; i++) {
final int whichvm = i;
Integer port = (Integer) Host.getHost(0).getVM(whichvm).invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
try {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "locators", dunitLocator);
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT, "0");
final String name = uniqueName + "-" + whichvm;
final File subdir = new File(name);
subdir.mkdir();
assertTrue(subdir.exists() && subdir.isDirectory());
final Builder builder = new Builder().setMemberName(name).setPort(ports[whichvm]).setRedirectOutput(true).setWorkingDirectory(name);
launcher = builder.build();
assertEquals(Status.ONLINE, launcher.start().getStatus());
waitForLocatorToStart(launcher, TIMEOUT_MILLISECONDS, 10, true);
return launcher.getPort();
} finally {
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "locators");
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT);
}
}
});
ports[i] = port;
}
final String host = SocketCreator.getLocalHost().getHostAddress();
final Set<String> locators = new HashSet<String>();
locators.add(host + "[" + dunitLocator.substring(dunitLocator.indexOf("[") + 1, dunitLocator.indexOf("]")) + "]");
for (int port : ports) {
locators.add(host + "[" + port + "]");
}
// validation within non-locator
final DistributionManager dm = (DistributionManager) system.getDistributionManager();
final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
assertEquals(5, locatorIds.size());
final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
assertTrue(!hostedLocators.isEmpty());
assertEquals(5, hostedLocators.size());
for (InternalDistributedMember member : hostedLocators.keySet()) {
assertEquals(1, hostedLocators.get(member).size());
final String hostedLocator = hostedLocators.get(member).iterator().next();
assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
}
// validate fix for #46324
for (int whichvm = 0; whichvm < 4; whichvm++) {
Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
@Override
public void run() {
final DistributionManager dm = (DistributionManager) InternalDistributedSystem.getAnyInstance().getDistributionManager();
final InternalDistributedMember self = dm.getDistributionManagerId();
final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
assertTrue(locatorIds.contains(self));
final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
assertTrue("hit bug #46324: " + hostedLocators + " is missing " + InternalLocator.getLocatorStrings() + " for " + self, hostedLocators.containsKey(self));
}
});
}
// validation with locators
for (int whichvm = 0; whichvm < 4; whichvm++) {
Host.getHost(0).getVM(whichvm).invoke(new SerializableRunnable() {
@Override
public void run() {
final DistributionManager dm = (DistributionManager) InternalDistributedSystem.getAnyInstance().getDistributionManager();
final Set<InternalDistributedMember> locatorIds = dm.getLocatorDistributionManagerIds();
assertEquals(5, locatorIds.size());
final Map<InternalDistributedMember, Collection<String>> hostedLocators = dm.getAllHostedLocators();
assertTrue(!hostedLocators.isEmpty());
assertEquals(5, hostedLocators.size());
for (InternalDistributedMember member : hostedLocators.keySet()) {
assertEquals(1, hostedLocators.get(member).size());
final String hostedLocator = hostedLocators.get(member).iterator().next();
assertTrue(locators + " does not contain " + hostedLocator, locators.contains(hostedLocator));
}
}
});
}
}
use of org.apache.geode.test.dunit.SerializableCallable in project geode by apache.
the class DistributedMemberDUnitTest method createSystemAndGetId.
private DistributedMember createSystemAndGetId(VM vm, final String name) {
return (DistributedMember) vm.invoke(new SerializableCallable("create system and get member") {
@Override
public Object call() throws Exception {
Properties config = new Properties();
config.setProperty(NAME, name);
DistributedSystem ds = getSystem(config);
return ds.getDistributedMember();
}
});
}
Aggregations