use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class AccountManagerTest method testGroups.
@Test
public void testGroups() {
try (VTransactionWritable tx = obtainTx()) {
// Assert.assertEquals(2, identityManager.getGroupsCount());
// ----
Assert.assertEquals(1, accountManager.getGroupURIs(accountURI0).size());
if (!database) {
Assert.assertEquals(2, accountManager.getGroupURIs(accountURI1).size());
Assert.assertEquals(2, accountManager.getGroupURIs(accountURI2).size());
}
Assert.assertEquals(2, accountManager.getAccountURIs(groupURI).size());
Assert.assertEquals(database ? 8 : 10 + 4, accountManager.getAccountURIs(groupAllURI).size());
// ---
/*identityManager.attach(accountURI0, groupURI);
Assert.assertEquals(2, identityManager.getGroupURIs(accountURI0).size());
Assert.assertEquals(2, identityManager.getGroupURIs(accountURI1).size());
Assert.assertEquals(2, identityManager.getGroupURIs(accountURI2).size());
Assert.assertEquals(3, identityManager.getAccountURIs(groupURI).size());
Assert.assertEquals(10 + 3, identityManager.getAccountURIs(groupAllURI).size());*/
}
}
use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class SqlUtil method execRequests.
public static void execRequests(final VTransactionManager transactionManager, final TaskManager taskManager, final List<String> requests, final String taskName, final Optional<String> optDataSpace) {
// A chaque test on recrée la table famille
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
for (final String request : requests) {
final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineProc.class).withRequest(request).withDataSpace(optDataSpace.orElse(null)).build();
final Task task = Task.builder(taskDefinition).build();
taskManager.execute(task);
}
transaction.commit();
}
}
use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class VTransactionAspect method invoke.
@Override
public Object invoke(final Object[] args, final AspectMethodInvocation methodInvocation) {
// La transaction est REQUIRED : si elle existe on l'utilise, sinon on la crée.
if (transactionManager.hasCurrentTransaction()) {
return methodInvocation.proceed(args);
}
// Dans le cas ou il n'existe pas de transaction on en crée une.
try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final Object o = methodInvocation.proceed(args);
transaction.commit();
return o;
}
}
use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class AbstractKVStoreManagerTest method testFind.
@Test
public void testFind() {
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final Optional<Flower> foundFlower = kvStoreManager.find("flowers", "1", Flower.class);
Assert.assertEquals(Optional.empty(), foundFlower);
final Flower tulip = buildFlower("tulip", 100);
kvStoreManager.put("flowers", "1", tulip);
final Optional<Flower> foundFlower2 = kvStoreManager.find("flowers", "1", Flower.class);
Assert.assertTrue(foundFlower2.isPresent());
Assert.assertEquals("tulip", foundFlower2.get().getName());
// "Price must be excatly 100",
Assert.assertEquals(100d, foundFlower2.get().getPrice(), 0);
}
}
use of io.vertigo.commons.transaction.VTransactionWritable in project vertigo by KleeGroup.
the class BerkeleyKVStoreManagerTest method testRollback.
@Test(expected = RuntimeException.class)
public void testRollback() {
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final Flower tulip = buildFlower("tulip", 100);
kvStoreManager.put("flowers", "1", tulip);
transaction.commit();
}
final Optional<Flower> flower1 = kvStoreManager.find("flowers", "1", Flower.class);
Assert.assertTrue("Flower id 1 not found", flower1.isPresent());
final Optional<Flower> flower2 = kvStoreManager.find("flowers", "2", Flower.class);
Assert.assertFalse("There is already a flower id 2", flower2.isPresent());
try {
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final Flower tulip = buildFlower("rose", 100);
kvStoreManager.put("flowers", "2", tulip);
throw new VSystemException("Error");
}
} catch (final RuntimeException e) {
// on doit passer par là
}
final Optional<Flower> flower2bis = kvStoreManager.find("flowers", "2", Flower.class);
Assert.assertFalse("Rollback flower id 2 failed", flower2bis.isPresent());
}
Aggregations