Beispiel #1
0
  @Test
  public void pluginThatStartsClusterWithForwardersIsCleanedUp() {
    JavaPluginConfig config = new JavaPluginConfig("test");
    config.put("plugin.class", ClusterStartingPlugin.class.getName());
    JavaClusterConfig cluster = new JavaClusterConfig();
    cluster.addPlugin(config);

    JavaPluginConfig params = new JavaPluginConfig();

    IClusterControl control = context.newCluster(cluster, params);
    control.start();

    List<IClusterable> services = context.getServices("service.test", IClusterable.class);
    assertEquals(1, services.size());
    String serviceId = null;
    for (IClusterable service : services) {
      if (service instanceof IdService) {
        serviceId = ((IdService) service).getId();
      }
    }

    String id =
        context
            .getReference(context.getServices("service.test", IClusterable.class).get(0))
            .getServiceId();
    control.stop();

    assertEquals(0, context.getServices("service.test", IClusterable.class).size());
    assertNull(context.getService(id, IClusterable.class));
    assertEquals(0, context.getServices(serviceId, IClusterable.class).size());
  }
Beispiel #2
0
  @Test
  public void testCleanupServiceForwarders() {
    JavaPluginConfig config = new JavaPluginConfig("test");
    config.put("plugin.class", ServicingTestPlugin.class.getName());
    config.put("test.id", "${test.id}");
    JavaClusterConfig cluster = new JavaClusterConfig();
    cluster.addReference("test.id");
    cluster.addService("test.id");
    cluster.addPlugin(config);
    JavaPluginConfig params = new JavaPluginConfig();
    params.add("test.id", "service.test");

    IClusterable service = new IClusterable() {};
    context.registerService(service, "service.test");

    IClusterControl control = context.newCluster(cluster, params);
    control.start();

    assertEquals(2, context.getServices("service.test", IClusterable.class).size());
    String id =
        context
            .getReference(context.getServices("service.test", IClusterable.class).get(1))
            .getServiceId();
    assertNotNull(context.getService(id, IClusterable.class));
    assertEquals(
        context.getService(id, IClusterable.class),
        context.getServices("service.test", IClusterable.class).get(1));

    control.stop();

    assertEquals(1, context.getServices("service.test", IClusterable.class).size());
    assertEquals(service, context.getService("service.test", IClusterable.class));
    assertNull(context.getService(id, IClusterable.class));
  }
Beispiel #3
0
  @Test
  public void serviceUnregistrationIsImmediateDuringShutdown() throws IOException {
    JavaPluginConfig config = new JavaPluginConfig("test");
    config.put("plugin.class", DependentServicePlugin.class.getName());
    JavaClusterConfig cluster = new JavaClusterConfig();
    cluster.addPlugin(config);
    IClusterControl control = context.newCluster(cluster, new JavaPluginConfig());
    control.start();

    control.stop();

    ObjectOutputStream oos = new ObjectOutputStream(new ByteArrayOutputStream());
    oos.writeObject(context);
  }
Beispiel #4
0
  @Test
  public void testCleanupOnThrow() {
    JavaPluginConfig config = new JavaPluginConfig("test");
    config.put("plugin.class", ThrowingTestPlugin.class.getName());
    JavaClusterConfig cluster = new JavaClusterConfig();
    cluster.addPlugin(config);
    IClusterControl control = context.newCluster(cluster, new JavaPluginConfig());
    control.start();

    assertNull(context.getService("service.test", IClusterable.class));

    control.stop();

    assertNull(context.getService("service.test", IClusterable.class));
  }
Beispiel #5
0
  @Test
  public void nullRegistrationIsCleanedUp() {
    JavaPluginConfig config = new JavaPluginConfig("test");
    config.put("plugin.class", NullServiceTestPlugin.class.getName());
    JavaClusterConfig cluster = new JavaClusterConfig();
    cluster.addPlugin(config);
    IClusterControl control = context.newCluster(cluster, new JavaPluginConfig());
    control.start();

    ITestService testService = context.getService("service.test", ITestService.class);
    assertNotNull(testService);

    String serviceId = context.getReference(testService).getServiceId();
    control.stop();

    assertNull(context.getService(serviceId, ITestService.class));
  }
Beispiel #6
0
    @Override
    public void start() {
      IPluginContext context = getPluginContext();

      JavaPluginConfig config = new JavaPluginConfig("test");
      config.put("plugin.class", DummyPlugin.class.getName());
      JavaClusterConfig cluster = new JavaClusterConfig();
      cluster.addReference("test.id");
      cluster.addService("test.id");
      cluster.addPlugin(config);
      JavaPluginConfig params = new JavaPluginConfig();
      params.add("test.id", "service.test");

      IClusterControl control = context.newCluster(cluster, params);

      String id = control.getClusterConfig().getString("test.id");
      IClusterable service = new IdService(id);
      context.registerService(service, id);

      control.start();
    }
Beispiel #7
0
  @Test
  public void testCleanupOnStop() {
    JavaPluginConfig config = new JavaPluginConfig("test");
    config.put("plugin.class", TestPlugin.class.getName());
    JavaClusterConfig cluster = new JavaClusterConfig();
    cluster.addPlugin(config);
    IClusterControl control = context.newCluster(cluster, new JavaPluginConfig());
    control.start();

    assertNotNull(context.getService("service.test", IClusterable.class));
    String id =
        context.getReference(context.getService("service.test", IClusterable.class)).getServiceId();
    assertNotNull(context.getService(id, IClusterable.class));
    assertEquals(
        context.getService(id, IClusterable.class),
        context.getService("service.test", IClusterable.class));

    control.stop();

    assertNull(context.getService("service.test", IClusterable.class));
    assertNull(context.getService(id, IClusterable.class));
  }
Beispiel #8
0
  @Test
  public void testServiceIsInvisibleDuringConstruction() {
    ServiceTracker<ITestService> tracker =
        new ServiceTracker<ITestService>(ITestService.class) {
          private static final long serialVersionUID = 1L;

          @Override
          protected void onServiceAdded(ITestService service, String name) {
            service.test();
          }
        };
    context.registerTracker(tracker, "service.test");

    JavaPluginConfig config = new JavaPluginConfig("test");
    config.put("plugin.class", TestSubclassingPlugin.class.getName());
    JavaClusterConfig cluster = new JavaClusterConfig();
    cluster.addPlugin(config);
    IClusterControl control = context.newCluster(cluster, new JavaPluginConfig());
    control.start();

    ITestService testService = context.getService("service.test", ITestService.class);
    assertNotNull(testService);
    testService.test();
  }