use of com.scalar.db.io.BigIntValue in project scalardb by scalar-labs.
the class CoordinatorTest method getState_WithCoordinatorNamespaceChanged_ShouldGetWithChangedNamespace.
@Test
public void getState_WithCoordinatorNamespaceChanged_ShouldGetWithChangedNamespace() throws ExecutionException, CoordinatorException {
// Arrange
when(config.getCoordinatorNamespace()).thenReturn(Optional.of("changed_coordinator"));
coordinator = new Coordinator(storage, config);
Result result = mock(Result.class);
when(result.getValue(Attribute.ID)).thenReturn(Optional.of(new TextValue(Attribute.ID, ANY_ID_1)));
when(result.getValue(Attribute.STATE)).thenReturn(Optional.of(new IntValue(Attribute.STATE, TransactionState.COMMITTED.get())));
when(result.getValue(Attribute.CREATED_AT)).thenReturn(Optional.of(new BigIntValue(Attribute.CREATED_AT, ANY_TIME_1)));
when(storage.get(any(Get.class))).thenReturn(Optional.of(result));
// Act
Optional<Coordinator.State> state = coordinator.getState(ANY_ID_1);
// Assert
ArgumentCaptor<Get> captor = ArgumentCaptor.forClass(Get.class);
verify(storage).get(captor.capture());
assertThat(captor.getValue().forNamespace().get()).isEqualTo("changed_coordinator");
assertThat(captor.getValue().forTable().get()).isEqualTo(Coordinator.TABLE);
assertThat(state.get().getId()).isEqualTo(ANY_ID_1);
Assertions.assertThat(state.get().getState()).isEqualTo(TransactionState.COMMITTED);
assertThat(state.get().getCreatedAt()).isEqualTo(ANY_TIME_1);
}
use of com.scalar.db.io.BigIntValue in project scalardb by scalar-labs.
the class PutTest method withValue_ProperValuesGiven_ShouldReturnWhatsSet.
@Test
public void withValue_ProperValuesGiven_ShouldReturnWhatsSet() {
// Arrange
Put put = preparePut();
// Act
put.withValue("val1", true).withValue("val2", 5678).withValue("val3", 1234L).withValue("val4", 4.56f).withValue("val5", 1.23).withValue("val6", "string_value").withValue("val7", "blob_value".getBytes(StandardCharsets.UTF_8)).withValue("val8", ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
// Assert
Map<String, Value<?>> values = put.getValues();
assertThat(values.size()).isEqualTo(8);
assertThat(values.get("val1")).isEqualTo(new BooleanValue("val1", true));
assertThat(values.get("val2")).isEqualTo(new IntValue("val2", 5678));
assertThat(values.get("val3")).isEqualTo(new BigIntValue("val3", 1234L));
assertThat(values.get("val4")).isEqualTo(new FloatValue("val4", 4.56f));
assertThat(values.get("val5")).isEqualTo(new DoubleValue("val5", 1.23));
assertThat(values.get("val6")).isEqualTo(new TextValue("val6", "string_value"));
assertThat(values.get("val7")).isEqualTo(new BlobValue("val7", "blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(values.get("val8")).isEqualTo(new BlobValue("val8", "blob_value2".getBytes(StandardCharsets.UTF_8)));
Map<String, Column<?>> columns = put.getColumns();
assertThat(columns.size()).isEqualTo(8);
assertThat(columns.get("val1")).isEqualTo(BooleanColumn.of("val1", true));
assertThat(columns.get("val2")).isEqualTo(IntColumn.of("val2", 5678));
assertThat(columns.get("val3")).isEqualTo(BigIntColumn.of("val3", 1234L));
assertThat(columns.get("val4")).isEqualTo(FloatColumn.of("val4", 4.56f));
assertThat(columns.get("val5")).isEqualTo(DoubleColumn.of("val5", 1.23));
assertThat(columns.get("val6")).isEqualTo(TextColumn.of("val6", "string_value"));
assertThat(columns.get("val7")).isEqualTo(BlobColumn.of("val7", "blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(columns.get("val8")).isEqualTo(BlobColumn.of("val8", "blob_value2".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getContainedColumnNames()).isEqualTo(ImmutableSet.of("val1", "val2", "val3", "val4", "val5", "val6", "val7", "val8"));
assertThat(put.containsColumn("val1")).isTrue();
assertThat(put.isNullValue("val1")).isFalse();
assertThat(put.getBooleanValue("val1")).isTrue();
assertThat(put.getValueAsObject("val1")).isEqualTo(true);
assertThat(put.containsColumn("val2")).isTrue();
assertThat(put.isNullValue("val2")).isFalse();
assertThat(put.getIntValue("val2")).isEqualTo(5678);
assertThat(put.getValueAsObject("val2")).isEqualTo(5678);
assertThat(put.containsColumn("val3")).isTrue();
assertThat(put.isNullValue("val3")).isFalse();
assertThat(put.getBigIntValue("val3")).isEqualTo(1234L);
assertThat(put.getValueAsObject("val3")).isEqualTo(1234L);
assertThat(put.containsColumn("val4")).isTrue();
assertThat(put.isNullValue("val4")).isFalse();
assertThat(put.getFloatValue("val4")).isEqualTo(4.56f);
assertThat(put.getValueAsObject("val4")).isEqualTo(4.56f);
assertThat(put.containsColumn("val5")).isTrue();
assertThat(put.isNullValue("val5")).isFalse();
assertThat(put.getDoubleValue("val5")).isEqualTo(1.23);
assertThat(put.getValueAsObject("val5")).isEqualTo(1.23);
assertThat(put.containsColumn("val6")).isTrue();
assertThat(put.isNullValue("val6")).isFalse();
assertThat(put.getTextValue("val6")).isEqualTo("string_value");
assertThat(put.getValueAsObject("val6")).isEqualTo("string_value");
assertThat(put.containsColumn("val7")).isTrue();
assertThat(put.isNullValue("val7")).isFalse();
assertThat(put.getBlobValue("val7")).isEqualTo(ByteBuffer.wrap("blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getBlobValueAsByteBuffer("val7")).isEqualTo(ByteBuffer.wrap("blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getBlobValueAsBytes("val7")).isEqualTo("blob_value".getBytes(StandardCharsets.UTF_8));
assertThat(put.getValueAsObject("val7")).isEqualTo(ByteBuffer.wrap("blob_value".getBytes(StandardCharsets.UTF_8)));
assertThat(put.containsColumn("val8")).isTrue();
assertThat(put.isNullValue("val8")).isFalse();
assertThat(put.getBlobValue("val8")).isEqualTo(ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getBlobValueAsByteBuffer("val8")).isEqualTo(ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
assertThat(put.getBlobValueAsBytes("val8")).isEqualTo("blob_value2".getBytes(StandardCharsets.UTF_8));
assertThat(put.getValueAsObject("val8")).isEqualTo(ByteBuffer.wrap("blob_value2".getBytes(StandardCharsets.UTF_8)));
}
use of com.scalar.db.io.BigIntValue in project scalardb by scalar-labs.
the class StorageColumnValueIntegrationTestBase method put_WithNullValues_ShouldPutCorrectly.
@Test
public void put_WithNullValues_ShouldPutCorrectly() throws ExecutionException {
// Arrange
IntValue partitionKeyValue = new IntValue(PARTITION_KEY, 1);
BooleanValue col1Value = new BooleanValue(COL_NAME1, false);
IntValue col2Value = new IntValue(COL_NAME2, 0);
BigIntValue col3Value = new BigIntValue(COL_NAME3, 0L);
FloatValue col4Value = new FloatValue(COL_NAME4, 0.0f);
DoubleValue col5Value = new DoubleValue(COL_NAME5, 0.0d);
TextValue col6Value = new TextValue(COL_NAME6, (String) null);
BlobValue col7Value = new BlobValue(COL_NAME7, (byte[]) null);
Put put = new Put(new Key(partitionKeyValue)).withNullValue(COL_NAME1).withNullValue(COL_NAME2).withNullValue(COL_NAME3).withNullValue(COL_NAME4).withNullValue(COL_NAME5).withNullValue(COL_NAME6).withNullValue(COL_NAME7).forNamespace(namespace).forTable(TABLE);
// Act
storage.put(put);
// Assert
Optional<Result> actual = storage.get(new Get(new Key(partitionKeyValue)).forNamespace(namespace).forTable(TABLE));
assertThat(actual).isPresent();
assertThat(actual.get().getValue(PARTITION_KEY).isPresent()).isTrue();
assertThat(actual.get().getValue(PARTITION_KEY).get()).isEqualTo(partitionKeyValue);
assertThat(actual.get().getValue(COL_NAME1).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME1).get()).isEqualTo(col1Value);
assertThat(actual.get().getValue(COL_NAME2).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME2).get()).isEqualTo(col2Value);
assertThat(actual.get().getValue(COL_NAME3).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME3).get()).isEqualTo(col3Value);
assertThat(actual.get().getValue(COL_NAME4).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME4).get()).isEqualTo(col4Value);
assertThat(actual.get().getValue(COL_NAME5).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME5).get()).isEqualTo(col5Value);
assertThat(actual.get().getValue(COL_NAME6).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME6).get()).isEqualTo(col6Value);
assertThat(actual.get().getValue(COL_NAME7).isPresent()).isTrue();
assertThat(actual.get().getValue(COL_NAME7).get()).isEqualTo(col7Value);
assertThat(actual.get().getContainedColumnNames()).isEqualTo(new HashSet<>(Arrays.asList(PARTITION_KEY, COL_NAME1, COL_NAME2, COL_NAME3, COL_NAME4, COL_NAME5, COL_NAME6, COL_NAME7)));
assertThat(actual.get().contains(PARTITION_KEY)).isTrue();
assertThat(actual.get().isNull(PARTITION_KEY)).isFalse();
assertThat(actual.get().getInt(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
assertThat(actual.get().getAsObject(PARTITION_KEY)).isEqualTo(partitionKeyValue.get());
assertThat(actual.get().contains(COL_NAME1)).isTrue();
assertThat(actual.get().isNull(COL_NAME1)).isTrue();
assertThat(actual.get().getBoolean(COL_NAME1)).isEqualTo(col1Value.get());
assertThat(actual.get().getAsObject(COL_NAME1)).isNull();
assertThat(actual.get().contains(COL_NAME2)).isTrue();
assertThat(actual.get().isNull(COL_NAME2)).isTrue();
assertThat(actual.get().getInt(COL_NAME2)).isEqualTo(col2Value.get());
assertThat(actual.get().getAsObject(COL_NAME2)).isNull();
assertThat(actual.get().contains(COL_NAME3)).isTrue();
assertThat(actual.get().isNull(COL_NAME3)).isTrue();
assertThat(actual.get().getBigInt(COL_NAME3)).isEqualTo(col3Value.get());
assertThat(actual.get().getAsObject(COL_NAME3)).isNull();
assertThat(actual.get().contains(COL_NAME4)).isTrue();
assertThat(actual.get().isNull(COL_NAME4)).isTrue();
assertThat(actual.get().getFloat(COL_NAME4)).isEqualTo(col4Value.get());
assertThat(actual.get().getAsObject(COL_NAME4)).isNull();
assertThat(actual.get().contains(COL_NAME5)).isTrue();
assertThat(actual.get().isNull(COL_NAME5)).isTrue();
assertThat(actual.get().getDouble(COL_NAME5)).isEqualTo(col5Value.get());
assertThat(actual.get().getAsObject(COL_NAME5)).isNull();
assertThat(actual.get().contains(COL_NAME6)).isTrue();
assertThat(actual.get().isNull(COL_NAME6)).isTrue();
assertThat(actual.get().getText(COL_NAME6)).isNull();
assertThat(actual.get().getAsObject(COL_NAME6)).isNull();
assertThat(actual.get().contains(COL_NAME7)).isTrue();
assertThat(actual.get().isNull(COL_NAME7)).isTrue();
assertThat(actual.get().getBlob(COL_NAME7)).isNull();
assertThat(actual.get().getBlobAsByteBuffer(COL_NAME7)).isNull();
assertThat(actual.get().getBlobAsBytes(COL_NAME7)).isNull();
assertThat(actual.get().getAsObject(COL_NAME7)).isNull();
}
use of com.scalar.db.io.BigIntValue in project scalardb by scalar-labs.
the class ConditionExpressionTest method constructor_ProperArgsGiven_ShouldConstructProperly.
@Test
public void constructor_ProperArgsGiven_ShouldConstructProperly() {
// Arrange
// Act
ConditionalExpression expression1 = new ConditionalExpression("col1", new TextValue("aaa"), Operator.EQ);
ConditionalExpression expression2 = new ConditionalExpression("col2", true, Operator.EQ);
ConditionalExpression expression3 = new ConditionalExpression("col3", 123, Operator.NE);
ConditionalExpression expression4 = new ConditionalExpression("col4", 456L, Operator.GT);
ConditionalExpression expression5 = new ConditionalExpression("col5", 1.23F, Operator.GTE);
ConditionalExpression expression6 = new ConditionalExpression("col6", 4.56D, Operator.LT);
ConditionalExpression expression7 = new ConditionalExpression("col7", "text", Operator.LTE);
ConditionalExpression expression8 = new ConditionalExpression("col8", "blob".getBytes(StandardCharsets.UTF_8), Operator.EQ);
ConditionalExpression expression9 = new ConditionalExpression("col9", ByteBuffer.wrap("blob2".getBytes(StandardCharsets.UTF_8)), Operator.NE);
// Assert
assertThat(expression1.getColumnName()).isEqualTo("col1");
assertThat(expression1.getValue()).isEqualTo(new TextValue("aaa"));
assertThat(expression1.getTextValue()).isEqualTo("aaa");
assertThat(expression1.getValueAsObject()).isEqualTo("aaa");
assertThat(expression1.getOperator()).isEqualTo(Operator.EQ);
assertThat(expression2.getColumnName()).isEqualTo("col2");
assertThat(expression2.getValue()).isEqualTo(new BooleanValue(true));
assertThat(expression2.getBooleanValue()).isTrue();
assertThat(expression2.getValueAsObject()).isEqualTo(true);
assertThat(expression2.getOperator()).isEqualTo(Operator.EQ);
assertThat(expression3.getColumnName()).isEqualTo("col3");
assertThat(expression3.getValue()).isEqualTo(new IntValue(123));
assertThat(expression3.getIntValue()).isEqualTo(123);
assertThat(expression3.getValueAsObject()).isEqualTo(123);
assertThat(expression3.getOperator()).isEqualTo(Operator.NE);
assertThat(expression4.getColumnName()).isEqualTo("col4");
assertThat(expression4.getValue()).isEqualTo(new BigIntValue(456L));
assertThat(expression4.getBigIntValue()).isEqualTo(456L);
assertThat(expression4.getValueAsObject()).isEqualTo(456L);
assertThat(expression4.getOperator()).isEqualTo(Operator.GT);
assertThat(expression5.getColumnName()).isEqualTo("col5");
assertThat(expression5.getValue()).isEqualTo(new FloatValue(1.23F));
assertThat(expression5.getFloatValue()).isEqualTo(1.23F);
assertThat(expression5.getValueAsObject()).isEqualTo(1.23F);
assertThat(expression5.getOperator()).isEqualTo(Operator.GTE);
assertThat(expression6.getColumnName()).isEqualTo("col6");
assertThat(expression6.getValue()).isEqualTo(new DoubleValue(4.56D));
assertThat(expression6.getDoubleValue()).isEqualTo(4.56D);
assertThat(expression6.getValueAsObject()).isEqualTo(4.56D);
assertThat(expression6.getOperator()).isEqualTo(Operator.LT);
assertThat(expression7.getColumnName()).isEqualTo("col7");
assertThat(expression7.getValue()).isEqualTo(new TextValue("text"));
assertThat(expression7.getTextValue()).isEqualTo("text");
assertThat(expression7.getValueAsObject()).isEqualTo("text");
assertThat(expression7.getOperator()).isEqualTo(Operator.LTE);
assertThat(expression8.getColumnName()).isEqualTo("col8");
assertThat(expression8.getValue()).isEqualTo(new BlobValue("blob".getBytes(StandardCharsets.UTF_8)));
assertThat(expression8.getBlobValue()).isEqualTo(ByteBuffer.wrap("blob".getBytes(StandardCharsets.UTF_8)));
assertThat(expression8.getBlobValueAsByteBuffer()).isEqualTo(ByteBuffer.wrap("blob".getBytes(StandardCharsets.UTF_8)));
assertThat(expression8.getBlobValueAsBytes()).isEqualTo("blob".getBytes(StandardCharsets.UTF_8));
assertThat(expression8.getValueAsObject()).isEqualTo(ByteBuffer.wrap("blob".getBytes(StandardCharsets.UTF_8)));
assertThat(expression8.getOperator()).isEqualTo(Operator.EQ);
assertThat(expression9.getColumnName()).isEqualTo("col9");
assertThat(expression9.getValue()).isEqualTo(new BlobValue("blob2".getBytes(StandardCharsets.UTF_8)));
assertThat(expression9.getBlobValue()).isEqualTo(ByteBuffer.wrap("blob2".getBytes(StandardCharsets.UTF_8)));
assertThat(expression9.getBlobValueAsByteBuffer()).isEqualTo(ByteBuffer.wrap("blob2".getBytes(StandardCharsets.UTF_8)));
assertThat(expression9.getBlobValueAsBytes()).isEqualTo("blob2".getBytes(StandardCharsets.UTF_8));
assertThat(expression9.getValueAsObject()).isEqualTo(ByteBuffer.wrap("blob2".getBytes(StandardCharsets.UTF_8)));
assertThat(expression9.getOperator()).isEqualTo(Operator.NE);
}
use of com.scalar.db.io.BigIntValue in project scalardb by scalar-labs.
the class ValueBinderTest method visit_BigIntValueAcceptCalled_ShouldCallSetLong.
@Test
public void visit_BigIntValueAcceptCalled_ShouldCallSetLong() {
// Arrange
BigIntValue value = new BigIntValue(ANY_NAME, ANY_LONG);
ValueBinder binder = new ValueBinder(bound);
// Act
value.accept(binder);
// Assert
verify(bound).setLong(0, ANY_LONG);
}
Aggregations