Search in sources :

Example 6 with VirtualMachineDescriptor

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();
    }
}
Also used : VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) IOException(java.io.IOException) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) AttachProvider(com.sun.tools.attach.spi.AttachProvider) VirtualMachine(com.sun.tools.attach.VirtualMachine) Test(org.testng.annotations.Test)

Example 7 with VirtualMachineDescriptor

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();
    }
}
Also used : VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) IOException(java.io.IOException) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) AttachProvider(com.sun.tools.attach.spi.AttachProvider) VirtualMachine(com.sun.tools.attach.VirtualMachine) Test(org.testng.annotations.Test)

Example 8 with VirtualMachineDescriptor

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();
    }
}
Also used : VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) AttachProvider(com.sun.tools.attach.spi.AttachProvider) Test(org.testng.annotations.Test)

Example 9 with VirtualMachineDescriptor

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);
        }
    }
}
Also used : VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) IOException(java.io.IOException) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) AttachProvider(com.sun.tools.attach.spi.AttachProvider) VirtualMachine(com.sun.tools.attach.VirtualMachine) Test(org.testng.annotations.Test)

Example 10 with VirtualMachineDescriptor

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();
    }
}
Also used : VirtualMachineDescriptor(com.sun.tools.attach.VirtualMachineDescriptor) IOException(java.io.IOException) AttachNotSupportedException(com.sun.tools.attach.AttachNotSupportedException) AttachProvider(com.sun.tools.attach.spi.AttachProvider) VirtualMachine(com.sun.tools.attach.VirtualMachine) Test(org.testng.annotations.Test)

Aggregations

VirtualMachineDescriptor (com.sun.tools.attach.VirtualMachineDescriptor)26 IOException (java.io.IOException)16 AttachNotSupportedException (com.sun.tools.attach.AttachNotSupportedException)13 AttachProvider (com.sun.tools.attach.spi.AttachProvider)12 VirtualMachine (com.sun.tools.attach.VirtualMachine)11 Test (org.testng.annotations.Test)7 ArrayList (java.util.ArrayList)5 Msg.getString (com.ibm.oti.util.Msg.getString)2 AgentLoadException (com.sun.tools.attach.AgentLoadException)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 JMXServiceURL (javax.management.remote.JMXServiceURL)2 MonitorException (sun.jvmstat.monitor.MonitorException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 FileLock (com.ibm.tools.attach.target.FileLock)1 Reply (com.ibm.tools.attach.target.Reply)1 AgentInitializationException (com.sun.tools.attach.AgentInitializationException)1 AttachOperationFailedException (com.sun.tools.attach.AttachOperationFailedException)1 CommonContext (io.aeron.CommonContext)1 AeronCluster (io.aeron.cluster.client.AeronCluster)1