use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class ShowMetricsDUnitTest method testShowMetricsRegionFromMember.
@Test
public void testShowMetricsRegionFromMember() throws ClassNotFoundException, IOException, InterruptedException {
systemSetUp();
Cache cache = getCache();
final DistributedMember distributedMember = cache.getDistributedSystem().getDistributedMember();
final String exportFileName = "regionOnAMemberReport.csv";
final String regionName = "REGION1";
SerializableCallable showMetricCmd = new SerializableCallable() {
@Override
public Object call() throws Exception {
WaitCriterion wc = createMBeanWaitCriterion(4, regionName, distributedMember, 0);
waitForCriterion(wc, 5000, 500, true);
CommandProcessor commandProcessor = new CommandProcessor();
Result result = commandProcessor.createCommandStatement("show metrics --region=" + regionName + " --member=" + distributedMember.getName() + " --file=" + exportFileName, 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);
}
use of org.apache.geode.distributed.DistributedMember 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.distributed.DistributedMember 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.distributed.DistributedMember in project geode by apache.
the class CommitFunction method execute.
public void execute(FunctionContext context) {
Cache cache = CacheFactory.getAnyInstance();
TXId txId = null;
try {
txId = (TXId) context.getArguments();
} catch (ClassCastException e) {
logger.info("CommitFunction should be invoked with a TransactionId as an argument i.e. setArguments(txId).execute(function)");
throw e;
}
DistributedMember member = txId.getMemberId();
Boolean result = false;
final boolean isDebugEnabled = logger.isDebugEnabled();
if (cache.getDistributedSystem().getDistributedMember().equals(member)) {
if (isDebugEnabled) {
logger.debug("CommitFunction: for transaction: {} committing locally", txId);
}
CacheTransactionManager txMgr = cache.getCacheTransactionManager();
if (txMgr.tryResume(txId)) {
if (isDebugEnabled) {
logger.debug("CommitFunction: resumed transaction: {}", txId);
}
txMgr.commit();
result = true;
}
} else {
ArrayList args = new ArrayList();
args.add(txId);
args.add(NestedTransactionFunction.COMMIT);
Execution ex = FunctionService.onMember(member).setArguments(args);
if (isDebugEnabled) {
logger.debug("CommitFunction: for transaction: {} executing NestedTransactionFunction on member: {}", txId, member);
}
try {
List list = (List) ex.execute(new NestedTransactionFunction()).getResult();
result = (Boolean) list.get(0);
} catch (FunctionException fe) {
if (fe.getCause() instanceof FunctionInvocationTargetException) {
throw new TransactionDataNodeHasDepartedException("Could not commit on member:" + member);
} else {
throw fe;
}
}
}
if (isDebugEnabled) {
logger.debug("CommitFunction: for transaction: {} returning result: {}", txId, result);
}
context.getResultSender().lastResult(result);
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class ClientServerTransactionDUnitTest method doTestFunctionFromPeer.
private void doTestFunctionFromPeer(final boolean commit) {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM peer1 = host.getVM(1);
VM peer2 = host.getVM(2);
createRegionOnServer(peer1);
createRegionOnServer(peer2);
createRegionOnServer(accessor, false, true);
final TransactionId txId = (TransactionId) peer1.invoke(new SerializableCallable() {
public Object call() throws Exception {
PartitionedRegion r = (PartitionedRegion) getCache().getRegion(CUSTOMER);
CustId cust = null;
DistributedMember myId = getCache().getDistributedSystem().getDistributedMember();
List<CustId> keys = new ArrayList<CustId>();
for (int i = 0; i < 10; i++) {
cust = new CustId(i);
int bucketId = PartitionedRegionHelper.getHashKey(r, cust);
if (!myId.equals(r.getBucketPrimary(bucketId))) {
keys.add(cust);
}
}
assertTrue(keys.size() > 2);
CacheTransactionManager mgr = getCache().getCacheTransactionManager();
mgr.begin();
for (CustId custId : keys) {
r.put(cust, new Customer("newname", "newaddress"));
}
return mgr.suspend();
}
});
assertNotNull(txId);
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
Execution exe = FunctionService.onMember(((TXId) txId).getMemberId()).setArguments(txId);
List list = null;
if (commit) {
list = (List) exe.execute(new CommitFunction()).getResult();
} else {
list = (List) exe.execute(new RollbackFunction()).getResult();
}
assertEquals(1, list.size());
assertTrue((Boolean) list.get(0));
return null;
}
});
}
Aggregations