use of io.vertigo.dynamo.kvstore.data.Flower in project vertigo by KleeGroup.
the class AbstractKVStoreManagerTest method testRemove.
@Test
public void testRemove() {
try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final Optional<Flower> flower = kvStoreManager.find("flowers", "10", Flower.class);
Assert.assertFalse("There is already a flower id 10", flower.isPresent());
kvStoreManager.put("flowers", "10", buildFlower("daisy", 60));
kvStoreManager.put("flowers", "11", buildFlower("tulip", 100));
final Optional<Flower> flower1 = kvStoreManager.find("flowers", "10", Flower.class);
final Optional<Flower> flower2 = kvStoreManager.find("flowers", "11", Flower.class);
Assert.assertTrue("Flower id 10 not found", flower1.isPresent());
Assert.assertTrue("Flower id 11 not found", flower2.isPresent());
transaction.commit();
}
try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final Optional<Flower> flower = kvStoreManager.find("flowers", "10", Flower.class);
Assert.assertTrue("Flower id 10 not found", flower.isPresent());
kvStoreManager.remove("flowers", "10");
final Optional<Flower> flower1 = kvStoreManager.find("flowers", "10", Flower.class);
final Optional<Flower> flower2 = kvStoreManager.find("flowers", "11", Flower.class);
Assert.assertFalse("Remove flower id 10 failed", flower1.isPresent());
Assert.assertTrue("Flower id 11 not found", flower2.isPresent());
}
}
use of io.vertigo.dynamo.kvstore.data.Flower in project vertigo by KleeGroup.
the class AbstractKVStoreManagerTest method testCount.
@Test
public void testCount() {
try (VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final int nbFlowers = kvStoreManager.count("flowers");
Assert.assertEquals(0, nbFlowers);
final Flower tulip1 = buildFlower("tulip", 100);
kvStoreManager.put("flowers", "1", tulip1);
final Flower tulip2 = buildFlower("tulip", 110);
kvStoreManager.put("flowers", "2", tulip2);
final Flower tulip3 = buildFlower("tulip", 120);
kvStoreManager.put("flowers", "3", tulip3);
// count after 3 inserts
final int nbFlowers2 = kvStoreManager.count("flowers");
Assert.assertEquals(3, nbFlowers2);
// count after 1 more insert of same value
kvStoreManager.put("flowers", "4", tulip3);
final int nbFlowers3 = kvStoreManager.count("flowers");
Assert.assertEquals(4, nbFlowers3);
// count after 1 insert of same key : update
kvStoreManager.put("flowers", "3", tulip3);
final int nbFlowers4 = kvStoreManager.count("flowers");
Assert.assertEquals(4, nbFlowers4);
}
}
use of io.vertigo.dynamo.kvstore.data.Flower in project vertigo by KleeGroup.
the class BerkeleyKVStoreManagerTest method testFindAll.
@Test
public void testFindAll() {
final List<Flower> flowers = new ListBuilder<Flower>().add(buildFlower("daisy", 60)).add(buildFlower("tulip", 100)).add(buildFlower("rose", 110)).add(buildFlower("lily", 120)).add(buildFlower("orchid", 200)).build();
try (final VTransactionWritable transaction = transactionManager.createCurrentTransaction()) {
final List<Flower> foundFlowers = kvStoreManager.findAll("flowers", 0, null, Flower.class);
Assert.assertTrue(foundFlowers.isEmpty());
int i = 0;
for (final Flower flower : flowers) {
final String id = "" + i++;
kvStoreManager.put("flowers", id, flower);
}
final List<Flower> foundFlowers2 = kvStoreManager.findAll("flowers", 0, 1000, Flower.class);
Assert.assertEquals(flowers.size(), foundFlowers2.size());
transaction.commit();
}
}
use of io.vertigo.dynamo.kvstore.data.Flower 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.dynamo.kvstore.data.Flower 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