Search in sources :

Example 6 with CassandraResourceResolver

use of org.apache.sling.cassandra.resource.provider.CassandraResourceResolver in project sling by apache.

the class CassandraDataChildNodeIterableTest method getChildrenData.

private void getChildrenData(CassandraResourceProvider cassandraResourceProvider, String cf) {
    Resource resource = cassandraResourceProvider.getResource(new CassandraResourceResolver(), "/content/cassandra/" + cf + "/c1");
    Assert.assertNotNull(resource);
    Iterable<Resource> iterableChildren = resource.getChildren();
    Iterator<Resource> children = iterableChildren.iterator();
    boolean hasChild = false;
    while (children.hasNext()) {
        Resource r = children.next();
        if (r.getPath().equals("/content/cassandra/" + cf + "/c1/c2")) {
            Assert.assertNotNull(r);
            Assert.assertEquals("/content/cassandra/" + cf + "/c1/c2", r.getPath());
            hasChild = true;
        }
    }
    Assert.assertTrue(hasChild);
}
Also used : Resource(org.apache.sling.api.resource.Resource) CassandraResourceResolver(org.apache.sling.cassandra.resource.provider.CassandraResourceResolver)

Example 7 with CassandraResourceResolver

use of org.apache.sling.cassandra.resource.provider.CassandraResourceResolver in project sling by apache.

the class CassandraDataChildNodeTest method getChildrenData.

private void getChildrenData(CassandraResourceProvider cassandraResourceProvider, String cf) {
    Resource resource = cassandraResourceProvider.getResource(new CassandraResourceResolver(), "/content/cassandra/" + cf + "/c1");
    Assert.assertNotNull(resource);
    Iterator<Resource> children = resource.listChildren();
    boolean hasChild = false;
    while (children.hasNext()) {
        Resource r = children.next();
        if (r.getPath().equals("/content/cassandra/" + cf + "/c1/c2")) {
            Assert.assertNotNull(r);
            Assert.assertEquals("/content/cassandra/" + cf + "/c1/c2", r.getPath());
            hasChild = true;
        }
    }
    Assert.assertTrue(hasChild);
}
Also used : Resource(org.apache.sling.api.resource.Resource) CassandraResourceResolver(org.apache.sling.cassandra.resource.provider.CassandraResourceResolver)

Example 8 with CassandraResourceResolver

use of org.apache.sling.cassandra.resource.provider.CassandraResourceResolver in project sling by apache.

the class CassandraModifyResourceProviderAddTest method testAddData.

@Test
public void testAddData() {
    String cf = "p2";
    try {
        String path1 = "/content/cassandra/" + cf + "/c1";
        CassandraResourceProvider cassandraResourceProvider = new CassandraResourceProvider();
        createColumnFamily(cf, cassandraResourceProvider.getKeyspace(), new StringSerializer());
        cassandraResourceProvider.setColumnFamily(cf);
        Map<String, Object> map1 = new HashMap<String, Object>();
        map1.put("metadata", "resolutionPathInfo=json");
        map1.put("resourceType", "nt:cassandra0");
        map1.put("resourceSuperType", "nt:supercass1");
        CassandraResourceResolver resolver = new CassandraResourceResolver();
        cassandraResourceProvider.create(resolver, path1, map1);
        Assert.assertNull("Before Commiting Resource should be null", cassandraResourceProvider.getResource(resolver, path1));
        cassandraResourceProvider.commit(resolver);
        Assert.assertNotNull("Commited Resource cannot be null", cassandraResourceProvider.getResource(resolver, path1));
    } catch (Exception e) {
        LOGGER.info("Ignore err" + e.getMessage());
        Assert.fail("Failed to add data to cassandra");
    }
}
Also used : HashMap(java.util.HashMap) CassandraResourceProvider(org.apache.sling.cassandra.resource.provider.CassandraResourceProvider) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer) HInvalidRequestException(me.prettyprint.hector.api.exceptions.HInvalidRequestException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CassandraResourceResolver(org.apache.sling.cassandra.resource.provider.CassandraResourceResolver) Test(org.junit.Test)

Aggregations

CassandraResourceResolver (org.apache.sling.cassandra.resource.provider.CassandraResourceResolver)8 HashMap (java.util.HashMap)4 StringSerializer (me.prettyprint.cassandra.serializers.StringSerializer)4 HInvalidRequestException (me.prettyprint.hector.api.exceptions.HInvalidRequestException)4 Resource (org.apache.sling.api.resource.Resource)4 CassandraResourceProvider (org.apache.sling.cassandra.resource.provider.CassandraResourceProvider)4 Test (org.junit.Test)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2