use of com.sun.tools.attach.VirtualMachineDescriptor in project openj9 by eclipse.
the class TestAttachAPI method test_vmname04.
@Test
public void test_vmname04() {
logger.debug("starting " + testName);
TargetManager target = launchTarget();
VirtualMachine vm = null;
VirtualMachineDescriptor vmd = null;
try {
String tgtId = target.getTargetPid();
List<AttachProvider> providers = AttachProvider.providers();
AttachProvider myProvider = providers.get(0);
vmd = findVmdForPid(myProvider, tgtId);
vm = VirtualMachine.attach(vmd);
String vmId = vm.id();
String vmdId = vmd.id();
AssertJUnit.assertEquals("VirtualMachineDescriptor.id() == VirtualMachine.id()", vmId, vmdId);
} catch (AttachNotSupportedException | IOException e) {
logger.error("Trying to attach " + vmd.id() + " " + vmd.displayName());
logExceptionInfoAndFail(e);
} finally {
if (null != vm) {
try {
vm.detach();
} catch (IOException e) {
logExceptionInfoAndFail(e);
}
}
target.terminateTarget();
}
}
use of com.sun.tools.attach.VirtualMachineDescriptor in project openj9 by eclipse.
the class TestAttachAPI method test_attach05.
@Test
public void test_attach05() {
TargetManager target = launchTarget();
VirtualMachine vm = null;
try {
List<AttachProvider> providers = com.sun.tools.attach.spi.AttachProvider.providers();
AttachProvider myProvider = providers.get(0);
VirtualMachineDescriptor vmd;
if (null == (vmd = findVmdForPid(myProvider, target.getTargetPid()))) {
fail("ERROR " + testName + ": no target VMs found");
}
vm = VirtualMachine.attach(vmd);
if (null == vm) {
fail("vm is null");
return;
}
if (null == vmd) {
fail("vmd is null");
return;
}
AttachProvider vmdProvider = vmd.provider();
AssertJUnit.assertEquals("VirtualMachineDescriptor.provider() == main provider", vmdProvider, myProvider);
AttachProvider vmProvider = vm.provider();
AssertJUnit.assertEquals("VirtualMachine.provider() == main provider", vmProvider, myProvider);
} catch (AttachNotSupportedException | IOException e) {
listIpcDir();
logExceptionInfoAndFail(e);
} finally {
if (null != vm) {
try {
vm.detach();
} catch (IOException e) {
logExceptionInfoAndFail(e);
}
}
target.terminateTarget();
}
}
use of com.sun.tools.attach.VirtualMachineDescriptor in project openj9 by eclipse.
the class TestAttachAPI method test_vmname06.
@Test
public void test_vmname06() {
logger.debug("starting " + testName);
TargetManager mainTarget = launchTarget();
try {
List<AttachProvider> providers = com.sun.tools.attach.spi.AttachProvider.providers();
AttachProvider myProvider = providers.get(0);
List<VirtualMachineDescriptor> vmdList = myProvider.listVirtualMachines();
List<VirtualMachineDescriptor> vmdList2 = myProvider.listVirtualMachines();
if (vmdList.size() < 2) {
fail("ERROR " + testName + ": no target VMs found");
}
VirtualMachineDescriptor mainDesc = vmdList.get(0);
boolean found = false;
Iterator<VirtualMachineDescriptor> vmdi = vmdList2.iterator();
while (vmdi.hasNext()) {
VirtualMachineDescriptor vmd = vmdi.next();
if (vmd.equals(mainDesc)) {
found = true;
break;
}
}
assertTrue("VirtualMachineDescriptor.equals", found);
} finally {
mainTarget.terminateTarget();
}
}
use of com.sun.tools.attach.VirtualMachineDescriptor 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.VirtualMachineDescriptor 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();
}
}
Aggregations