Search in sources :

Example 1 with BlobClusterStateStore

use of org.apache.whirr.state.BlobClusterStateStore in project whirr by apache.

the class BlobClusterStateStoreTest method testStoreAndLoadState.

@Test(timeout = TestConstants.ITEST_TIMEOUT)
public void testStoreAndLoadState() throws Exception {
    ClusterSpec spec = getTestClusterSpec();
    BlobStoreContext context = BlobStoreContextBuilder.build(spec);
    String container = generateRandomContainerName(context);
    try {
        spec.setStateStore("blob");
        spec.setStateStoreContainer(container);
        Cluster expected = createTestCluster(new String[] { "region/id1", "region/id2" }, new String[] { "role1", "role2" });
        BlobClusterStateStore store = new BlobClusterStateStore(spec);
        store.save(expected);
        /* load and check the stored state */
        Cluster stored = store.load();
        Cluster.Instance first = Iterables.getFirst(stored.getInstances(), null);
        assertNotNull(first);
        assertThat(first.getId(), is("region/id1"));
        assertThat(first.getRoles().contains("role1"), is(true));
        assertThat(stored.getInstances().size(), is(2));
        /* destroy stored state and check it no longer exists */
        store.destroy();
        expected = store.load();
        assertNull(expected);
    } finally {
        LOG.info("Removing temporary container '{}'", container);
        context.getBlobStore().deleteContainer(container);
    }
}
Also used : BlobClusterStateStore(org.apache.whirr.state.BlobClusterStateStore) Cluster(org.apache.whirr.Cluster) ClusterSpec(org.apache.whirr.ClusterSpec) BlobStoreContext(org.jclouds.blobstore.BlobStoreContext) Test(org.junit.Test)

Aggregations

Cluster (org.apache.whirr.Cluster)1 ClusterSpec (org.apache.whirr.ClusterSpec)1 BlobClusterStateStore (org.apache.whirr.state.BlobClusterStateStore)1 BlobStoreContext (org.jclouds.blobstore.BlobStoreContext)1 Test (org.junit.Test)1