@Test public void testCreateSelectTemplate() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("key1"); updater.setString("column1","value1"); template.update(updater); template.setCount(10); String value = template.queryColumns("key1", new ColumnFamilyRowMapper<String, String, String>() { @Override public String mapRow(ColumnFamilyResult<String, String> results) { // TODO Auto-generated method stub return results.getString("column1"); } }); assertEquals("value1",value); }
@Test public void testCreateSelect() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("key1"); updater.setString("column1","value1"); template.update(updater); template.addColumn("column1", se); ColumnFamilyResult<String,String> wrapper = template.queryColumns("key1"); assertEquals("value1",wrapper.getString("column1")); }
@Test public void testGetKeyTwiceCall() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); ColumnFamilyResult<String, String> results = template.queryColumns("noresults"); assertEquals("noresults",results.getKey()); assertEquals("noresults",results.getKey()); assertEquals("noresults",results.getKey()); } @Test
@Test public void testHasNoResults() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); assertFalse(template.queryColumns("noresults").hasResults()); assertFalse(template.queryColumns("noresults").hasNext()); assertEquals("noresults",template.queryColumns("noresults").getKey()); }
@Test public void testCreateSelectMultiColumn() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("cskey1"); updater.setString("stringval","value1"); Date date = new Date(); updater.setDate("curdate", date); updater.setLong("longval", 5L); template.update(updater); template.addColumn("stringval", se); template.addColumn("curdate", DateSerializer.get()); template.addColumn("longval", LongSerializer.get()); ColumnFamilyResult<String,String> wrapper = template.queryColumns("cskey1"); assertEquals("value1",wrapper.getString("stringval")); assertEquals(date,wrapper.getDate("curdate")); assertEquals(new Long(5),wrapper.getLong("longval")); assertEquals(3,wrapper.getColumnNames().size()); }
ColumnFamilyTemplate<K, ByteBuffer> template = new ThriftColumnFamilyTemplate<K, ByteBuffer>(this.keyspace, this.cf, this.keySerializer, this.bs); Mutator<K> mutator = HFactory.createMutator(this.keyspace, this.keySerializer, new BatchSizeHint(1, this.mutateInterval)); ColumnFamilyUpdater<K, ByteBuffer> updater = template.createUpdater(this.destinationKey, mutator);
final float EPSILON = 0.0000001f; ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se);
@Test public void testTtl() throws InterruptedException { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace,"Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("test_ttl_key1"); updater.setString("expired_string", "value1",1); updater.setString("unexpired_string", "value2"); updater.setBoolean("unexpired_bool", true); updater.setBoolean("expired_bool", true, 1); template.update(updater); Thread.sleep(1000); ColumnFamilyResult<String,String> wrapper = template.queryColumns("test_ttl_key1"); HColumn<String,ByteBuffer> col = wrapper.getColumn("unexpired_string"); assertNotNull(col); assertNotNull(col.getValue()); HColumn<String,ByteBuffer> expiredStringCol = wrapper.getColumn("expired_string"); assertNull(expiredStringCol); HColumn<String,ByteBuffer> expiredBooleanCol = wrapper.getColumn("expired_bool"); assertNull(expiredBooleanCol); }
@Test public void testOverloadedMapRowCallback() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("key1"); updater.setString("column1","value1"); updater.addKey("key2"); updater.setString("column1", "value2"); template.update(updater); template.setCount(10); MappedColumnFamilyResult<String,String,String> result = template.queryColumns(Arrays.asList("key1","key2"), new ColumnFamilyRowMapper<String, String, String>() { @Override public String mapRow(ColumnFamilyResult<String, String> results) { return results.getString("column1"); } }); assertEquals("key1",result.getKey()); assertEquals("value1", result.getRow()); result.next(); assertEquals("key2",result.getKey()); assertEquals("value2", result.getRow()); }
@Test public void testQueryMultiget() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("mg_key1"); updater.setString("column1","value1"); updater.addKey("mg_key2"); updater.setString("column1","value2"); updater.addKey("mg_key3"); updater.setString("column1","value3"); template.update(updater); template.addColumn("column1", se); ColumnFamilyResult<String,String> wrapper = template.queryColumns(Arrays.asList("mg_key1", "mg_key2", "mg_key3")); assertEquals("value1",wrapper.getString("column1")); wrapper.next(); assertEquals("value2",wrapper.getString("column1")); wrapper.next(); assertEquals("value3",wrapper.getString("column1")); }
@Test public void testCreateSelectSpecifiedColumn() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("csskey1"); updater.setString("col1","value1"); updater.setString("col2","value2"); updater.setString("col3","value3"); updater.setString("col4","value4"); updater.setString("col5","value5"); template.update(updater); template.addColumn("stringval", se); template.addColumn("curdate", DateSerializer.get()); template.addColumn("longval", LongSerializer.get()); ColumnFamilyResult<String,String> wrapper = template.queryColumns("csskey1", Arrays.asList("col1", "col3", "col5")); assertEquals("value1",wrapper.getString("col1")); assertNull(wrapper.getString("col2")); assertEquals("value3",wrapper.getString("col3")); assertNull(wrapper.getString("col4")); assertEquals("value5",wrapper.getString("col5")); assertEquals(3,wrapper.getColumnNames().size()); }
@Test public void testQueryIndexedSlices() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Indexed1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("index_key1"); updater.setLong("birthyear", 1974L);
@Test public void testCompareClocks() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); long ts1 = 1001; long ts2 = 1002; long ts3 = 1003; ColumnFamilyUpdater<String,String> updater = template.createUpdater("compare_clock_key1"); updater.setClock(ts1); updater.setString("stringval","value1"); Date date = new Date(); updater.setClock(ts2); updater.setDate("curdate", date); updater.setClock(ts3); updater.setLong("longval", 5L); template.update(updater); template.addColumn("stringval", se); template.addColumn("curdate", DateSerializer.get()); template.addColumn("longval", LongSerializer.get()); ColumnFamilyResult wrapper = template.queryColumns("compare_clock_key1"); assertEquals(ts1,wrapper.getColumn("stringval").getClock()); assertEquals(ts2,wrapper.getColumn("curdate").getClock()); assertEquals(ts3,wrapper.getColumn("longval").getClock()); assertEquals(3,wrapper.getColumnNames().size()); }
@Override public void prepare( Map conf, TopologyContext context) { Cluster cluster = HFactory.getOrCreateCluster( "mycluster", "127.0.0.1"); Keyspace keyspace = HFactory.createKeyspace( "superwebanalytics", cluster); _template = new ThriftColumnFamilyTemplate<String, Integer>( keyspace, "uniques", StringSerializer.get(), IntegerSerializer.get()); }
@Test public void testQueryMultigetSpecificColumns() { ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, "Standard1", se, se); ColumnFamilyUpdater<String,String> updater = template.createUpdater("mgs_key1"); updater.setString("column1","value1-1");
new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // this.projectTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // this.artifactMetadataTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // cassandraArchivaManager.getArtifactMetadataFamilyName(), this.metadataFacetTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // cassandraArchivaManager.getMetadataFacetFamilyName(), this.mailingListTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // cassandraArchivaManager.getMailingListFamilyName(), this.licenseTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // cassandraArchivaManager.getLicenseFamilyName(), this.dependencyTemplate = new ThriftColumnFamilyTemplate<>( cassandraArchivaManager.getKeyspace(), // cassandraArchivaManager.getDependencyFamilyName(),
@Override public State makeState(Map conf, IMetricsContext context, int partitionIndex, int numPartitions) { Cluster cluster = HFactory.getOrCreateCluster( "mycluster", _connStr); Keyspace keyspace = HFactory.createKeyspace( _keyspace, cluster); ThriftColumnFamilyTemplate template = new ThriftColumnFamilyTemplate( keyspace, _columnFamily, _opts.keySerializer.getSerializer(), _opts.colSerializer.getSerializer()); CassandraState s = new CassandraState(template, _opts, _valueSer); CachedMap c = new CachedMap(s, _opts.localCacheSize); MapState ms; if(_type == StateType.NON_TRANSACTIONAL) { ms = NonTransactionalMap.build(c); } else if(_type==StateType.TRANSACTIONAL){ ms = TransactionalMap.build(c); } else { throw new RuntimeException("Unknown state type: " + _type); } return new SnapshottableMap(ms, new Values(_opts.globalKey)); }
ColumnFamilyTemplate<K, ByteBuffer> template = new ThriftColumnFamilyTemplate<K, ByteBuffer>(this.keyspace, this.cf, this.keySerializer, this.bs); Mutator<K> mutator = HFactory.createMutator(this.keyspace, this.keySerializer, new BatchSizeHint(1, this.mutateInterval)); ColumnFamilyUpdater<K, ByteBuffer> updater = template.createUpdater(this.destinationKey, mutator);