use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class DiskStoreCommandsJUnitTest method testGetDiskStoreListThrowsRuntimeException.
@Test(expected = RuntimeException.class)
public void testGetDiskStoreListThrowsRuntimeException() {
final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
final DistributedMember mockDistributedMember = mockContext.mock(DistributedMember.class, "DistributedMember");
final Execution mockFunctionExecutor = mockContext.mock(Execution.class, "Function Executor");
mockContext.checking(new Expectations() {
{
oneOf(mockFunctionExecutor).execute(with(aNonNull(ListDiskStoresFunction.class)));
will(throwException(new RuntimeException("expected")));
}
});
final DiskStoreCommands commands = createDiskStoreCommands(mockCache, mockDistributedMember, mockFunctionExecutor);
try {
commands.getDiskStoreListing(commands.getNormalMembers(mockCache));
} catch (RuntimeException expected) {
assertEquals("expected", expected.getMessage());
throw expected;
}
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class DiskStoreCommandsJUnitTest method testGetDiskStoreListReturnsFunctionInvocationTargetExceptionInResults.
@Test
public void testGetDiskStoreListReturnsFunctionInvocationTargetExceptionInResults() {
final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
final DistributedMember mockDistributedMember = mockContext.mock(DistributedMember.class, "DistributedMember");
final AbstractExecution mockFunctionExecutor = mockContext.mock(AbstractExecution.class, "Function Executor");
final ResultCollector mockResultCollector = mockContext.mock(ResultCollector.class, "ResultCollector");
final DiskStoreDetails diskStoreDetails = createDiskStoreDetails("memberOne", "cacheServerDiskStore");
final List<DiskStoreDetails> expectedDiskStores = Arrays.asList(diskStoreDetails);
final List<Object> results = new ArrayList<Object>();
results.add(CollectionUtils.asSet(diskStoreDetails));
results.add(new FunctionInvocationTargetException("expected"));
mockContext.checking(new Expectations() {
{
oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
oneOf(mockFunctionExecutor).execute(with(aNonNull(ListDiskStoresFunction.class)));
will(returnValue(mockResultCollector));
oneOf(mockResultCollector).getResult();
will(returnValue(results));
}
});
final DiskStoreCommands commands = createDiskStoreCommands(mockCache, mockDistributedMember, mockFunctionExecutor);
final List<DiskStoreDetails> actualDiskStores = commands.getDiskStoreListing(commands.getNormalMembers(mockCache));
Assert.assertNotNull(actualDiskStores);
assertEquals(expectedDiskStores, actualDiskStores);
}
use of org.apache.geode.internal.cache.InternalCache 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.internal.cache.InternalCache in project geode by apache.
the class GemfireDataCommandsDUnitTest method testRegionsViaMbeanAndFunctionsForPartRgn.
@Test
public void testRegionsViaMbeanAndFunctionsForPartRgn() {
setupWith2Regions();
waitForListClientMbean(REBALANCE_REGION_NAME);
final VM manager = Host.getHost(0).getVM(0);
String memSizeFromMbean = (String) manager.invoke(new SerializableCallable() {
public Object call() {
Cache cache = GemFireCacheImpl.getInstance();
DistributedRegionMXBean bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean(REBALANCE_REGION_NAME);
if (bean == null) {
bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean(Region.SEPARATOR + REBALANCE_REGION_NAME);
}
if (bean == null) {
return null;
}
String[] membersName = bean.getMembers();
return "" + membersName.length;
}
});
getLogWriter().info("testRegionsViaMbeanAndFunctionsForPartRgn memSizeFromMbean= " + memSizeFromMbean);
String memSizeFromFunctionCall = (String) manager.invoke(new SerializableCallable() {
public Object call() {
InternalCache cache = GemFireCacheImpl.getInstance();
return "" + CliUtil.getMembersForeRegionViaFunction(cache, REBALANCE_REGION_NAME, true).size();
}
});
getLogWriter().info("testRegionsViaMbeanAndFunctionsForPartRgn memSizeFromFunctionCall= " + memSizeFromFunctionCall);
assertTrue(memSizeFromFunctionCall.equals(memSizeFromMbean));
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class GfshCommandJUnitTest method testGetMemberWithMatchingMemberId.
@Test
public void testGetMemberWithMatchingMemberId() {
final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
final DistributedMember mockMemberSelf = createMockMember("S", "Self");
final DistributedMember mockMemberOne = createMockMember("1", "One");
final DistributedMember mockMemberTwo = createMockMember("2", "Two");
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getMembers();
will(returnValue(CollectionUtils.asSet(mockMemberOne, mockMemberTwo)));
oneOf(mockCache).getDistributedSystem();
will(returnValue(mockDistributedSystem));
oneOf(mockDistributedSystem).getDistributedMember();
will(returnValue(mockMemberSelf));
}
});
final GfshCommand commands = createAbstractCommandsSupport(mockCache);
assertSame(mockMemberTwo, commands.getMember(mockCache, "2"));
}
Aggregations