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());
}
}
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();
}
}
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());
}
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();
}
}
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());
}
Aggregations