Search in sources :

Example 31 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerAsyncTest method shouldDeleteWithCallBack.

@Test
public void shouldDeleteWithCallBack() {
    AtomicBoolean callback = new AtomicBoolean(false);
    ColumnDeleteQuery deleteQuery = delete().from(COLUMN_FAMILY).where("id").eq(10L).build();
    columnEntityManager.delete(deleteQuery, v -> callback.set(true));
    await().untilTrue(callback);
    ColumnQuery query = select().from(COLUMN_FAMILY).where("id").eq(10L).build();
    AtomicReference<List<ColumnEntity>> entities = new AtomicReference<>(emptyList());
    callback.set(false);
    Consumer<List<ColumnEntity>> result = (l) -> {
        callback.set(true);
        entities.set(l);
    };
    columnEntityManager.select(query, result);
    await().untilTrue(callback);
    assertTrue(entities.get().isEmpty());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) EmbeddedCassandraServerHelper(org.cassandraunit.utils.EmbeddedCassandraServerHelper) TTransportException(org.apache.thrift.transport.TTransportException) Matchers.not(org.hamcrest.Matchers.not) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) ColumnQueryBuilder.delete(org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) Collections.singletonList(java.util.Collections.singletonList) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Arrays.asList(java.util.Arrays.asList) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Duration(java.time.Duration) Map(java.util.Map) Columns(org.jnosql.diana.api.column.Columns) Thread.sleep(java.lang.Thread.sleep) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) KEY_SPACE(org.jnosql.diana.cassandra.column.Constants.KEY_SPACE) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Awaitility.await(org.awaitility.Awaitility.await) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Collections.emptyList(java.util.Collections.emptyList) IOException(java.io.IOException) COLUMN_FAMILY(org.jnosql.diana.cassandra.column.Constants.COLUMN_FAMILY) Column(org.jnosql.diana.api.column.Column) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) ColumnQueryBuilder.select(org.jnosql.diana.api.column.query.ColumnQueryBuilder.select) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) ColumnDeleteQuery(org.jnosql.diana.api.column.ColumnDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 32 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerTest method shouldInsertWithTtl.

@Test
public void shouldInsertWithTtl() throws InterruptedException {
    ColumnEntity columnEntity = getColumnFamily();
    entityManager.insert(columnEntity, Duration.ofSeconds(1L));
    sleep(2_000L);
    List<ColumnEntity> entities = entityManager.select(select().from(COLUMN_FAMILY).where("id").eq(10L).build());
    assertTrue(entities.isEmpty());
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Example 33 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerTest method shouldFindByIdWithConsistenceLevel.

@Test
public void shouldFindByIdWithConsistenceLevel() {
    entityManager.insert(getColumnFamily());
    ColumnQuery query = select().from(COLUMN_FAMILY).where("id").eq(10L).build();
    List<ColumnEntity> columnEntity = entityManager.select(query, CONSISTENCY_LEVEL);
    assertFalse(columnEntity.isEmpty());
    List<Column> columns = columnEntity.get(0).getColumns();
    assertThat(columns.stream().map(Column::getName).collect(toList()), containsInAnyOrder("name", "version", "options", "id"));
    assertThat(columns.stream().map(Column::getValue).map(Value::get).collect(toList()), containsInAnyOrder("Cassandra", 3.2, asList(1, 2, 3), 10L));
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Column(org.jnosql.diana.api.column.Column) Value(org.jnosql.diana.api.Value) Test(org.junit.jupiter.api.Test)

Example 34 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerTest method shouldInsertColumnsWithConsistencyLevel.

@Test
public void shouldInsertColumnsWithConsistencyLevel() {
    ColumnEntity columnEntity = getColumnFamily();
    entityManager.save(columnEntity, CONSISTENCY_LEVEL);
}
Also used : ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Example 35 with ColumnEntity

use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-diana-driver by eclipse.

the class CassandraColumnFamilyManagerTest method shouldLimitResult.

@Test
public void shouldLimitResult() {
    getEntities().forEach(entityManager::insert);
    ColumnQuery query = select().from(COLUMN_FAMILY).where("id").in(Arrays.asList(1L, 2L, 3L)).limit(2).build();
    List<ColumnEntity> columnFamilyEntities = entityManager.select(query);
    assertEquals(Integer.valueOf(2), Integer.valueOf(columnFamilyEntities.size()));
}
Also used : ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) ColumnEntity(org.jnosql.diana.api.column.ColumnEntity) Test(org.junit.jupiter.api.Test)

Aggregations

ColumnEntity (org.jnosql.diana.api.column.ColumnEntity)88 Test (org.junit.jupiter.api.Test)76 ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)26 Column (org.jnosql.diana.api.column.Column)22 Arrays.asList (java.util.Arrays.asList)17 List (java.util.List)17 Consumer (java.util.function.Consumer)14 Collections.singletonList (java.util.Collections.singletonList)13 ColumnDeleteQuery (org.jnosql.diana.api.column.ColumnDeleteQuery)13 Person (org.jnosql.artemis.model.Person)12 Duration (java.time.Duration)11 Collections.emptyList (java.util.Collections.emptyList)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 ColumnQueryBuilder.delete (org.jnosql.diana.api.column.query.ColumnQueryBuilder.delete)9 ColumnQueryBuilder.select (org.jnosql.diana.api.column.query.ColumnQueryBuilder.select)9 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 ArrayList (java.util.ArrayList)8 Arrays (java.util.Arrays)8