Search in sources :

Example 51 with VTransactionWritable

use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.

the class BerkeleyKVStoreManagerTest method testTimeToLive.

@Test
public void testTimeToLive() {
    try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        final int nbFlowers = kvStoreManager.count("flowers");
        Assert.assertEquals(0, nbFlowers);
        // put a flower a t+0s (expire a T+10s)
        final Flower tulip1 = buildFlower("tulip", 100);
        kvStoreManager.put("flowers", "1", tulip1);
        sleep(2);
        // put a flower a t+2s (expire a T+12s)
        final Flower tulip2 = buildFlower("tulip", 110);
        kvStoreManager.put("flowers", "2", tulip2);
        sleep(2);
        // put a flower a t+4s (expire a T+14s)
        final Flower tulip3 = buildFlower("tulip", 120);
        kvStoreManager.put("flowers", "3", tulip3);
        sleep(2);
        // count after 3 inserts and T+6s
        // can't use count as it doesnt detect too old element (needs daemon)
        final long nbFlowers2 = kvStoreManager.findAll("flowers", 0, 1000, Flower.class).size();
        Assert.assertEquals(3, nbFlowers2);
        sleep(3);
        // find unexpired element
        final Optional<Flower> tulip1Load = kvStoreManager.find("flowers", "1", Flower.class);
        Assert.assertTrue(tulip1Load.isPresent());
        // count after 3 inserts and T+9s
        final long nbFlowers3 = kvStoreManager.findAll("flowers", 0, 1000, Flower.class).size();
        Assert.assertEquals(3, nbFlowers3);
        sleep(2);
        // count after 3 inserts and T+11s
        final long nbFlowers4 = kvStoreManager.findAll("flowers", 0, 1000, Flower.class).size();
        Assert.assertEquals(2, nbFlowers4);
        sleep(2);
        // count after 3 inserts and T+13s
        final long nbFlowers5 = kvStoreManager.findAll("flowers", 0, 1000, Flower.class).size();
        Assert.assertEquals(1, nbFlowers5);
        sleep(2);
        // count after 3 inserts and 15s
        final long nbFlowers6 = kvStoreManager.findAll("flowers", 0, 1000, Flower.class).size();
        Assert.assertEquals(0, nbFlowers6);
        // find expired element
        final Optional<Flower> tulip1Reload = kvStoreManager.find("flowers", "1", Flower.class);
        Assert.assertFalse(tulip1Reload.isPresent());
    }
}
Also used : Flower(io.vertigo.dynamo.kvstore.data.Flower) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) AbstractKVStoreManagerTest(io.vertigo.dynamo.kvstore.AbstractKVStoreManagerTest) Test(org.junit.Test)

Example 52 with VTransactionWritable

use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.

the class SuperHeroDataBase method populateSuperHero.

void populateSuperHero(final StoreManager storeManager, final int size) {
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        // -----
        for (int i = 0; i < size; i++) {
            final SuperHero superHero = new SuperHero();
            superHero.setName("SuperHero ( " + i + ")");
            storeManager.getDataStore().create(superHero);
        }
        transaction.commit();
    }
}
Also used : SuperHero(io.vertigo.dynamo.task.data.domain.SuperHero) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable)

Example 53 with VTransactionWritable

use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.

the class TaskEngineProcBatchTest method testInsertBatchWithAdditionalParam.

/**
 * Tests batch insertion with a task
 */
@Test
public void testInsertBatchWithAdditionalParam() {
    final String request = new StringBuilder("insert into SUPER_HERO(ID, NAME) values (").append("#").append(DTC_SUPER_HERO_IN + ".ID").append("# , ").append("#").append(OTHER_PARAM_IN).append("# ) ").toString();
    final TaskDefinition taskDefinition = TaskDefinition.builder("TK_TEST_INSERT_BATCH").withEngine(TaskEngineProcBatch.class).addInRequired(DTC_SUPER_HERO_IN, getApp().getDefinitionSpace().resolve(DO_DT_SUPER_HERO_DTC, Domain.class)).addInRequired(OTHER_PARAM_IN, getApp().getDefinitionSpace().resolve(DO_STRING, Domain.class)).withRequest(request).build();
    final DtList<SuperHero> superHeroes = SuperHeroDataBase.getSuperHeroes();
    final Task task = Task.builder(taskDefinition).addValue(DTC_SUPER_HERO_IN, superHeroes).addValue(OTHER_PARAM_IN, "test").build();
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        taskManager.execute(task);
        transaction.commit();
    }
    Assert.assertEquals(superHeroes.size(), selectHeroes().size());
}
Also used : SuperHero(io.vertigo.dynamo.task.data.domain.SuperHero) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Domain(io.vertigo.dynamo.domain.metamodel.Domain) Test(org.junit.Test)

Example 54 with VTransactionWritable

use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.

the class TaskEngineProcBatchTest method selectHeroes.

private DtList<SuperHero> selectHeroes() {
    final TaskDefinition taskDefinition = TaskDefinition.builder("TK_SELECT_HEROES").withEngine(TaskEngineSelect.class).withRequest("select * from SUPER_HERO").withOutRequired(DTC_SUPER_HERO_OUT, getApp().getDefinitionSpace().resolve(DO_DT_SUPER_HERO_DTC, Domain.class)).build();
    final Task task = Task.builder(taskDefinition).build();
    try (VTransactionWritable tx = transactionManager.createCurrentTransaction()) {
        return taskManager.execute(task).getResult();
    }
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable)

Example 55 with VTransactionWritable

use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.

the class TaskEngineProcBatchTest method testInsertBatchPrimitive.

/**
 * Tests batch insertion with a task
 */
@Test
public void testInsertBatchPrimitive() {
    final String request = new StringBuilder("insert into SUPER_HERO(ID, NAME) values (").append("#").append(SUPER_HERO_ID_LIST_IN).append("# , 'test' ").append(" )").toString();
    final TaskDefinition taskDefinition = TaskDefinition.builder("TK_TEST_INSERT_BATCH").withEngine(TaskEngineProcBatch.class).addInRequired(SUPER_HERO_ID_LIST_IN, getApp().getDefinitionSpace().resolve(DO_LONGS, Domain.class)).withRequest(request).build();
    final List<Long> superHeroesIds = SuperHeroDataBase.getSuperHeroes().stream().map(superHero -> superHero.getId()).collect(Collectors.toList());
    final Task task = Task.builder(taskDefinition).addValue(SUPER_HERO_ID_LIST_IN, superHeroesIds).build();
    try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
        taskManager.execute(task);
        transaction.commit();
    }
    Assert.assertEquals(superHeroesIds.size(), selectHeroes().size());
}
Also used : TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) AbstractTestCaseJU4(io.vertigo.AbstractTestCaseJU4) Test(org.junit.Test) Domain(io.vertigo.dynamo.domain.metamodel.Domain) Task(io.vertigo.dynamo.task.model.Task) DtList(io.vertigo.dynamo.domain.model.DtList) Collectors(java.util.stream.Collectors) VTransactionManager(io.vertigo.commons.transaction.VTransactionManager) TaskEngineProcBatch(io.vertigo.dynamox.task.TaskEngineProcBatch) Inject(javax.inject.Inject) SuperHero(io.vertigo.dynamo.task.data.domain.SuperHero) List(java.util.List) TaskManager(io.vertigo.dynamo.task.TaskManager) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) Assert(org.junit.Assert) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) Task(io.vertigo.dynamo.task.model.Task) TaskEngineProcBatch(io.vertigo.dynamox.task.TaskEngineProcBatch) VTransactionWritable(io.vertigo.commons.transaction.VTransactionWritable) Domain(io.vertigo.dynamo.domain.metamodel.Domain) Test(org.junit.Test)

Aggregations

VTransactionWritable (io.vertigo.commons.transaction.VTransactionWritable)80 Test (org.junit.Test)63 Car (io.vertigo.dynamo.store.data.domain.car.Car)22 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)22 Task (io.vertigo.dynamo.task.model.Task)22 SuperHero (io.vertigo.dynamo.task.data.domain.SuperHero)18 DtList (io.vertigo.dynamo.domain.model.DtList)7 Flower (io.vertigo.dynamo.kvstore.data.Flower)6 Famille (io.vertigo.dynamo.store.data.domain.famille.Famille)6 SqlConnection (io.vertigo.database.sql.connection.SqlConnection)5 DtListURI (io.vertigo.dynamo.domain.model.DtListURI)5 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)4 DtListURIForCriteria (io.vertigo.dynamo.domain.model.DtListURIForCriteria)4 URI (io.vertigo.dynamo.domain.model.URI)4 Item (io.vertigo.dynamo.search.data.domain.Item)4 SearchIndexDefinition (io.vertigo.dynamo.search.metamodel.SearchIndexDefinition)4 Car (io.vertigo.dynamo.search_2_4.data.domain.Car)4 TaskEngineSelect (io.vertigo.dynamox.task.TaskEngineSelect)4 ArrayList (java.util.ArrayList)4 Domain (io.vertigo.dynamo.domain.metamodel.Domain)3