use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.
the class JGroupsMessengerJUnitTest method testJChannelError.
@Test
public void testJChannelError() throws Exception {
for (int i = 0; i < 2; i++) {
boolean enableMcast = (i == 1);
initMocks(enableMcast);
JChannel mockChannel = mock(JChannel.class);
when(mockChannel.isConnected()).thenReturn(true);
doThrow(new RuntimeException()).when(mockChannel).send(any(Message.class));
JChannel realChannel = messenger.myChannel;
messenger.myChannel = mockChannel;
try {
InternalDistributedMember mbr = createAddress(8888);
DistributedCacheOperation.CacheOperationMessage msg = mock(DistributedCacheOperation.CacheOperationMessage.class);
when(msg.getRecipients()).thenReturn(new InternalDistributedMember[] { mbr });
when(msg.getMulticast()).thenReturn(enableMcast);
when(msg.getProcessorId()).thenReturn(1234);
when(msg.getDSFID()).thenReturn((int) DataSerializableFixedID.PUT_ALL_MESSAGE);
try {
messenger.send(msg);
fail("expected a failure");
} catch (DistributedSystemDisconnectedException e) {
// success
}
verify(mockChannel).send(isA(Message.class));
} finally {
messenger.myChannel = realChannel;
}
}
}
use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.
the class DiskStoreCommandsDUnitTest method testMissingDiskStore.
// GEODE-2102
@Category(FlakyTest.class)
@Test
public void testMissingDiskStore() {
final String regionName = "testShowMissingDiskStoreRegion";
setUpJmxManagerOnVm0ThenConnect(null);
final VM vm0 = Host.getHost(0).getVM(0);
final VM vm1 = Host.getHost(0).getVM(1);
final String vm1Name = "VM" + vm1.getPid();
final String diskStoreName = "DiskStoreCommandsDUnitTest";
// Default setup creates a cache in the Manager, now create a cache in VM1
vm1.invoke(new SerializableRunnable() {
public void run() {
Properties localProps = new Properties();
localProps.setProperty(NAME, vm1Name);
getSystem(localProps);
Cache cache = getCache();
}
});
// Create a disk store and region in the Manager (VM0) and VM1 VMs
for (final VM vm : (new VM[] { vm0, vm1 })) {
final String vmName = "VM" + vm.getPid();
vm.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
File diskStoreDirFile = new File(diskStoreName + vm.getPid());
diskStoreDirFile.mkdirs();
DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
diskStoreFactory.setDiskDirs(new File[] { diskStoreDirFile });
diskStoreFactory.setMaxOplogSize(1);
diskStoreFactory.setAllowForceCompaction(true);
diskStoreFactory.setAutoCompact(false);
diskStoreFactory.create(regionName);
RegionFactory regionFactory = cache.createRegionFactory();
regionFactory.setDiskStoreName(regionName);
regionFactory.setDiskSynchronous(true);
regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
regionFactory.setScope(Scope.DISTRIBUTED_ACK);
regionFactory.create(regionName);
}
});
}
// Add data to the region
vm0.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(regionName);
region.put("A", "B");
}
});
// Make sure that everything thus far is okay and there are no missing disk stores
CommandResult cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
assertTrue(commandResultToString(cmdResult).contains("No missing disk store found"));
// Close the region in the Manager (VM0) VM
vm0.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(regionName);
region.close();
}
});
// Add data to VM1 and then close the region
vm1.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(regionName);
region.put("A", "C");
region.close();
}
});
// Add the region back to the Manager (VM0) VM
vm0.invokeAsync(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
RegionFactory regionFactory = cache.createRegionFactory();
regionFactory.setDiskStoreName(regionName);
regionFactory.setDiskSynchronous(true);
regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
regionFactory.setScope(Scope.DISTRIBUTED_ACK);
try {
regionFactory.create(regionName);
} catch (DistributedSystemDisconnectedException ignore) {
// okay to ignore
}
}
});
// Wait for the region in the Manager (VM0) to come online
vm0.invoke(new SerializableRunnable() {
public void run() {
WaitCriterion waitCriterion = new WaitCriterion() {
public boolean done() {
Cache cache = getCache();
PersistentMemberManager memberManager = ((InternalCache) cache).getPersistentMemberManager();
return !memberManager.getWaitingRegions().isEmpty();
}
public String description() {
return "Waiting for another persistent member to come online";
}
};
waitForCriterion(waitCriterion, 70000, 100, true);
}
});
// Validate that there is a missing disk store on VM1
cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
System.out.println("command result=" + stringResult);
assertEquals(5, countLinesInString(stringResult, false));
assertTrue(stringContainsLine(stringResult, "Disk Store ID.*Host.*Directory"));
assertTrue(stringContainsLine(stringResult, ".*" + diskStoreName + vm1.getPid()));
// Extract the id from the returned missing disk store
String line = getLineFromString(stringResult, 4);
assertFalse(line.contains("---------"));
StringTokenizer resultTokenizer = new StringTokenizer(line);
String id = resultTokenizer.nextToken();
// Remove the missing disk store and validate the result
cmdResult = executeCommand("revoke missing-disk-store --id=" + id);
assertNotNull(cmdResult);
assertEquals(Result.Status.OK, cmdResult.getStatus());
assertTrue(commandResultToString(cmdResult).contains("Missing disk store successfully revoked"));
// Do our own cleanup so that the disk store directories can be removed
super.destroyDefaultSetup();
for (final VM vm : (new VM[] { vm0, vm1 })) {
final String vmName = "VM" + vm.getPid();
vm.invoke(new SerializableRunnable() {
public void run() {
try {
FileUtils.deleteDirectory((new File(diskStoreName + vm.getPid())));
} catch (IOException iex) {
// There's nothing else we can do
}
}
});
}
}
use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testFinishIncompleteInitializationNoSend.
@Test
public void testFinishIncompleteInitializationNoSend() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// Add a hook which will disconnect the DS before sending a prepare message
vm1.invoke(new SerializableRunnable() {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof PrepareNewPersistentMemberMessage) {
DistributionMessageObserver.setInstance(null);
getSystem().disconnect();
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
}
});
}
});
createPersistentRegion(vm0);
putAnEntry(vm0);
updateTheEntry(vm0);
try {
createPersistentRegion(vm1);
} catch (Exception e) {
if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
throw e;
}
}
closeRegion(vm0);
// This wait for VM0 to come back
AsyncInvocation async1 = createPersistentRegionAsync(vm1);
waitForBlockedInitialization(vm1);
createPersistentRegion(vm0);
async1.getResult();
checkForEntry(vm1);
vm0.invoke(new SerializableRunnable("check for offline members") {
public void run() {
Cache cache = getCache();
DistributedRegion region = (DistributedRegion) cache.getRegion(REGION_NAME);
PersistentMembershipView view = region.getPersistenceAdvisor().getMembershipView();
DiskRegion dr = region.getDiskRegion();
assertEquals(Collections.emptySet(), dr.getOfflineMembers());
assertEquals(1, dr.getOnlineMembers().size());
}
});
}
use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.
the class FunctionStreamingReplyMessage method toData.
@Override
public void toData(DataOutput out) throws IOException {
super.toData(out);
out.writeInt(this.msgNum);
out.writeBoolean(this.lastMsg);
out.writeInt(this.processorId);
// soubhik. fix for ticket 40670
try {
DataSerializer.writeObject(this.result, out);
} catch (Exception ex) {
if (ex instanceof CancelException) {
throw new DistributedSystemDisconnectedException(ex);
}
NotSerializableException ioEx = new NotSerializableException(this.result.getClass().getName());
ioEx.initCause(ex);
throw ioEx;
}
}
use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.
the class GlobalTransaction method getId.
/**
* Read current {@link #DMid} and return it
*
* @return current DMid
*/
private static String getId() {
synchronized (DmidMutex) {
InternalDistributedSystem ids = InternalDistributedSystem.getAnyInstance();
if (ids == null) {
throw new DistributedSystemDisconnectedException("No distributed system");
}
if (ids == IdsForId) {
return DMid;
}
IdsForId = ids;
DM dm = ids.getDistributionManager();
DMid = dm.getId().toString();
return DMid;
}
}
Aggregations