use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class PersistentRVVRecoveryDUnitTest method testSkipConflictChecksForConcurrentOps.
/**
* Test that we skip conflict checks with entries that are on disk compared to entries that come
* in as part of a concurrent operation
*/
@Test
public void testSkipConflictChecksForConcurrentOps() throws Throwable {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// Create the region in few members to test recovery
createPersistentRegion(vm0);
createPersistentRegion(vm1);
// Create an update some entries in vm0 and vm1.
createData(vm0, 0, 1, "value1");
createData(vm0, 0, 1, "value2");
createData(vm0, 0, 1, "value2");
closeCache(vm1);
// Update the keys in vm0 until the entry version rolls over.
// This means that if we did a conflict check, vm0's key will have
// a lower entry version than vm1, which would cause us to prefer vm1's
// value
SerializableRunnable createData = new SerializableRunnable("rollEntryVersion") {
public void run() {
Cache cache = getCache();
LocalRegion region = (LocalRegion) cache.getRegion(REGION_NAME);
region.put(0, "value3");
RegionEntry entry = region.getRegionEntry(0);
entry = region.getRegionEntry(0);
// Sneak in and change the version number for an entry to generate
// a conflict.
VersionTag tag = entry.getVersionStamp().asVersionTag();
tag.setEntryVersion(tag.getEntryVersion() - 2);
entry.getVersionStamp().setVersions(tag);
}
};
vm0.invoke(createData);
// Add an observer to vm0 which will perform a concurrent operation during
// the GII. If we do a conflict check, this operation will be rejected
// because it will have a lower entry version that what vm1 recovered from
// disk
vm0.invoke(new SerializableRunnable() {
@Override
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage msg) {
if (msg instanceof InitialImageOperation.RequestImageMessage) {
if (((InitialImageOperation.RequestImageMessage) msg).regionPath.contains(REGION_NAME)) {
createData(vm0, 0, 1, "value4");
DistributionMessageObserver.setInstance(null);
}
}
}
});
}
});
// Create vm1, doing a GII
createPersistentRegion(vm1);
// If we did a conflict check, this would be value2
checkData(vm0, 0, 1, "value4");
checkData(vm1, 0, 1, "value4");
}
use of org.apache.geode.distributed.internal.DistributionManager 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.distributed.internal.DistributionManager in project geode by apache.
the class DistributedSystemDUnitTest method testWaitForDeparture.
/**
* ensure that waitForMemberDeparture correctly flushes the serial message queue for the given
* member
*/
@Test
public void testWaitForDeparture() throws Exception {
Properties config = new Properties();
config.put(LOCATORS, "");
config.put(START_LOCATOR, "localhost[" + this.locatorPort + "]");
config.put(DISABLE_TCP, "true");
InternalDistributedSystem system = (InternalDistributedSystem) DistributedSystem.connect(config);
// construct a member ID that will represent a departed member
InternalDistributedMember member = new InternalDistributedMember("localhost", 12345, "", "", NORMAL_DM_TYPE, null, null);
// schedule a message in order to create a queue for the fake member
DistributionManager distributionManager = (DistributionManager) system.getDistributionManager();
final FakeMessage message = new FakeMessage(null);
distributionManager.getExecutor(SERIAL_EXECUTOR, member).execute(new SizeableRunnable(100) {
@Override
public void run() {
// always throws NullPointerException
message.doAction(distributionManager, false);
}
@Override
public String toString() {
return "Processing fake message";
}
});
Assert.assertTrue("expected the serial queue to be flushed", distributionManager.getMembershipManager().waitForDeparture(member));
Assert.assertTrue(message.processed);
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class DistributedSystemDUnitTest method testMembershipPortRangeWithExactThreeValues.
@Test
public void testMembershipPortRangeWithExactThreeValues() throws Exception {
Properties config = new Properties();
config.setProperty(LOCATORS, "localhost[" + getDUnitLocatorPort() + "]");
config.setProperty(MEMBERSHIP_PORT_RANGE, this.lowerBoundOfPortRange + "-" + this.upperBoundOfPortRange);
InternalDistributedSystem system = getSystem(config);
Cache cache = CacheFactory.create(system);
cache.addCacheServer();
DistributionManager dm = (DistributionManager) system.getDistributionManager();
InternalDistributedMember member = dm.getDistributionManagerId();
GMSMembershipManager gms = (GMSMembershipManager) MembershipManagerHelper.getMembershipManager(system);
JGroupsMessenger messenger = (JGroupsMessenger) gms.getServices().getMessenger();
String jgConfig = messenger.getJGroupsStackConfig();
assertThat(jgConfig).as("expected to find port_range=\"2\" in " + jgConfig).contains("port_range=\"2\"");
verifyMembershipPortsInRange(member, this.lowerBoundOfPortRange, this.upperBoundOfPortRange);
}
use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.
the class DistributedLockServiceDUnitTest method testDestroyLockServiceBeforeGrantRequest.
@Test
public void testDestroyLockServiceBeforeGrantRequest() throws Throwable {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
final String serviceName = getUniqueName();
vm0.invoke(new SerializableRunnable("Create the grantor") {
public void run() {
connectDistributedSystem();
final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
// lock and unlock to make sure this vm is grantor
assertTrue(service.lock("obj", -1, -1));
service.unlock("obj");
}
});
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof DLockRequestMessage) {
DistributedLockService.destroy(serviceName);
}
}
});
connectDistributedSystem();
final DistributedLockService service = DistributedLockService.create(serviceName, dlstSystem);
try {
service.lock("obj", -1, -1);
fail("The lock service should have been destroyed");
} catch (LockServiceDestroyedException expected) {
// Do nothing
}
vm0.invoke(new SerializableRunnable("check to make sure the lock is not orphaned") {
public void run() {
final DistributedLockService service = DistributedLockService.getServiceNamed(serviceName);
// lock and unlock to make sure this vm is grantor
assertTrue(service.lock("obj", -1, -1));
service.unlock("obj");
}
});
}
Aggregations