use of io.fabric8.itests.paxexam.support.ContainerCondition in project fabric8 by jboss-fuse.
the class ExampleCamelClusterTest method testRegistryEntries.
@Test
public void testRegistryEntries() throws Exception {
System.out.println(executeCommand("fabric:create -n --wait-for-provisioning root"));
// 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();
CuratorFramework curator = fabricService.adapt(CuratorFramework.class);
Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 3).withName("fabric-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 p1 = c.getVersion().getRequiredProfile("feature-camel");
Profile p2 = c.getVersion().getRequiredProfile("example-camel-cluster-cluster.server");
c.setProfiles(new Profile[] { p1, p2 });
}
Provision.provisioningSuccess(servers, PROVISION_TIMEOUT);
Profile p1 = client.getVersion().getRequiredProfile("feature-camel");
Profile p2 = client.getVersion().getRequiredProfile("example-camel-cluster-cluster.client");
client.setProfiles(new Profile[] { p1, p2 });
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();
}
}
use of io.fabric8.itests.paxexam.support.ContainerCondition in project fabric8 by jboss-fuse.
the class ExampleMQProfileTest method testExample.
@Test
public void testExample() 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();
CuratorFramework curator = fabricService.adapt(CuratorFramework.class);
Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 2).withName("cnt").withProfiles("default").assertProvisioningResult().build();
try {
LinkedList<Container> containerList = new LinkedList<Container>(containers);
Container broker = containerList.removeLast();
setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(broker.getId()), "changing");
System.out.println(executeCommand("fabric:container-change-profile " + broker.getId() + " mq-default"));
Provision.provisioningSuccess(Arrays.asList(new Container[] { broker }), PROVISION_TIMEOUT);
System.out.println(executeCommand("fabric:cluster-list"));
for (Container c : containerList) {
setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(c.getId()), "changing");
System.out.println(executeCommand("fabric:container-change-profile " + c.getId() + " example-mq"));
}
Provision.provisioningSuccess(containerList, PROVISION_TIMEOUT);
System.out.println(executeCommand("fabric:cluster-list"));
Assert.assertTrue(Provision.waitForCondition(Arrays.asList(new Container[] { broker }), new ContainerCondition() {
@Override
public Boolean checkConditionOnContainer(final Container c) {
System.out.println(executeCommand("fabric:container-connect -u admin -p admin " + c.getId() + " activemq:bstat"));
String output = executeCommand("fabric:container-connect -u admin -p admin " + c.getId() + " activemq:query -QQueue=FABRIC.DEMO");
return output.contains("DequeueCount = ") && !output.contains("DequeueCount = 0");
}
}, 10000L));
} finally {
ContainerBuilder.destroy(containers);
}
} finally {
fabricProxy.close();
}
}
use of io.fabric8.itests.paxexam.support.ContainerCondition in project fabric8 by jboss-fuse.
the class FabricFeaturesTest method assertProvisionedFeature.
/**
* Adds a feature to the profile and tests it on the container.
* <p>Note:</p> Before and after the test the container moves to default profile.
*/
protected void assertProvisionedFeature(FabricService fabricService, CuratorFramework curator, Set<? extends Container> containers, String featureNames, String profileName, final String expectedSymbolicNames) throws Exception {
StringBuilder sb = new StringBuilder();
sb.append("[ ");
for (Container container : containers) {
sb.append(container.getId()).append(" ");
}
sb.append("]");
System.out.println("Testing profile:" + profileName + " on container:" + sb.toString() + " by adding feature:" + featureNames);
Version version = fabricService.getRequiredDefaultVersion();
Profile defaultProfile = version.getRequiredProfile("default");
Profile targetProfile = version.getRequiredProfile(profileName);
for (Container container : containers) {
// We set container to default to clean the container up.
container.setProfiles(new Profile[] { defaultProfile });
}
Provision.containerStatus(containers, PROVISION_TIMEOUT);
for (String featureName : featureNames.split(" ")) {
System.out.println(executeCommand("fabric:profile-edit --feature " + featureName + " " + targetProfile.getId()));
}
System.out.println(executeCommand("fabric:profile-display " + profileName));
for (Container container : containers) {
// Test the modified profile.
setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(container.getId()), "switching profile");
container.setProfiles(new Profile[] { targetProfile });
}
Provision.containerStatus(containers, PROVISION_TIMEOUT);
System.out.println(executeCommand("fabric:container-list"));
Assert.assertTrue(Provision.waitForCondition(containers, new ContainerCondition() {
@Override
public Boolean checkConditionOnContainer(Container c) {
for (String symbolicName : expectedSymbolicNames.split(" ")) {
String bundles = executeCommand("container-connect -u admin -p admin " + c.getId() + " osgi:list -s -t 0 | grep " + symbolicName);
if (bundles != null) {
return bundles.contains(symbolicName);
}
}
return false;
}
}, PROVISION_TIMEOUT));
for (Container container : containers) {
// We set the container to default to clean up the profile.
if (!defaultProfile.equals(targetProfile)) {
setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(container.getId()), "switching profile");
}
container.setProfiles(new Profile[] { defaultProfile });
}
Provision.containerStatus(containers, PROVISION_TIMEOUT);
for (String featureName : featureNames.split(" ")) {
System.out.println(executeCommand("fabric:profile-edit --delete --feature " + featureName + " " + targetProfile.getId()));
}
}
use of io.fabric8.itests.paxexam.support.ContainerCondition in project fabric8 by jboss-fuse.
the class FabricDosgiCamelTest method testFeatureProvisioning.
@Test
public void testFeatureProvisioning() throws Exception {
System.out.println(executeCommand("fabric:create -n --wait-for-provisioning root"));
// 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();
CuratorFramework curator = fabricService.adapt(CuratorFramework.class);
waitForFabricCommands();
Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 2).withName("dosgi").withProfiles("karaf").assertProvisioningResult().build();
try {
List<Container> containerList = new ArrayList<Container>(containers);
List<Container> dosgiProviderContainers = containerList.subList(0, containerList.size() / 2);
List<Container> dosgiCamelContainers = containerList.subList(containerList.size() / 2, containerList.size());
for (Container c : dosgiProviderContainers) {
setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(c.getId()), "changing profile");
Profile p = c.getVersion().getRequiredProfile("example-dosgi-camel.provider");
c.setProfiles(new Profile[] { p });
}
for (Container c : dosgiCamelContainers) {
setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(c.getId()), "changing profile");
Profile p = c.getVersion().getRequiredProfile("example-dosgi-camel.consumer");
c.setProfiles(new Profile[] { p });
}
Provision.provisioningSuccess(dosgiProviderContainers, PROVISION_TIMEOUT);
Provision.provisioningSuccess(dosgiCamelContainers, PROVISION_TIMEOUT);
Assert.assertTrue(Provision.waitForCondition(dosgiCamelContainers, new ContainerCondition() {
@Override
public Boolean checkConditionOnContainer(final Container c) {
String response = executeCommand("fabric:container-connect -u admin -p admin " + c.getId() + " log:display | grep \"Message from distributed service to\"");
System.out.println(executeCommand("fabric:container-connect -u admin -p admin " + c.getId() + " camel:route-info fabric-client"));
Assert.assertNotNull(response);
System.out.println(response);
String[] lines = response.split("\n");
// TODO: This assertion is very relaxed and guarantees nothing.
return lines.length >= 1;
}
}, 20000L));
} finally {
ContainerBuilder.destroy(containers);
}
} finally {
fabricProxy.close();
}
}
use of io.fabric8.itests.paxexam.support.ContainerCondition in project fabric8 by jboss-fuse.
the class ExampleCamelCxfTest method testExample.
@Test
public void testExample() 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 {
Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy).withName("child").withProfiles("example-camel-cxf").assertProvisioningResult().build();
try {
System.out.println(executeCommand("fabric:container-list"));
Assert.assertTrue(Provision.waitForCondition(containers, new ContainerCondition() {
@Override
public Boolean checkConditionOnContainer(final Container c) {
String response = new AnsiString(executeCommand("fabric:container-connect -u admin -p admin " + c.getId() + " camel:route-list | grep fabric-camel-cxf")).getPlain().toString();
return response.contains("fabric-camel-cxf");
}
}, 60000L));
for (Container container : containers) {
System.out.println(executeCommand("fabric:container-connect -u admin -p admin " + container.getId() + " osgi:list"));
String response = executeCommand("fabric:container-connect -u admin -p admin " + container.getId() + " camel:route-list | grep fabric-camel-cxf");
System.out.println(response);
Assert.assertTrue(response.contains("Started"));
}
} finally {
ContainerBuilder.destroy(containers);
}
} finally {
fabricProxy.close();
}
}
Aggregations