for (Entry ent : mutation.getAdditions()) { ColumnOrSuperColumn cosc = new ColumnOrSuperColumn(); Column column = new Column(ent.getColumnAs(StaticBuffer.BB_FACTORY)); column.setValue(ent.getValueAs(StaticBuffer.BB_FACTORY));
public HColumnImpl(Serializer<N> nameSerializer, Serializer<V> valueSerializer) { notNull(nameSerializer, "nameSerializer is null"); notNull(valueSerializer, "valueSerializer is null"); this.nameSerializer = nameSerializer; this.valueSerializer = valueSerializer; this.column = new Column(); }
@Test public void casDoesNotUpdateMetrics() throws TException, LimitExceededException { client.cas(TEST_TABLE, ByteBuffer.allocate(1), ImmutableList.of(new Column()), ImmutableList.of(new Column()), ConsistencyLevel.SERIAL, ConsistencyLevel.SERIAL); verify(mockClient, times(1)).cas(TEST_TABLE, ByteBuffer.allocate(1), ImmutableList.of(new Column()), ImmutableList.of(new Column()), ConsistencyLevel.SERIAL, ConsistencyLevel.SERIAL); verifyNoMoreInteractions(mockClient); verifyNoMoreInteractions(mockMetrics); } }
private Column makeColumn(long ts) { Column col = new Column(); col.setName(getColumnName()); col.setValue(PtBytes.toBytes(ts)); col.setTimestamp(CASSANDRA_TIMESTAMP); return col; }
@Test public void passesCqlQueriesAndResultsToAndFromDelegate() throws TException { ByteBuffer byteBuffer = ByteBuffer.allocate(1); CqlResult standardCqlResult = new CqlResult(CqlResultType.ROWS) .setRows(ImmutableList.of(new CqlRow(byteBuffer, ImmutableList.of(new Column(byteBuffer))))); setDelegateResponseToCqlQuery(standardCqlResult); assertThat(executeCqlQuery()).isEqualTo(standardCqlResult); verifyCqlQueryWasExecuted(); }
public HColumnImpl(N name, V value, long clock, Serializer<N> nameSerializer, Serializer<V> valueSerializer) { this(nameSerializer, valueSerializer); notNull(name, "name is null"); notNull(value, "value is null"); this.column = new Column(nameSerializer.toByteBuffer(name)); this.column.setValue(valueSerializer.toByteBuffer(value)); this.column.setTimestamp(clock); }
@Test public void getSizeForColumnOrSuperColumnWithAnEmptyColumn() { assertThat(ThriftObjectSizeUtils.getColumnOrSuperColumnSize(new ColumnOrSuperColumn().setColumn(new Column()))) .isEqualTo(NULL_SIZE * 8); }
/** * Populates foreign key as column. * * @param rlName * relation name * @param rlValue * relation value * @param timestamp * the timestamp * @return the column * @throws PropertyAccessException * the property access exception */ protected Column populateFkey(String rlName, Object rlValue, long timestamp) throws PropertyAccessException { Column col = new Column(); col.setName(PropertyAccessorFactory.STRING.toBytes(rlName)); col.setValue(PropertyAccessorHelper.getBytes(rlValue)); col.setTimestamp(timestamp); return col; }
private static Column createColumnAtSpecificCassandraTimestamp(Cell cell, Value value, long cassandraTimestamp) { byte[] contents = value.getContents(); long atlasTimestamp = value.getTimestamp(); ByteBuffer colName = makeCompositeBuffer(cell.getColumnName(), atlasTimestamp); Column col = new Column(); col.setName(colName); col.setValue(contents); col.setTimestamp(cassandraTimestamp); return col; }
private static Column createColumn(String name, byte[] value) { Column column = new Column(); column.setName(PtBytes.toBytes(name)); column.setValue(value); return column; } }
@Test public void handlesNullMultigetSliceResponseFromDelegate() throws TException { ByteBuffer byteBuffer = ByteBuffer.wrap(PtBytes.toBytes("foo")); List<ColumnOrSuperColumn> columns = ImmutableList.of( new ColumnOrSuperColumn().setColumn(new Column(byteBuffer))); ImmutableMap<ByteBuffer, List<ColumnOrSuperColumn>> resultMap = ImmutableMap.of(byteBuffer, columns); when(delegate.multiget_slice(any(), any(), any(), any(), any())).thenReturn(resultMap); assertThat(delegate.multiget_slice( "getRows", TableReference.createFromFullyQualifiedName("a.b"), ImmutableList.of(byteBuffer), new SlicePredicate(), ConsistencyLevel.QUORUM)).isEqualTo(resultMap); verify(delegate).multiget_slice( "getRows", TableReference.createFromFullyQualifiedName("a.b"), ImmutableList.of(byteBuffer), new SlicePredicate(), ConsistencyLevel.QUORUM); }
@Test public void testAddInsertionWithHint() { BatchMutation<String> batchMutate = new BatchMutation<String>(StringSerializer.get(), new BatchSizeHint(1, 50)); Column column = new Column(StringSerializer.get().toByteBuffer("c_name")); column.setValue(StringSerializer.get().toByteBuffer("c_val")); column.setTimestamp(System.currentTimeMillis()); batchMutate.addInsertion("key1", columnFamilies, column); Map<ByteBuffer, Map<String, List<Mutation>>> mutMap = batchMutate.getMutationMap(); assertEquals(1, mutMap.size()); assertEquals(ByteBuffer.wrap("key1".getBytes()), mutMap.keySet().iterator().next()); Map<String, List<Mutation>> cfMutMap = mutMap.values().iterator().next(); assertEquals(1, cfMutMap.size()); List<Mutation> cfMutList = cfMutMap.values().iterator().next(); assertTrue(cfMutList instanceof ArrayList); }
@Override public void insert(String key, ColumnPath columnPath, ByteBuffer value, long timestamp) throws HectorException { // valideColumnPath(columnPath); ColumnParent columnParent = new ColumnParent(columnPath.getColumn_family()); if (columnPath.isSetSuper_column()) { columnParent.setSuper_column(columnPath.getSuper_column()); } Column column = new Column(ByteBuffer.wrap(columnPath.getColumn())); column.setValue(value); column.setTimestamp(timestamp); insert(StringSerializer.get().toByteBuffer(key), columnParent, column); }
@Test public void testMultiCallOnByteBuffer() { List<Column> tColumns = new ArrayList<Column>(); Column column = new Column(se.toByteBuffer("1")); column.setValue(ByteBuffer.wrap("colvalue".getBytes())); column.setTimestamp(0L); tColumns.add(column); ColumnSlice<String, ByteBuffer> slice = new ColumnSliceImpl<String, ByteBuffer>(tColumns, se, ByteBufferSerializer.get()); ByteBuffer value = slice.getColumnByName("1").getValue(); Assert.assertEquals("colvalue", se.fromByteBuffer(value)); value.rewind(); Assert.assertEquals("colvalue", se.fromByteBuffer(value)); value.rewind(); Assert.assertEquals("colvalue", se.fromByteBuffer(value)); } }
@Test public void testConstruction() { List<Column> tColumns = new ArrayList<Column>(); ColumnSlice<String, Long> slice = new ColumnSliceImpl<String, Long>(tColumns, se, le); Assert.assertTrue(slice.getColumns().isEmpty()); Column column = new Column(ByteBuffer.wrap(new byte[]{})); column.setValue(ByteBuffer.wrap(new byte[]{})); column.setTimestamp(0L); tColumns.add(column); slice = new ColumnSliceImpl<String, Long>(tColumns, se, le); Assert.assertEquals(1, slice.getColumns().size()); tColumns = new ArrayList<Column>(); column = new Column(se.toByteBuffer("1")); column.setValue(le.toByteBuffer(1L)); column.setTimestamp(0L); tColumns.add(column); slice = new ColumnSliceImpl<String, Long>(tColumns, se, le); Assert.assertEquals((Long) 1L, slice.getColumnByName("1").getValue()); }
@Override public void insert(String key, ColumnPath columnPath, ByteBuffer value) throws HectorException { // valideColumnPath(columnPath); ColumnParent columnParent = new ColumnParent(columnPath.getColumn_family()); if (columnPath.isSetSuper_column()) { columnParent.setSuper_column(columnPath.getSuper_column()); } Column column = new Column(ByteBuffer.wrap(columnPath.getColumn())); column.setValue(value); column.setTimestamp(connectionManager.createClock()); insert(StringSerializer.get().toByteBuffer(key), columnParent, column); }
@Test public void testConstruction() { LongSerializer le = LongSerializer.get(); StringSerializer se = StringSerializer.get(); ByteBufferSerializer be = ByteBufferSerializer.get(); // empty one List<SuperColumn> tColumns = new ArrayList<SuperColumn>(); SuperSlice<String, Long, ByteBuffer> slice = new SuperSliceImpl<String, Long, ByteBuffer>(tColumns, se, le, be); Assert.assertTrue(slice.getSuperColumns().isEmpty()); // non-empty one Column c = new Column(le.toByteBuffer(5L)); c.setValue(be.toByteBuffer(ByteBuffer.wrap(new byte[] { 1 }))); c.setTimestamp(2L); tColumns.add(new SuperColumn(se.toByteBuffer("super"), Arrays.asList(c))); slice = new SuperSliceImpl<String, Long, ByteBuffer>(tColumns, se, le, be); Assert.assertEquals(1, slice.getSuperColumns().size()); Assert.assertEquals((Long) 5L, slice.getColumnByName("super").get(0).getName()); } }
@Test public void testAddInsertion() { Column column = new Column(StringSerializer.get().toByteBuffer("c_name")); column.setValue(StringSerializer.get().toByteBuffer("c_val")); column.setTimestamp(System.currentTimeMillis()); batchMutate.addInsertion("key1", columnFamilies, column); // assert there is one outter map row with 'key' as the key Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap = batchMutate.getMutationMap(); assertEquals(1, mutationMap.get(StringSerializer.get().toByteBuffer("key1")).size()); // add again with a different column and verify there is one key and two mutations underneath // for "standard1" Column column2 = new Column(StringSerializer.get().toByteBuffer("c_name2")); column2.setValue(StringSerializer.get().toByteBuffer("c_val2")); column2.setTimestamp(System.currentTimeMillis()); batchMutate.addInsertion("key1",columnFamilies, column2); assertEquals(2, mutationMap.get(StringSerializer.get().toByteBuffer("key1")).get("Standard1").size()); }
@Test public void testAddSuperInsertion() { Column column = new Column(StringSerializer.get().toByteBuffer("c_name")); column.setValue(StringSerializer.get().toByteBuffer("c_val")); column.setTimestamp(System.currentTimeMillis()); SuperColumn sc = new SuperColumn(StringSerializer.get().toByteBuffer("c_name"), Arrays.asList(column)); batchMutate.addSuperInsertion("key1", columnFamilies, sc); // assert there is one outter map row with 'key' as the key assertEquals(1, batchMutate.getMutationMap().get(StringSerializer.get().toByteBuffer("key1")).size()); // add again with a different column and verify there is one key and two mutations underneath // for "standard1" column = new Column(StringSerializer.get().toByteBuffer("c_name")); column.setValue(StringSerializer.get().toByteBuffer("c_val")); column.setTimestamp(System.currentTimeMillis()); SuperColumn sc2 = new SuperColumn(StringSerializer.get().toByteBuffer("c_name2"), Arrays.asList(column)); batchMutate.addSuperInsertion("key1", columnFamilies, sc2); assertEquals(2, batchMutate.getMutationMap().get(StringSerializer.get().toByteBuffer("key1")).get("Standard1").size()); }
@Test public void testIsEmpty() { assertTrue(batchMutate.isEmpty()); // Insert a column Column c1 = new Column(StringSerializer.get().toByteBuffer("c_name")); c1.setValue(StringSerializer.get().toByteBuffer("c_val")); c1.setTimestamp(System.currentTimeMillis()); batchMutate.addInsertion("key1", columnFamilies, c1); assertFalse(batchMutate.isEmpty()); // Insert a Counter. CounterColumn cc1 = new CounterColumn(StringSerializer.get().toByteBuffer("c_name"), 13); batchMutate.addCounterInsertion("key1", columnFamilies, cc1); assertFalse(batchMutate.isEmpty()); }