Search in sources :

Example 26 with Instance

use of org.apache.karaf.instance.core.Instance in project karaf by apache.

the class InstanceServiceMBeanImplTest method testGetInstances.

public void testGetInstances() throws Exception {
    Instance i1 = EasyMock.createMock(Instance.class);
    EasyMock.expect(i1.getPid()).andReturn(1234);
    EasyMock.expect(i1.getSshPort()).andReturn(8818);
    EasyMock.expect(i1.getSshHost()).andReturn("0.0.0.0");
    EasyMock.expect(i1.getRmiRegistryPort()).andReturn(1122);
    EasyMock.expect(i1.getRmiRegistryHost()).andReturn("0.0.0.0");
    EasyMock.expect(i1.getRmiServerPort()).andReturn(44444);
    EasyMock.expect(i1.getRmiServerHost()).andReturn("0.0.0.0");
    EasyMock.expect(i1.getName()).andReturn("i1");
    EasyMock.expect(i1.isRoot()).andReturn(true);
    EasyMock.expect(i1.getLocation()).andReturn("somewhere");
    EasyMock.expect(i1.getJavaOpts()).andReturn("someopts");
    EasyMock.expect(i1.getState()).andReturn("Stopped");
    EasyMock.replay(i1);
    Instance i2 = EasyMock.createNiceMock(Instance.class);
    EasyMock.expect(i2.getName()).andReturn("i2");
    EasyMock.replay(i2);
    InstanceService instanceService = EasyMock.createMock(InstanceService.class);
    EasyMock.expect(instanceService.getInstances()).andReturn(new Instance[] { i1, i2 });
    EasyMock.replay(instanceService);
    InstancesMBeanImpl instanceServiceMBean = new InstancesMBeanImpl(instanceService);
    TabularData tabularData = instanceServiceMBean.getInstances();
    Assert.assertEquals(2, tabularData.size());
    CompositeData cd1 = tabularData.get(new Object[] { "i1" });
    Assert.assertTrue(cd1.containsValue("i1"));
    Assert.assertTrue(cd1.containsValue(true));
    Assert.assertTrue(cd1.containsValue(1234));
    Assert.assertTrue(cd1.containsValue(8818));
    Assert.assertTrue(cd1.containsValue(1122));
    Assert.assertTrue(cd1.containsValue(44444));
    Assert.assertTrue(cd1.containsValue("0.0.0.0"));
    Assert.assertTrue(cd1.containsValue("somewhere"));
    Assert.assertTrue(cd1.containsValue("someopts"));
    Assert.assertTrue(cd1.containsValue("Stopped"));
    CompositeData cd2 = tabularData.get(new Object[] { "i2" });
    Assert.assertTrue(cd2.containsValue("i2"));
}
Also used : Instance(org.apache.karaf.instance.core.Instance) InstancesMBeanImpl(org.apache.karaf.instance.core.internal.InstancesMBeanImpl) CompositeData(javax.management.openmbean.CompositeData) InstanceService(org.apache.karaf.instance.core.InstanceService) TabularData(javax.management.openmbean.TabularData)

Example 27 with Instance

use of org.apache.karaf.instance.core.Instance in project karaf by apache.

the class InstanceServiceMBeanImplTest method testRmiRegistryChangePort.

public void testRmiRegistryChangePort() throws Exception {
    Instance inst = EasyMock.createMock(Instance.class);
    inst.changeRmiRegistryPort(1123);
    EasyMock.expectLastCall();
    EasyMock.replay(inst);
    InstanceService instanceService = EasyMock.createMock(InstanceService.class);
    EasyMock.expect(instanceService.getInstance("test instance")).andReturn(inst);
    EasyMock.replay(instanceService);
    InstancesMBean instanceServiceMBean = new InstancesMBeanImpl(instanceService);
    instanceServiceMBean.changeRmiRegistryPort("test instance", 1123);
    EasyMock.verify(instanceService);
    EasyMock.verify(inst);
}
Also used : Instance(org.apache.karaf.instance.core.Instance) InstancesMBeanImpl(org.apache.karaf.instance.core.internal.InstancesMBeanImpl) InstancesMBean(org.apache.karaf.instance.core.InstancesMBean) InstanceService(org.apache.karaf.instance.core.InstanceService)

Example 28 with Instance

use of org.apache.karaf.instance.core.Instance in project karaf by apache.

the class InstanceToTableMapperTest method testJMXInstance.

public void testJMXInstance() throws Exception {
    Instance instance = EasyMock.createMock(Instance.class);
    EasyMock.expect(instance.getPid()).andReturn(1712);
    EasyMock.expect(instance.getName()).andReturn("MyInstance");
    EasyMock.expect(instance.isRoot()).andReturn(false);
    EasyMock.expect(instance.getSshPort()).andReturn(0);
    EasyMock.expect(instance.getSshHost()).andReturn("0.0.0.0");
    EasyMock.expect(instance.getRmiRegistryPort()).andReturn(0);
    EasyMock.expect(instance.getRmiRegistryHost()).andReturn("0.0.0.0");
    EasyMock.expect(instance.getRmiServerPort()).andReturn(0);
    EasyMock.expect(instance.getRmiServerHost()).andReturn("0.0.0.0");
    EasyMock.expect(instance.getState()).andThrow(new Exception("gotcha"));
    EasyMock.expect(instance.getLocation()).andReturn("somewhere");
    EasyMock.expect(instance.getJavaOpts()).andReturn("someopts");
    EasyMock.replay(instance);
    TabularData td = InstanceToTableMapper.tableFrom(Collections.singletonList(instance));
    Collection<?> keys = (Collection<?>) td.keySet().iterator().next();
    Assert.assertEquals("MyInstance", keys.iterator().next());
    CompositeData cd = td.get(keys.toArray());
    Assert.assertEquals(1712, cd.get("Pid"));
    Assert.assertEquals("MyInstance", cd.get("Name"));
    Assert.assertEquals(false, cd.get("Is Root"));
    Assert.assertEquals(0, cd.get("SSH Port"));
    Assert.assertEquals("0.0.0.0", cd.get("SSH Host"));
    Assert.assertEquals(0, cd.get("RMI Registry Port"));
    Assert.assertEquals("0.0.0.0", cd.get("RMI Registry Host"));
    Assert.assertEquals(0, cd.get("RMI Server Port"));
    Assert.assertEquals("0.0.0.0", cd.get("RMI Server Host"));
    Assert.assertEquals("Error", cd.get("State"));
    Assert.assertEquals("somewhere", cd.get("Location"));
    Assert.assertEquals("someopts", cd.get("JavaOpts"));
}
Also used : Instance(org.apache.karaf.instance.core.Instance) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) TabularData(javax.management.openmbean.TabularData)

Aggregations

Instance (org.apache.karaf.instance.core.Instance)28 InstanceService (org.apache.karaf.instance.core.InstanceService)11 InstancesMBeanImpl (org.apache.karaf.instance.core.internal.InstancesMBeanImpl)10 InstancesMBean (org.apache.karaf.instance.core.InstancesMBean)8 InstanceSettings (org.apache.karaf.instance.core.InstanceSettings)5 TabularData (javax.management.openmbean.TabularData)4 MultiException (org.apache.karaf.shell.support.MultiException)4 ArrayList (java.util.ArrayList)3 CompositeData (javax.management.openmbean.CompositeData)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 MBeanException (javax.management.MBeanException)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)2 ServletException (javax.servlet.ServletException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)1