use of org.apache.geode.cache.Cache in project geode by apache.
the class ListIndexFunctionJUnitTest method testExecuteThrowsException.
@Test(expected = RuntimeException.class)
public void testExecuteThrowsException() throws Throwable {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
final DistributedMember mockDistributedMember = mockContext.mock(DistributedMember.class, "DistributedMember");
final QueryService mockQueryService = mockContext.mock(QueryService.class, "QueryService");
final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getDistributedSystem();
will(returnValue(mockDistributedSystem));
oneOf(mockCache).getQueryService();
will(returnValue(mockQueryService));
oneOf(mockDistributedSystem).getDistributedMember();
will(returnValue(mockDistributedMember));
oneOf(mockQueryService).getIndexes();
will(throwException(new RuntimeException("expected")));
oneOf(mockFunctionContext).getResultSender();
will(returnValue(testResultSender));
}
});
final ListIndexFunction function = createListIndexFunction(mockCache);
function.execute(mockFunctionContext);
try {
testResultSender.getResults();
} catch (Throwable t) {
assertTrue(t instanceof RuntimeException);
assertEquals("expected", t.getMessage());
throw t;
}
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class ExportLogsFunctionIntegrationTest method exportLogsFunctionDoesNotBlowUp.
@Test
public void exportLogsFunctionDoesNotBlowUp() throws Throwable {
File logFile1 = new File(serverWorkingDir, "server1.log");
FileUtils.writeStringToFile(logFile1, "some log for server1 \n some other log line");
File logFile2 = new File(serverWorkingDir, "server2.log");
FileUtils.writeStringToFile(logFile2, "some log for server2 \n some other log line");
File notALogFile = new File(serverWorkingDir, "foo.txt");
FileUtils.writeStringToFile(notALogFile, "some text");
verifyExportLogsFunctionDoesNotBlowUp();
Cache cache = GemFireCacheImpl.getInstance();
assertThat(cache.getRegion(ExportLogsFunction.EXPORT_LOGS_REGION)).isEmpty();
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class ShowMetricsDUnitTest method testShowMetricsDefault.
/**
* tests the default version of "show metrics"
*/
@Test
public void testShowMetricsDefault() {
setUpJmxManagerOnVm0ThenConnect(null);
createLocalSetUp();
final VM vm1 = Host.getHost(0).getVM(1);
final String vm1Name = "VM" + vm1.getPid();
vm1.invoke(new SerializableRunnable() {
public void run() {
Properties localProps = new Properties();
localProps.setProperty(NAME, vm1Name);
getSystem(localProps);
Cache cache = getCache();
RegionFactory<Integer, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE);
Region region = dataRegionFactory.create("REGION1");
}
});
SerializableCallable showMetricCmd = new SerializableCallable() {
@Override
public Object call() throws Exception {
WaitCriterion wc = createMBeanWaitCriterion(1, "", null, 0);
waitForCriterion(wc, 5000, 500, true);
CommandProcessor commandProcessor = new CommandProcessor();
Result result = commandProcessor.createCommandStatement("show metrics", Collections.EMPTY_MAP).process();
String resultStr = commandResultToString((CommandResult) result);
getLogWriter().info(resultStr);
assertEquals(resultStr, true, result.getStatus().equals(Status.OK));
return resultStr;
}
};
// Invoke the command in the Manager VM
final VM managerVm = Host.getHost(0).getVM(0);
Object managerResultObj = managerVm.invoke(showMetricCmd);
String managerResult = (String) managerResultObj;
getLogWriter().info("#SB Manager");
getLogWriter().info(managerResult);
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class ShowMetricsDUnitTest method testShowMetricsMember.
// GEODE-1764
@Category(FlakyTest.class)
@Test
public void testShowMetricsMember() throws ClassNotFoundException, IOException, InterruptedException {
systemSetUp();
Cache cache = getCache();
final DistributedMember distributedMember = cache.getDistributedSystem().getDistributedMember();
final String exportFileName = "memberMetricReport.csv";
int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(1);
CacheServer cs = getCache().addCacheServer();
cs.setPort(ports[0]);
cs.start();
final int cacheServerPort = cs.getPort();
SerializableCallable showMetricCmd = new SerializableCallable() {
@Override
public Object call() throws Exception {
WaitCriterion wc = createMBeanWaitCriterion(3, "", distributedMember, 0);
waitForCriterion(wc, 5000, 500, true);
wc = createMBeanWaitCriterion(5, "", distributedMember, cacheServerPort);
waitForCriterion(wc, 10000, 500, true);
final String command = CliStrings.SHOW_METRICS + " --" + CliStrings.SHOW_METRICS__MEMBER + "=" + distributedMember.getId() + " --" + CliStrings.SHOW_METRICS__CACHESERVER__PORT + "=" + cacheServerPort + " --" + CliStrings.SHOW_METRICS__FILE + "=" + exportFileName;
CommandProcessor commandProcessor = new CommandProcessor();
Result result = commandProcessor.createCommandStatement(command, Collections.EMPTY_MAP).process();
String resultAsString = commandResultToString((CommandResult) result);
assertEquals(resultAsString, true, result.getStatus().equals(Status.OK));
assertTrue(result.hasIncomingFiles());
result.saveIncomingFiles(null);
File file = new File(exportFileName);
file.deleteOnExit();
assertTrue(file.exists());
file.delete();
return resultAsString;
}
};
// Invoke the command in the Manager VM
final VM managerVm = Host.getHost(0).getVM(0);
Object managerResultObj = managerVm.invoke(showMetricCmd);
String managerResult = (String) managerResultObj;
getLogWriter().info("#SB Manager");
getLogWriter().info(managerResult);
cs.stop();
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class CacheXmlGeode10DUnitTest method testEnableOffHeapMemory.
@SuppressWarnings("rawtypes")
@Test
public void testEnableOffHeapMemory() throws Exception {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + OFF_HEAP_MEMORY_SIZE, "1m");
final String regionName = "testEnableOffHeapMemory";
final CacheCreation cache = new CacheCreation();
final RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setOffHeap(true);
assertEquals(true, attrs.getOffHeap());
final Region regionBefore = cache.createRegion(regionName, attrs);
assertNotNull(regionBefore);
assertEquals(true, regionBefore.getAttributes().getOffHeap());
testXml(cache);
final Cache c = getCache();
assertNotNull(c);
final Region regionAfter = c.getRegion(regionName);
assertNotNull(regionAfter);
assertEquals(true, regionAfter.getAttributes().getOffHeap());
assertEquals(true, ((RegionEntryContext) regionAfter).getOffHeap());
regionAfter.localDestroyRegion();
}
Aggregations