Package net.kuujo.vertigo.network

Examples of net.kuujo.vertigo.network.NetworkContext


  @Test
  public void testDefaultWorkerModuleContext() {
    DefaultNetworkConfig network = new DefaultNetworkConfig("test");
    network.addModule("worker", "com.test~test-module~1.0");
    NetworkContext context = ContextBuilder.buildContext(network, "vertigo");
    assertEquals("vertigo.test", context.address());
    ModuleContext moduleContext = context.component("worker");
    assertEquals("worker", moduleContext.name());
    assertEquals("vertigo.test.worker", moduleContext.address());
    assertEquals("com.test~test-module~1.0", moduleContext.module());
    assertFalse(moduleContext.isVerticle());
    assertTrue(moduleContext.isModule());
View Full Code Here


    ModuleConfig module = network.addModule("worker", "com.test~test-module~1.0");
    module.setModule("com.test~test-module~1.0");
    module.setConfig(new JsonObject().putString("foo", "bar"));
    module.setInstances(2);
    module.setGroup("test");
    NetworkContext context = ContextBuilder.buildContext(network, "vertigo");
    assertEquals("vertigo.test", context.address());
    ModuleContext moduleContext = context.component("worker");
    assertEquals("worker", moduleContext.name());
    assertEquals("vertigo.test.worker", moduleContext.address());
    assertEquals("com.test~test-module~1.0", moduleContext.module());
    assertFalse(moduleContext.isVerticle());
    assertTrue(moduleContext.isModule());
View Full Code Here

  @Test
  public void testInstanceContext() {
    DefaultNetworkConfig network = new DefaultNetworkConfig("test");
    VerticleConfig verticle = network.addVerticle("feeder", "feeder.py");
    verticle.setInstances(2);
    NetworkContext context = ContextBuilder.buildContext(network, "vertigo");
    assertEquals("vertigo.test", context.address());
    VerticleContext verticleContext = context.component("feeder");
    assertEquals("feeder", verticleContext.name());
    assertEquals("vertigo.test.feeder", verticleContext.address());
    assertEquals(2, verticleContext.instances().size());
    assertEquals("vertigo.test.feeder-1", verticleContext.instances().get(0).address());
    assertEquals("vertigo.test.feeder-2", verticleContext.instances().get(1).address());
View Full Code Here

  @Test
  public void testUpdateContext() {
    NetworkConfig network = new DefaultNetworkConfig("test");
    network.addVerticle("sender", "sender.py", 2);
    NetworkContext context = ContextBuilder.buildContext(network, "vertigo");
    NetworkConfig network2 = new DefaultNetworkConfig("test");
    network2.addVerticle("receiver", "receiver.py", 2);
    NetworkContext context2 = ContextBuilder.buildContext(network2, "vertigo");
    assertNotNull(context2.component("receiver"));
    context.notify(context2);
    assertNotNull(context.component("receiver"));
  }
View Full Code Here

public class ContextTest {

  @Test
  public void testDefaultNetworkContext() {
    DefaultNetworkConfig network = new DefaultNetworkConfig("test");
    NetworkContext context = ContextBuilder.buildContext(network, "vertigo");
    assertEquals("vertigo.test", context.address());
    assertEquals(0, context.components().size());
  }
View Full Code Here

  }

  @Test
  public void testConfiguredNetworkContext() {
    DefaultNetworkConfig network = new DefaultNetworkConfig("test");
    NetworkContext context = ContextBuilder.buildContext(network, "vertigo");
    assertEquals("vertigo.test", context.address());
    assertEquals(0, context.components().size());
  }
View Full Code Here

            if (result.failed()) {
              log.error(result.cause());
              task.complete();
            } else {
              if (currentContext != null) {
                final NetworkContext runningContext = currentContext;
                currentContext = context;
               

                // We have to update all instance contexts before deploying
                // any new components in order to ensure connections are
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  private static <T extends Context<T>> T deserialize(String uri, JsonObject context) {
    ContextUri curi = new ContextUri(uri);
    NetworkContext network = SerializerFactory.getSerializer(Context.class).deserializeObject(context, NetworkContext.class);
    if (!curi.getCluster().equals(network.cluster()) || !curi.getNetwork().equals(network.name())) {
      throw new IllegalArgumentException("The given URI does not match the given context configuration");
    }

    if (curi.hasComponent()) {
      ComponentContext<?> component = network.component(curi.getComponent());
      if (component == null) {
        throw new IllegalArgumentException("The URI component " + curi.getComponent() + " does not exist in the given network configuration");
      }
      if (curi.hasInstance()) {
        InstanceContext instance = component.instance(curi.getInstance());
View Full Code Here

    final Vertigo vertigo = new Vertigo(this);
    vertigo.deployCluster("vertigo", new Handler<AsyncResult<Cluster>>() {
      @Override
      public void handle(AsyncResult<Cluster> result) {
        assertTrue(result.succeeded());
        final NetworkContext context = DefaultNetworkContext.Builder.newBuilder()
            .setName("test-coordinator-start")
            .setAddress("test")
            .setStatusAddress("test.__status")
            .setCluster("test")
            .addComponent(DefaultVerticleContext.Builder.newBuilder()
                .setName("test")
                .setAddress("test.test")
                .setStatusAddress("test.test.__status")
                .addInstance(DefaultInstanceContext.Builder.newBuilder()
                    .setAddress("test.test-1")
                    .setStatusAddress("test.test-1.__status")
                    .setInput(DefaultInputContext.Builder.newBuilder().build())
                    .setOutput(DefaultOutputContext.Builder.newBuilder().build()).build()).build()).build();
        final InstanceContext instance = context.component("test").instances().iterator().next();

        final Cluster cluster = new DefaultCluster("vertigo", vertx, container);
        final WatchableAsyncMap<String, String> data = new WrappedWatchableAsyncMap<String, String>(cluster.<String, String>getMap("test"), vertx);

        data.put(instance.address(), Contexts.serialize(instance).encode(), new Handler<AsyncResult<String>>() {
          @Override
          public void handle(AsyncResult<String> result) {
            if (result.failed()) {
              fail(result.cause().getMessage());
            } else {
              final ComponentCoordinator coordinator = new DefaultComponentCoordinator(instance, vertx, new DefaultCluster("vertigo", vertx, container));
              coordinator.start(new Handler<AsyncResult<Void>>() {
                @Override
                public void handle(AsyncResult<Void> result) {
                  if (result.failed()) {
                    fail(result.cause().getMessage());
                  } else {
                    testComplete();
                  }
                }
              });
              data.put(context.status(), "ready");
            }
          }
        });
      }
    });
View Full Code Here

    final Vertigo vertigo = new Vertigo(this);
    vertigo.deployCluster("vertigo", new Handler<AsyncResult<Cluster>>() {
      @Override
      public void handle(AsyncResult<Cluster> result) {
        assertTrue(result.succeeded());
        final NetworkContext context = DefaultNetworkContext.Builder.newBuilder()
            .setName("test-coordinator-pause")
            .setAddress("test")
            .setStatusAddress("test.__status")
            .setCluster("test")
            .addComponent(DefaultVerticleContext.Builder.newBuilder()
                .setName("test")
                .setAddress("test.test")
                .setStatusAddress("test.test.__status")
                .addInstance(DefaultInstanceContext.Builder.newBuilder()
                    .setAddress("test.test-1")
                    .setStatusAddress("test.test-1.__status")
                    .setInput(DefaultInputContext.Builder.newBuilder().build())
                    .setOutput(DefaultOutputContext.Builder.newBuilder().build()).build()).build()).build();
        final InstanceContext instance = context.component("test").instances().iterator().next();

        final Cluster cluster = new DefaultCluster("vertigo", vertx, container);
        final WatchableAsyncMap<String, String> data = new WrappedWatchableAsyncMap<String, String>(cluster.<String, String>getMap("test"), vertx);

        data.put(instance.address(), Contexts.serialize(instance).encode(), new Handler<AsyncResult<String>>() {
          @Override
          public void handle(AsyncResult<String> result) {
            if (result.failed()) {
              fail(result.cause().getMessage());
            } else {
              final ComponentCoordinator coordinator = new DefaultComponentCoordinator(instance, vertx, new DefaultCluster("vertigo", vertx, container));
              coordinator.start(new Handler<AsyncResult<Void>>() {
                @Override
                public void handle(AsyncResult<Void> result) {
                  if (result.failed()) {
                    fail(result.cause().getMessage());
                  } else {
                    coordinator.pauseHandler(new Handler<Void>() {
                      @Override
                      public void handle(Void _) {
                        testComplete();
                      }
                    });
                    data.remove(context.status());
                  }
                }
              });
              data.put(context.status(), "ready");
            }
          }
        });
      }
    });
View Full Code Here

TOP

Related Classes of net.kuujo.vertigo.network.NetworkContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.