@Test
  public void testFeatures() throws Exception {
    System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
    // System.out.println(executeCommand("shell:info"));
    // System.out.println(executeCommand("fabric:info"));
    // System.out.println(executeCommand("fabric:profile-list"));

    ServiceProxy<FabricService> fabricProxy =
        ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
    try {
      FabricService fabricService = fabricProxy.getService();

      Set<ContainerProxy> containers =
          ContainerBuilder.create(fabricProxy)
              .withName("feature-camel")
              .withProfiles("feature-camel")
              .assertProvisioningResult()
              .build();
      try {
        CuratorFramework curator = fabricService.adapt(CuratorFramework.class);
        assertProvisionedFeature(
            fabricService,
            curator,
            containers,
            "camel-script-javascript",
            "feature-camel",
            "scriptengines-javascript");
      } finally {
        ContainerBuilder.destroy(containers);
      }
    } finally {
      fabricProxy.close();
    }
  }
  @Test
  public void testExample() throws Exception {
    System.err.println("creating the cxf-server container.");
    ServiceProxy<FabricService> fabricProxy =
        ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
    try {
      Set<ContainerProxy> containers =
          ContainerBuilder.create(fabricProxy)
              .withName("child")
              .withProfiles("example-cxf-cxf.server")
              .assertProvisioningResult()
              .build();
      try {
        assertTrue("We should create the cxf-server container.", containers.size() == 1);
        System.err.println("created the cxf-server container.");
        // install bundle of CXF
        Thread.sleep(2000);
        System.err.println(executeCommand("fabric:cluster-list"));
        // install bundle of CXF
        Thread.sleep(2000);
        // calling the client here

        System.err.println("install the cxf client demo in root container");
        // This test need to take sometime to download the cxf feature related bundles
        System.err.println(executeCommand("features:install fabric-cxf", 600000, false));
        String projectVersion = System.getProperty("fabricitest.version");
        // install bundle of CXF demo client
        System.err.println(
            executeCommand(
                "osgi:install -s mvn:io.fabric8.examples/fabric-cxf-demo-client/"
                    + projectVersion));
        System.err.println(executeCommand("osgi:list"));

        System.err.println("invoking the web service");
        Hello proxy = ServiceLocator.awaitService(bundleContext, Hello.class);
        assertNotNull(proxy);
        String result1 = proxy.sayHello();
        String result2 = proxy.sayHello();
        assertNotSame("We should get the two different result", result1, result2);
      } finally {
        ContainerBuilder.destroy(containers);
      }
    } finally {
      fabricProxy.close();
    }
  }
예제 #3
0
 @After
 public void tearDown() throws InterruptedException {
   ContainerBuilder.destroy();
 }
  @Test
  public void testRegistryEntries() throws Exception {
    System.out.println(executeCommand("fabric:create -n root"));
    System.out.println(executeCommand("fabric:profile-list"));

    ServiceProxy<FabricService> fabricProxy =
        ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
    try {
      FabricService fabricService = fabricProxy.getService();
      CuratorFramework curator = fabricService.adapt(CuratorFramework.class);

      Set<ContainerProxy> containers =
          ContainerBuilder.create(fabricProxy, 3)
              .withName("fabric-camel")
              .withProfiles("feature-camel")
              .assertProvisioningResult()
              .build();
      try {
        // We will use the first container as a client and the rest as servers.
        LinkedList<Container> containerList = new LinkedList<Container>(containers);
        Container client = containerList.removeLast();

        LinkedList<Container> servers = new LinkedList<Container>(containerList);

        for (Container c : servers) {
          Profile p = c.getVersion().getProfile("example-camel-cluster.server");
          c.setProfiles(new Profile[] {p});
        }

        Provision.provisioningSuccess(servers, PROVISION_TIMEOUT);

        Profile p = client.getVersion().getProfile("example-camel-cluster.client");
        client.setProfiles(new Profile[] {p});

        Provision.provisioningSuccess(Arrays.asList(new Container[] {client}), PROVISION_TIMEOUT);

        System.out.println(executeCommand("fabric:container-list"));
        System.out.println(executeCommand("fabric:profile-display --overlay fabric-camel-server"));

        // Check that the entries have been properly propagated.
        Assert.assertNotNull(exists(curator, "/fabric/registry/camel/endpoints"));
        Assert.assertEquals(1, getChildren(curator, "/fabric/registry/camel/endpoints").size());

        Assert.assertTrue(
            Provision.waitForCondition(
                Arrays.asList(client),
                new ContainerCondition() {
                  @Override
                  public Boolean checkConditionOnContainer(final Container c) {
                    return getCompletedExchangesCount(c) > 0;
                  }
                },
                60000L));

        // We want to kill all but one server, so we take out the first and keep it to the end.
        Container lastActiveServerContainer = servers.removeLast();

        for (Container c : servers) {
          try {
            c.destroy(true);
          } catch (Exception ex) {
            // ignore.
          }
          // Get the number of exchanges completed before we kill the server.
          final int completed = getCompletedExchangesCount(client);

          // Ensure that we still have messages flowing
          Assert.assertTrue(
              Provision.waitForCondition(
                  Arrays.asList(client),
                  new ContainerCondition() {
                    @Override
                    public Boolean checkConditionOnContainer(final Container c) {
                      return getCompletedExchangesCount(c) > completed + 3;
                    }
                  },
                  60000L));
        }
        System.out.println(
            new AnsiString(
                    executeCommand(
                        "fabric:container-connect -u admin -p admin "
                            + client.getId()
                            + " camel:route-info fabric-client"))
                .getPlain()
                .toString());
      } finally {
        ContainerBuilder.destroy(containers);
      }
    } finally {
      fabricProxy.close();
    }
  }