Package com.hmsonline.storm.cassandra.client

Examples of com.hmsonline.storm.cassandra.client.AstyanaxClient


    @Test
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public void testCompositeKey() throws Exception {
        TupleMapper tupleMapper = new SimpleTupleMapper(KEYSPACE, "simple");
        AstyanaxClient client = new AstyanaxClient();
        Map<String, Object> clientConfig = new HashMap<String, Object>();
        clientConfig.put(StormCassandraConstants.CASSANDRA_HOST, "localhost:9160");
        clientConfig.put(StormCassandraConstants.CASSANDRA_KEYSPACE, Arrays.asList(new String [] {KEYSPACE}));
        client.start(clientConfig);

        Fields fields = new Fields("key1", "key2", "foo", "bar");
        Values values = new Values("key1val", "key2val", "fooval", "barval");
        Tuple tuple = new MockTuple(fields, values);

        client.writeTuple(tuple, tupleMapper);

        AstyanaxContext<Keyspace> context = newContext("localhost:9160", KEYSPACE);
        Keyspace ks = context.getEntity();

        Column<String> result = ks
                .prepareQuery(
                        new ColumnFamily<SimpleComposite, String>("simple",
                                new AnnotatedCompositeSerializer<SimpleComposite>(SimpleComposite.class),
                                StringSerializer.get())).getKey(new SimpleComposite("key1val", "key2val"))
                .getColumn("foo").execute().getResult();
        assertEquals("fooval", result.getStringValue());
       
        // test lookup
        Map<String, String> map = client.lookup(tupleMapper, tuple);
        assertEquals("fooval", map.get("foo"));
       
       
        map = client.lookup(tupleMapper, tuple, "bar", "foo", Equality.EQUAL);
        assertNotNull(map.get("foo"));
        assertNotNull(map.get("bar"));
        assertNull(map.get("key1"));
       
        ArrayList<String> slice = new ArrayList<String>();
        slice.add("foo");
        slice.add("bar");
        slice.add("key1");
        map = client.lookup(tupleMapper, tuple, slice);
        assertNotNull(map.get("foo"));
        assertNotNull(map.get("bar"));
        assertNotNull(map.get("key1"));
       
        client.stop();

    }
View Full Code Here


    }
   
    @Test
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public void testTrident() throws Exception {
        AstyanaxClient client = new AstyanaxClient();
        Map<String, Object> clientConfig = new HashMap<String, Object>();
        clientConfig.put(StormCassandraConstants.CASSANDRA_HOST, "localhost:9160");
        clientConfig.put(StormCassandraConstants.CASSANDRA_KEYSPACE, Arrays.asList(new String [] {KEYSPACE}));
        client.start(clientConfig);
       
        Fields fields = new Fields("key1", "key2", "foo", "bar");
        Values values = new Values("key1val", "key2val", "fooval", "barval");
        TridentTuple tuple = newTridentTuple(fields, values);
       
        SimpleTridentTupleMapper tupleMapper = new SimpleTridentTupleMapper(KEYSPACE, fields);
       
        client.writeTuple(tuple, tupleMapper);
       
        Map<String, String> map = client.lookup(tupleMapper, tuple);
       
        assertEquals("fooval", map.get("foo"));
       
        map = client.lookup(tupleMapper, tuple,"bar", "foo",Equality.GREATER_THAN_EQUAL);
        assertEquals("fooval", map.get("foo"));
        assertEquals("barval", map.get("bar"));
        assertNull(map.get("key1"));
        client.stop();
    }
View Full Code Here

   
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Test
    public void testCompositeRangeQuery() throws InterruptedException {
        try{
        AstyanaxClient client = new AstyanaxClient();
        Map<String, Object> clientConfig = new HashMap<String, Object>();
        clientConfig.put(StormCassandraConstants.CASSANDRA_HOST, "localhost:9160");
        clientConfig.put(StormCassandraConstants.CASSANDRA_KEYSPACE, Arrays.asList(new String [] {KEYSPACE}));
        client.start(clientConfig);
       
        Fields fields = new Fields("rowkey", "a", "b", "value");
        Values values = new Values("my_row", "a", "a", "aa");
        TridentTuple tuple = newTridentTuple(fields, values);
       
        CompositeColumnTridentTupleMapper tupleMapper = new CompositeColumnTridentTupleMapper(KEYSPACE);
       
        client.writeTuple(tuple, tupleMapper);
       
        tuple = newTridentTuple(fields, new Values("my_row", "b", "b", "bb"));
        client.writeTuple(tuple, tupleMapper);
       
        tuple = newTridentTuple(fields, new Values("my_row", "a", "b", "ab"));
        client.writeTuple(tuple, tupleMapper);
       
        tuple = newTridentTuple(fields, new Values("my_row", "a", "c", "ac"));
        client.writeTuple(tuple, tupleMapper);
       
        tuple = newTridentTuple(fields, new Values("my_row", "a", "d", "ad"));
        client.writeTuple(tuple, tupleMapper);
       
        tuple = newTridentTuple(fields, new Values("my_row", "c", "c", "cc"));
        client.writeTuple(tuple, tupleMapper);
       
        tuple = newTridentTuple(fields, new Values("my_row", "d", "d", "dd"));
        client.writeTuple(tuple, tupleMapper);
       
       
        Map<SimpleComposite, String> map = client.lookup(tupleMapper, tuple, new SimpleComposite("a", "a"), new SimpleComposite("a", "c"), Equality.GREATER_THAN_EQUAL);
        dumpMap(map);
       
        assertNotNull(map.get(new SimpleComposite("a", "a")));
        assertNotNull(map.get(new SimpleComposite("a", "b")));
        assertNotNull(map.get(new SimpleComposite("a", "c")));
        assertNull(map.get(new SimpleComposite("a", "d")));
        assertNull(map.get(new SimpleComposite("c", "c")));
        assertNull(map.get(new SimpleComposite("d", "d")));
        client.stop();
        } catch (Exception e){
            e.printStackTrace();
            fail();
        }
    }
View Full Code Here

     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public State makeState(Map conf, IMetricsContext metrics, int partitionIndex, int numPartitions) {
        LOG.info("Making new CassandraState object for cluster " + cassandraClusterId + ": partition [" + partitionIndex + "] of [" + numPartitions + "]");
        AstyanaxClient client = AstyanaxClientFactory.getInstance(cassandraClusterId, (Map)conf.get(cassandraClusterId));
        int batchMaxSize = Utils.getInt(Utils.get(conf, StormCassandraConstants.CASSANDRA_BATCH_MAX_SIZE,
                CassandraState.DEFAULT_MAX_BATCH_SIZE));
        return new CassandraState(client, batchMaxSize, this.exceptionHandler);
    }
View Full Code Here

TOP

Related Classes of com.hmsonline.storm.cassandra.client.AstyanaxClient

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.