Search in sources :

Example 1 with LauncherSupervisor

use of aQute.remote.plugin.LauncherSupervisor in project bnd by bndtools.

the class MainTest method testRemoteMain.

public void testRemoteMain() throws Exception {
    //
    // Create a framework & start an agent
    //
    LauncherSupervisor supervisor = new LauncherSupervisor();
    supervisor.connect("localhost", Agent.DEFAULT_PORT + 1);
    assertEquals("not talking to an envoy", true, supervisor.getAgent().isEnvoy());
    HashMap<String, Object> configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    configuration.put(Constants.FRAMEWORK_STORAGE, "generated/storage");
    List<String> emptyList = Collections.emptyList();
    boolean created = supervisor.getAgent().createFramework("test", emptyList, configuration);
    assertTrue("there already was a framework, funny, since we created the main in setUp?", created);
    FrameworkDTO framework = supervisor.getAgent().getFramework();
    assertNotNull("just created it, so we should have a framework", framework);
    //
    // Create a second supervisor and ensure we do not
    // kill the primary
    //
    LauncherSupervisor sv2 = new LauncherSupervisor();
    sv2.connect("localhost", Agent.DEFAULT_PORT + 1);
    assertTrue("no second framework", supervisor.getAgent().ping());
    assertEquals("must be an envoy", true, sv2.getAgent().isEnvoy());
    assertFalse("the framework should already exist", sv2.getAgent().createFramework("test", emptyList, configuration));
    assertTrue("first framework is gone", supervisor.getAgent().ping());
    FrameworkDTO fw2 = sv2.getAgent().getFramework();
    assertEquals("we should not have created a new framework", framework.properties.get("org.osgi.framework.uuid"), fw2.properties.get("org.osgi.framework.uuid"));
    //
    // Kill the second framework
    //
    supervisor.getAgent().abort();
    Thread.sleep(500);
    assertFalse(supervisor.isOpen());
    assertTrue("should not have killed sv2", sv2.getAgent().ping());
    sv2.abort();
    Thread.sleep(500);
    assertFalse(sv2.isOpen());
}
Also used : FrameworkDTO(org.osgi.framework.dto.FrameworkDTO) HashMap(java.util.HashMap) LauncherSupervisor(aQute.remote.plugin.LauncherSupervisor)

Example 2 with LauncherSupervisor

use of aQute.remote.plugin.LauncherSupervisor in project bnd by bndtools.

the class RemoteTest method testSimple.

public void testSimple() throws Exception {
    LauncherSupervisor supervisor = new LauncherSupervisor();
    supervisor.connect("localhost", Agent.DEFAULT_PORT);
    assertNotNull(supervisor);
    Agent agent = supervisor.getAgent();
    assertNotNull(agent.getFramework());
    // Create stdin/stderr buffers
    // and redirect output
    StringBuffer stderr = new StringBuffer();
    StringBuffer stdout = new StringBuffer();
    supervisor.setStderr(stderr);
    supervisor.setStdout(stdout);
    supervisor.redirect(1);
    //
    // Install the bundle systemio
    //
    File f = IO.getFile("generated/biz.aQute.remote.test.systemio.jar");
    String sha = supervisor.addFile(f);
    BundleDTO bundle = agent.install(f.getAbsolutePath(), sha);
    //
    // Start the bundle and capture the output
    //
    String result = agent.start(bundle.id);
    assertNull(result, result);
    Thread.sleep(1000);
    assertEquals("Hello World", stdout.toString().trim());
    stdout.setLength(0);
    // Send input (will be consumed by the Activator.stop
    ByteArrayInputStream bin = new ByteArrayInputStream(new String("Input\n").getBytes());
    supervisor.setStdin(bin);
    // stop the bundle (will return input as uppercase)
    result = agent.stop(bundle.id);
    assertNull(result, result);
    Thread.sleep(1000);
    assertEquals("INPUT", stdout.toString().trim());
}
Also used : Agent(aQute.remote.api.Agent) ByteArrayInputStream(java.io.ByteArrayInputStream) LauncherSupervisor(aQute.remote.plugin.LauncherSupervisor) BundleDTO(org.osgi.framework.dto.BundleDTO) File(java.io.File)

Example 3 with LauncherSupervisor

use of aQute.remote.plugin.LauncherSupervisor in project bnd by bndtools.

the class RemoteTest method testUpdateOrder.

public void testUpdateOrder() throws Exception {
    LauncherSupervisor supervisor = new LauncherSupervisor();
    supervisor.connect("localhost", Agent.DEFAULT_PORT);
    List<String> bundles = new ArrayList<String>();
    LinkedHashMap<String, String> update = new LinkedHashMap<String, String>();
    for (int i = 0; i < 50; i++) {
        String name = UUID.randomUUID().toString();
        File f = create(name, new Version(1, 0, 0));
        assertTrue(f.isFile());
        String sha = supervisor.addFile(f);
        update.put(f.getAbsolutePath(), sha);
        bundles.add(name);
    }
    String errors = supervisor.getAgent().update(update);
    assertNull(errors);
    //
    // Now check installed bundle order
    //
    Bundle[] installed = context.getBundles();
    for (int i = 2; i < installed.length; i++) {
        Bundle b = installed[i];
        assertTrue(b.getLocation().endsWith(bundles.get(i - 2) + "-1.0.0.jar"));
    }
    // delete
    supervisor.getAgent().update(null);
}
Also used : Version(aQute.bnd.version.Version) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) LauncherSupervisor(aQute.remote.plugin.LauncherSupervisor) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with LauncherSupervisor

use of aQute.remote.plugin.LauncherSupervisor in project bnd by bndtools.

the class RemoteTest method testUpdate.

public void testUpdate() throws Exception {
    LauncherSupervisor supervisor = new LauncherSupervisor();
    supervisor.connect("localhost", Agent.DEFAULT_PORT);
    File t1 = create("bsn-1", new Version(1, 0, 0));
    File t2 = create("bsn-2", new Version(1, 0, 0));
    assertTrue(t1.isFile());
    assertTrue(t2.isFile());
    String sha1 = supervisor.addFile(t1);
    String sha2 = supervisor.addFile(t2);
    Map<String, String> update = new HashMap<String, String>();
    update.put(t1.getAbsolutePath(), sha1);
    String errors = supervisor.getAgent().update(update);
    assertNull(errors);
    //
    // Verify that t1 is installed and t2 not
    //
    Bundle b1 = context.getBundle(t1.getAbsolutePath());
    assertNotNull(b1);
    Bundle b2 = context.getBundle(t2.getAbsolutePath());
    assertNull(b2);
    //
    // Now add a new one
    //
    update = new HashMap<String, String>();
    update.put(t1.getAbsolutePath(), sha1);
    update.put(t2.getAbsolutePath(), sha2);
    errors = supervisor.getAgent().update(update);
    assertNull(errors);
    assertNotNull(context.getBundle(t1.getAbsolutePath()));
    assertNotNull(context.getBundle(t2.getAbsolutePath()));
    //
    // Now change a bundle
    //
    t1 = create("bsn-1", new Version(2, 0, 0));
    sha1 = supervisor.addFile(t1);
    update = new HashMap<String, String>();
    update.put(t1.getAbsolutePath(), sha1);
    update.put(t2.getAbsolutePath(), sha2);
    errors = supervisor.getAgent().update(update);
    assertNull(errors);
    b1 = context.getBundle(t1.getAbsolutePath());
    assertNotNull(b1);
    b2 = context.getBundle(t2.getAbsolutePath());
    assertNotNull(b2);
    assertEquals(new Version(2, 0, 0).toString(), b1.getVersion().toString());
    assertEquals(Bundle.ACTIVE, b1.getState());
    assertEquals(Bundle.ACTIVE, b2.getState());
    //
    // Now delete t1
    //
    update = new HashMap<String, String>();
    update.put(t2.getAbsolutePath(), sha2);
    errors = supervisor.getAgent().update(update);
    assertNull(errors);
    assertNull(context.getBundle(t1.getAbsolutePath()));
    assertNotNull(context.getBundle(t2.getAbsolutePath()));
    //
    // Delete all
    //
    supervisor.getAgent().update(null);
    assertNull(context.getBundle(t1.getAbsolutePath()));
    assertNull(context.getBundle(t2.getAbsolutePath()));
}
Also used : Version(aQute.bnd.version.Version) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Bundle(org.osgi.framework.Bundle) LauncherSupervisor(aQute.remote.plugin.LauncherSupervisor) File(java.io.File)

Example 5 with LauncherSupervisor

use of aQute.remote.plugin.LauncherSupervisor in project bnd by bndtools.

the class RemoteTest method testBRD.

/*
	 * Test if we can get the BundleRevisionDTOs
	 */
public void testBRD() throws Exception {
    LauncherSupervisor supervisor = new LauncherSupervisor();
    supervisor.connect("localhost", Agent.DEFAULT_PORT);
    assertNotNull(supervisor);
    Agent agent = supervisor.getAgent();
    assertNotNull(agent);
    List<BundleRevisionDTO> bundleRevisons = agent.getBundleRevisons();
    assertNotNull(bundleRevisons);
}
Also used : Agent(aQute.remote.api.Agent) BundleRevisionDTO(org.osgi.framework.wiring.dto.BundleRevisionDTO) LauncherSupervisor(aQute.remote.plugin.LauncherSupervisor)

Aggregations

LauncherSupervisor (aQute.remote.plugin.LauncherSupervisor)5 File (java.io.File)3 Version (aQute.bnd.version.Version)2 Agent (aQute.remote.api.Agent)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Bundle (org.osgi.framework.Bundle)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 BundleDTO (org.osgi.framework.dto.BundleDTO)1 FrameworkDTO (org.osgi.framework.dto.FrameworkDTO)1 BundleRevisionDTO (org.osgi.framework.wiring.dto.BundleRevisionDTO)1