use of org.apache.geode.distributed.internal.deadlock.GemFireDeadlockDetector in project geode by apache.
the class ShowDeadlockDUnitTest method testNoDeadlock.
@Test
public void testNoDeadlock() throws Exception {
GemFireDeadlockDetector detect = new GemFireDeadlockDetector();
assertEquals(null, detect.find().findCycle());
File outputFile = new File(temporaryFolder.getRoot(), "dependency.txt");
String showDeadlockCommand = new CommandStringBuilder(CliStrings.SHOW_DEADLOCK).addOption(CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE, outputFile.getName()).toString();
Result result = new CommandProcessor().createCommandStatement(showDeadlockCommand, Collections.emptyMap()).process();
String commandOutput = getResultAsString(result);
assertEquals(true, result.hasIncomingFiles());
assertEquals(true, result.getStatus().equals(Status.OK));
assertEquals(true, commandOutput.startsWith(CliStrings.SHOW_DEADLOCK__NO__DEADLOCK));
result.saveIncomingFiles(temporaryFolder.getRoot().getAbsolutePath());
assertTrue(outputFile.exists());
}
use of org.apache.geode.distributed.internal.deadlock.GemFireDeadlockDetector in project geode by apache.
the class MiscellaneousCommands method showDeadlock.
@CliCommand(value = CliStrings.SHOW_DEADLOCK, help = CliStrings.SHOW_DEADLOCK__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_DEBUG_UTIL })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result showDeadlock(@CliOption(key = CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE, help = CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE__HELP, mandatory = true) String filename) {
Result result = null;
try {
if (!filename.endsWith(".txt")) {
return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.INVALID_FILE_EXTENSION, ".txt"));
}
InternalCache cache = getCache();
Set<DistributedMember> allMembers = CliUtil.getAllMembers(cache);
GemFireDeadlockDetector gfeDeadLockDetector = new GemFireDeadlockDetector(allMembers);
DependencyGraph dependencyGraph = gfeDeadLockDetector.find();
Collection<Dependency> deadlock = dependencyGraph.findCycle();
DependencyGraph deepest = null;
if (deadlock == null) {
deepest = dependencyGraph.findLongestCallChain();
if (deepest != null) {
deadlock = deepest.getEdges();
}
}
Set<Dependency> dependencies = (Set<Dependency>) dependencyGraph.getEdges();
InfoResultData resultData = ResultBuilder.createInfoResultData();
if (deadlock != null) {
if (deepest != null) {
resultData.addLine(CliStrings.SHOW_DEADLOCK__DEEPEST_FOUND);
} else {
resultData.addLine(CliStrings.SHOW_DEADLOCK__DEADLOCK__DETECTED);
}
resultData.addLine(DeadlockDetector.prettyFormat(deadlock));
} else {
resultData.addLine(CliStrings.SHOW_DEADLOCK__NO__DEADLOCK);
}
resultData.addAsFile(filename, DeadlockDetector.prettyFormat(dependencies), MessageFormat.format(CliStrings.SHOW_DEADLOCK__DEPENDENCIES__REVIEW, filename), false);
result = ResultBuilder.buildResult(resultData);
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.SHOW_DEADLOCK__ERROR + " : " + e.getMessage());
}
return result;
}
Aggregations