use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class MemberCommands method describeMember.
@CliCommand(value = { CliStrings.DESCRIBE_MEMBER }, help = CliStrings.DESCRIBE_MEMBER__HELP)
@CliMetaData(shellOnly = false, relatedTopic = CliStrings.TOPIC_GEODE_SERVER)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeMember(@CliOption(key = CliStrings.DESCRIBE_MEMBER__IDENTIFIER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.DESCRIBE_MEMBER__HELP, mandatory = true) String memberNameOrId) {
Result result = null;
try {
DistributedMember memberToBeDescribed = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
if (memberToBeDescribed != null) {
// This information should be available through the MBeans too. We might not need
// the function.
// Yes, but then the command is subject to Mbean availability, which would be
// affected once MBean filters are used.
ResultCollector<?, ?> rc = CliUtil.executeFunction(getMemberInformation, null, memberToBeDescribed);
ArrayList<?> output = (ArrayList<?>) rc.getResult();
Object obj = output.get(0);
if (obj != null && (obj instanceof MemberInformation)) {
CompositeResultData crd = ResultBuilder.createCompositeResultData();
MemberInformation memberInformation = (MemberInformation) obj;
memberInformation.setName(memberToBeDescribed.getName());
memberInformation.setId(memberToBeDescribed.getId());
memberInformation.setHost(memberToBeDescribed.getHost());
memberInformation.setProcessId("" + memberToBeDescribed.getProcessId());
SectionResultData section = crd.addSection();
section.addData("Name", memberInformation.getName());
section.addData("Id", memberInformation.getId());
section.addData("Host", memberInformation.getHost());
section.addData("Regions", CliUtil.convertStringSetToString(memberInformation.getHostedRegions(), '\n'));
section.addData("PID", memberInformation.getProcessId());
section.addData("Groups", memberInformation.getGroups());
section.addData("Used Heap", memberInformation.getHeapUsage() + "M");
section.addData("Max Heap", memberInformation.getMaxHeapSize() + "M");
String offHeapMemorySize = memberInformation.getOffHeapMemorySize();
if (offHeapMemorySize != null && !offHeapMemorySize.isEmpty()) {
section.addData("Off Heap Size", offHeapMemorySize);
}
section.addData("Working Dir", memberInformation.getWorkingDirPath());
section.addData("Log file", memberInformation.getLogFilePath());
section.addData("Locators", memberInformation.getLocators());
if (memberInformation.isServer()) {
SectionResultData clientServiceSection = crd.addSection();
List<CacheServerInfo> csList = memberInformation.getCacheServeInfo();
if (csList != null) {
Iterator<CacheServerInfo> iters = csList.iterator();
clientServiceSection.setHeader("Cache Server Information");
while (iters.hasNext()) {
CacheServerInfo cacheServerInfo = iters.next();
clientServiceSection.addData("Server Bind", cacheServerInfo.getBindAddress());
clientServiceSection.addData("Server Port", cacheServerInfo.getPort());
clientServiceSection.addData("Running", cacheServerInfo.isRunning());
}
clientServiceSection.addData("Client Connections", memberInformation.getClientCount());
}
}
result = ResultBuilder.buildResult(crd);
} else {
result = ResultBuilder.createInfoResult(CliStrings.format(CliStrings.DESCRIBE_MEMBER__MSG__INFO_FOR__0__COULD_NOT_BE_RETRIEVED, new Object[] { memberNameOrId }));
}
} else {
result = ResultBuilder.createInfoResult(CliStrings.format(CliStrings.DESCRIBE_MEMBER__MSG__NOT_FOUND, new Object[] { memberNameOrId }));
}
} catch (CacheClosedException e) {
} catch (FunctionInvocationTargetException e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class MemoryBlockNodeJUnitTest method getDataValueCatchesCacheClosedException.
@Test
public void getDataValueCatchesCacheClosedException() {
Object obj = getValue();
storedObject = createValueAsSerializedStoredObject(obj);
OffHeapStoredObject spyStoredObject = spy((OffHeapStoredObject) storedObject);
doReturn("java.lang.Long").when(spyStoredObject).getDataType();
doThrow(new CacheClosedException("Unit test forced exception")).when(spyStoredObject).getRawBytes();
ByteArrayOutputStream errContent = new ByteArrayOutputStream();
System.setErr(new PrintStream(errContent));
MemoryBlock mb = new MemoryBlockNode(ma, spyStoredObject);
softly.assertThat(mb.getDataValue()).isEqualTo("CacheClosedException:Unit test forced exception");
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class SingleHopStatsDUnitTest method closeCacheAndDisconnect.
private void closeCacheAndDisconnect() {
try {
Cache cache = CacheFactory.getAnyInstance();
if (cache != null && !cache.isClosed()) {
cache.close();
cache.getDistributedSystem().disconnect();
}
} catch (CacheClosedException e) {
}
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class OnGroupsFunctionExecutionDUnitTest method testStreamingClientServerFunction.
@Test
public void testStreamingClientServerFunction() {
Host host = Host.getHost(0);
VM server0 = host.getVM(0);
VM server1 = host.getVM(1);
VM server2 = host.getVM(2);
VM client = host.getVM(3);
VM locator = Host.getLocator();
final String regionName = getName();
initVM(server0, "mg,g0", regionName, true);
initVM(server1, "g1", regionName, true);
initVM(server2, "g0,g1", regionName, true);
final int locatorPort = getLocatorPort(locator);
final String hostName = host.getHostName();
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
try {
Cache c = CacheFactory.getAnyInstance();
c.close();
} catch (CacheClosedException cce) {
}
disconnectFromDS();
LogWriterUtils.getLogWriter().fine("SWAP:creating client cache");
ClientCacheFactory ccf = new ClientCacheFactory();
ccf.addPoolLocator(hostName, locatorPort);
ccf.setPoolServerGroup("mg");
ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
ClientCache c = ccf.create();
c.getLogger().info("SWAP:invoking function from client on g0");
Execution e = InternalFunctionService.onServers(c, "g0");
ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
int sum = 0;
for (int i = 0; i < l.size(); i++) {
sum += l.get(i);
}
assertEquals(10, sum);
return null;
}
});
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
ClientCache c = ClientCacheFactory.getAnyInstance();
c.getLogger().fine("SWAP:invoking function from client on mg");
Execution e = InternalFunctionService.onServers(c, "mg");
ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
int sum = 0;
for (int i = 0; i < l.size(); i++) {
sum += l.get(i);
}
assertEquals(5, sum);
return null;
}
});
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
ClientCache c = ClientCacheFactory.getAnyInstance();
c.getLogger().fine("SWAP:invoking function from client on g0 g1");
Execution e = InternalFunctionService.onServers(c, "g0", "g1");
ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
int sum = 0;
for (int i = 0; i < l.size(); i++) {
sum += l.get(i);
}
assertEquals(15, sum);
return null;
}
});
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class OnGroupsFunctionExecutionDUnitTest method testOnServer.
@Test
public void testOnServer() {
Host host = Host.getHost(0);
VM server0 = host.getVM(0);
VM server1 = host.getVM(1);
VM server2 = host.getVM(2);
VM client = host.getVM(3);
VM locator = Host.getLocator();
final String regionName = getName();
initVM(server0, "mg,g0", regionName, true);
initVM(server1, "g1", regionName, true);
initVM(server2, "g0,g1,g2", regionName, true);
final int locatorPort = getLocatorPort(locator);
final String hostName = host.getHostName();
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
try {
Cache c = CacheFactory.getAnyInstance();
c.close();
} catch (CacheClosedException cce) {
}
disconnectFromDS();
LogWriterUtils.getLogWriter().fine("SWAP:creating client cache");
ClientCacheFactory ccf = new ClientCacheFactory();
ccf.addPoolLocator(hostName, locatorPort);
ccf.setPoolServerGroup("mg");
ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
ClientCache c = ccf.create();
IgnoredException ex = IgnoredException.addIgnoredException("No member found");
try {
InternalFunctionService.onServer(c, "no such group").execute(new OnGroupsFunction()).getResult();
fail("expected exception not thrown");
} catch (FunctionException e) {
} finally {
ex.remove();
}
InternalFunctionService.onServer(c, "g1").execute(new OnGroupsFunction()).getResult();
return null;
}
});
int c0 = getAndResetInvocationCount(server0);
int c1 = getAndResetInvocationCount(server1);
int c2 = getAndResetInvocationCount(server2);
assertEquals(1, c0 + c1 + c2);
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
ClientCache c = ClientCacheFactory.getAnyInstance();
InternalFunctionService.onServer(c, "g0").execute(new OnGroupsFunction()).getResult();
return null;
}
});
verifyAndResetInvocationCount(server0, 1);
verifyAndResetInvocationCount(server1, 0);
verifyAndResetInvocationCount(server2, 0);
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
ClientCache c = ClientCacheFactory.getAnyInstance();
InternalFunctionService.onServer(c, "mg", "g1").execute(new OnGroupsFunction()).getResult();
return null;
}
});
c0 = getAndResetInvocationCount(server0);
c1 = getAndResetInvocationCount(server1);
c2 = getAndResetInvocationCount(server2);
assertEquals(2, c0 + c1 + c2);
}
Aggregations