use of com.sun.tools.attach.spi.AttachProvider in project openj9 by eclipse.
the class TestAttachAPI method test_vmname05.
@Test
public void test_vmname05() {
final int NUM_TARGETS = 3;
logger.debug("starting " + testName);
listIpcDir();
TargetManager.setLogging(true);
TargetManager mainTarget = launchTarget();
TargetManager otherTarget = launchTarget();
VirtualMachine[] mainVms = new VirtualMachine[NUM_TARGETS], otherVms = new VirtualMachine[NUM_TARGETS];
VirtualMachineDescriptor vmd = null;
VirtualMachineDescriptor otherVmd = null;
try {
List<AttachProvider> providers = com.sun.tools.attach.spi.AttachProvider.providers();
AttachProvider myProvider = providers.get(0);
List<VirtualMachineDescriptor> vmdList = myProvider.listVirtualMachines();
listIpcDir();
if (vmdList.size() < 2) {
fail("ERROR " + testName + ": no target VMs found");
}
for (int i = 0; i < NUM_TARGETS; ++i) {
String pid = mainTarget.getTargetPid();
logger.debug("connecting to " + pid);
mainVms[i] = VirtualMachine.attach(pid);
}
for (int i = 0; i < NUM_TARGETS; ++i) {
String pid = otherTarget.getTargetPid();
logger.debug("connecting to " + pid);
otherVms[i] = VirtualMachine.attach(pid);
}
for (int i = 0; i < NUM_TARGETS; ++i) {
if (!mainVms[0].equals(mainVms[i])) {
logger.error("mainVms[0]=" + mainVms[0].id() + " mainVms[" + i + "]" + mainVms[i].id());
fail("VirtualMachine equals for same VM");
}
if (!otherVms[0].equals(otherVms[i])) {
logger.error("otherVms[0]=" + otherVms[0].id() + "otherVms[i]" + otherVms[i].id());
fail("VirtualMachine equals for same VM");
}
}
for (int i = 0; i < NUM_TARGETS; ++i) {
AssertJUnit.assertFalse("VirtualMachine unequal for other VM", mainVms[0].equals(otherVms[i]));
}
} catch (AttachNotSupportedException e) {
if ((null != vmd) && (null != otherVmd)) {
logger.error("Trying to attach " + vmd.id() + " " + vmd.displayName() + " or " + otherVmd.id() + " " + otherVmd.displayName());
}
listIpcDir();
logExceptionInfoAndFail(e);
} catch (IOException e) {
logExceptionInfoAndFail(e);
} finally {
try {
for (int i = 0; i < NUM_TARGETS; ++i) {
if (null != mainVms[i]) {
mainVms[i].detach();
}
}
for (int i = 0; i < NUM_TARGETS; ++i) {
if (null != otherVms[i]) {
otherVms[i].detach();
}
}
String errOutput = mainTarget.getErrOutput();
String outOutput = mainTarget.getOutOutput();
logger.debug(outOutput);
logger.debug(errOutput);
errOutput = otherTarget.getErrOutput();
outOutput = otherTarget.getOutOutput();
logger.debug(outOutput);
logger.debug(errOutput);
mainTarget.terminateTarget();
otherTarget.terminateTarget();
errOutput = mainTarget.getErrOutput();
outOutput = mainTarget.getOutOutput();
logger.debug(outOutput);
logger.debug(errOutput);
errOutput = otherTarget.getErrOutput();
outOutput = otherTarget.getOutOutput();
logger.debug(outOutput);
} catch (IOException e) {
logExceptionInfoAndFail(e);
}
}
}
use of com.sun.tools.attach.spi.AttachProvider in project openj9 by eclipse.
the class TestAttachAPI method test_attach04.
@Test
public void test_attach04() {
logger.debug("starting " + testName);
TargetManager target = launchTarget();
VirtualMachine vm = null;
VirtualMachineDescriptor vmd = null;
try {
List<AttachProvider> providers = com.sun.tools.attach.spi.AttachProvider.providers();
AttachProvider myProvider = providers.get(0);
vmd = findVmdForPid(myProvider, target.getTargetPid());
try {
vm = VirtualMachine.attach(vmd);
} catch (IOException e) {
logExceptionInfoAndFail(e);
}
if (null == vm) {
fail("VirtualMachine.attach returned null");
}
String vmToString = vm.toString();
String vmdToString = vmd.toString();
logger.debug(testName + ": vm.toString()=" + vmToString);
logger.debug(testName + ": vmd.toString()=" + vmdToString);
String vmdId = vmd.id();
assertTrue(vmdToString.contains(vmdId));
} catch (AttachNotSupportedException e) {
listIpcDir();
logExceptionInfoAndFail(e);
} finally {
if (null != vm) {
try {
vm.detach();
} catch (IOException e) {
logExceptionInfoAndFail(e);
}
}
target.terminateTarget();
}
}
use of com.sun.tools.attach.spi.AttachProvider in project openj9 by eclipse.
the class ListVms method listVms.
private static void listVms() {
List<AttachProvider> providers = AttachProvider.providers();
AttachProvider ap = providers.get(0);
if (null == ap) {
System.err.println("no attach providers available");
}
@SuppressWarnings("null") List<VirtualMachineDescriptor> vmds = ap.listVirtualMachines();
System.out.println("looking for attach targets");
for (VirtualMachineDescriptor vmd : vmds) {
System.out.println("id: " + vmd.id() + " name: " + vmd.displayName());
}
System.out.println(LIST_VMS_EXIT);
System.out.flush();
System.out.close();
System.err.close();
}
use of com.sun.tools.attach.spi.AttachProvider in project openj9 by eclipse.
the class TestAttachAPI method test_vmname03.
/**
* @testcase vmname03
* @procedure start a process without displayName specified
* @expect the id is an integer (PID), the displayName is the command
* @variations
*/
@Test
public void test_vmname03() {
logger.debug("starting " + testName);
TargetManager target = launchTarget();
try {
List<AttachProvider> providers = com.sun.tools.attach.spi.AttachProvider.providers();
AttachProvider myProvider = providers.get(0);
List<VirtualMachineDescriptor> vmdList = myProvider.listVirtualMachines();
if (vmdList.size() < 1) {
fail("test_vmname03 ERROR: no target VMs found");
}
boolean found = false;
Iterator<VirtualMachineDescriptor> vmi = vmdList.iterator();
VirtualMachineDescriptor vm = null;
while (!found && vmi.hasNext()) {
vm = vmi.next();
if (TestConstants.TARGET_VM_CLASS.equals(vm.displayName())) {
found = true;
}
}
if (null == vm) {
fail("vm is null");
return;
}
if (found) {
try {
Integer.parseInt(vm.id());
} catch (NumberFormatException e) {
fail("vm ID = " + vm.id());
}
} else {
fail("displayName " + TestConstants.TARGET_VM_CLASS + " not found");
}
} finally {
target.terminateTarget();
}
}
use of com.sun.tools.attach.spi.AttachProvider in project openj9 by eclipse.
the class TestAttachAPI method vmIdExists.
private boolean vmIdExists(String id, String id2, String displayName) {
List<AttachProvider> providers = AttachProvider.providers();
AttachProvider ap = providers.get(0);
AssertJUnit.assertNotNull("no default attach provider", ap);
List<VirtualMachineDescriptor> vmds = ap.listVirtualMachines();
Iterator<VirtualMachineDescriptor> vmi = vmds.iterator();
while (vmi.hasNext()) {
VirtualMachineDescriptor vm = vmi.next();
if ((id.equals(vm.id()) || id2.equals(vm.id())) && ((null == displayName) || displayName.equals(vm.displayName()))) {
return true;
}
}
return false;
}
Aggregations