@Test public void testBagRemove() throws JasDBException { DBSession session = sessionFactory.createSession(); EntityBag bag = session.createOrGetBag("testbag1"); bag.ensureIndex(new SimpleIndexField("field1", new StringKeyType()), false); assertTrue(new File(jasdbHome, "testbag1.pjs").exists()); assertTrue(new File(jasdbHome, "testbag1_field1ID.idx").exists()); assertEquals(1, session.getBags().size()); session.removeBag("testbag1"); assertFalse(new File(jasdbHome, "testbag1.pjs").exists()); assertFalse(new File(jasdbHome, "testbag1_field1ID.idx").exists()); }
@Test public void testBagRemoveInstance() throws JasDBException, IOException { DBSession session = sessionFactory.createSession(); File newInstanceFolder = new File(storageLocation + "/.jasdb/myInstance"); session.addAndSwitchInstance(MY_INSTANCE); EntityBag bag = session.createOrGetBag("testbag1"); bag.ensureIndex(new SimpleIndexField("field1", new StringKeyType()), false); assertTrue(new File(newInstanceFolder, "testbag1.pjs").exists()); assertTrue(new File(newInstanceFolder, "testbag1_field1ID.idx").exists()); assertEquals(1, session.getBags().size()); session.removeBag("testbag1"); assertFalse(new File(newInstanceFolder, "testbag1.pjs").exists()); assertFalse(new File(newInstanceFolder, "testbag1_field1ID.idx").exists()); } }
@Test public void testEnsureAndRemoveIndex() throws JasDBException { DBSession session = sessionFactory.createSession(); EntityBag bag = session.createOrGetBag("testbag"); bag.ensureIndex(new SimpleIndexField("field1", new StringKeyType()), true); bag.ensureIndex(new SimpleIndexField("field2", new StringKeyType()), false); bag.addEntity(new SimpleEntity().addProperty("field1", "value1").addProperty("field2", "testkey2value")); String jasdbHome = storageLocation + "/.jasdb"; File field1Index = new File(jasdbHome, "testbag_field1.idx"); File field2Index = new File(jasdbHome, "testbag_field2ID.idx"); assertTrue("Index 1 file should exist", field1Index.exists()); assertTrue("Index 2 file should exist", field2Index.exists()); bag.removeIndex("field1"); assertFalse("Index 1 file should no longer exist", field1Index.exists()); assertTrue("Index 2 file should exist", field2Index.exists()); bag.removeIndex("field2ID"); assertFalse("Index 1 file should no longer exist", field1Index.exists()); assertFalse("Index 2 file should no longer exist", field2Index.exists()); }
DBSession pojoDb = sessionFactory.createSession(); EntityBag bag = pojoDb.createOrGetBag("testbag"); bag.ensureIndex(new SimpleIndexField("title", new StringKeyType()), true);
bag.ensureIndex(new SimpleIndexField("field1", new StringKeyType()), false); bag.ensureIndex(new SimpleIndexField("field5", new LongKeyType()), false, new SimpleIndexField("field6", new LongKeyType())); bag.ensureIndex(new SimpleIndexField("field6", new LongKeyType()), false); bag.ensureIndex(new SimpleIndexField("age", new LongKeyType()), false); bag.ensureIndex(new SimpleIndexField("city", new StringKeyType()), false); bag.ensureIndex(new SimpleIndexField("embed.embeddedProperty", new StringKeyType()), false); bag.ensureIndex(new SimpleCompositeIndexField(new SimpleIndexField("age", new LongKeyType()), new SimpleIndexField("mainCity", new StringKeyType())), false);
@Test public void testDeleteEmptyIndexValue() throws Exception { try { DBSession session = sessionFactory.createSession(); EntityBag bag = session.createOrGetBag("somebag"); bag.ensureIndex(new SimpleIndexField("field", new StringKeyType()), false); String id = bag.addEntity(new SimpleEntity().addProperty("anotherfield", "somevalue")).getInternalId(); bag.removeEntity(id); } finally { JasDBMain.shutdown(); } }
@Test public void testRandomPersistUpdate() throws Exception { String[] cities = new String[] {"Amsterdam", "Rotterdam", "Utrecht", "Groningen", "Haarlem", "Den Haag", "Maastricht", "Eindhoven"}; int testSize = 1000; DBSession session = sessionFactory.createSession(); EntityBag bag = session.createOrGetBag("testbag"); bag.ensureIndex(new SimpleIndexField("city", new StringKeyType()), false); bag.ensureIndex(new SimpleIndexField("itemId", new LongKeyType()), true); try { Map<String, Integer> cityCounts = generateCities(testSize, bag); assertCityIndexes(bag, cities, cityCounts); for(int i=200; i<400; i++) { QueryExecutor executor = bag.find(QueryBuilder.createBuilder().field("itemId").value((long)i)); QueryResult result = executor.execute(); for(Entity entity : result) { String city = entity.getProperty("city").getFirstValueObject().toString(); entity.setProperty("city", "unknown"); bag.updateEntity(entity); changeCityCount(city, cityCounts, false); changeCityCount("unknown", cityCounts, true); } } assertCityIndexes(bag, cities, cityCounts); } finally { JasDBMain.shutdown(); } }
@Test public void testRandomPersistUpdateBigRecordUpdate() throws Exception { String htmlData = ResourceUtil.getContent("datasets/htmlpage.data", "UTF-8"); int testSize = 1000; DBSession session = sessionFactory.createSession(); EntityBag bag = session.createOrGetBag("testbag"); bag.ensureIndex(new SimpleIndexField("city", new StringKeyType()), false); bag.ensureIndex(new SimpleIndexField("itemId", new LongKeyType()), true); try { Map<String, Integer> cityCounts = generateCities(testSize, bag); assertCityIndexes(bag, cities, cityCounts); for(int i=200; i<400; i++) { QueryExecutor executor = bag.find(QueryBuilder.createBuilder().field("itemId").value((long)i)); QueryResult result = executor.execute(); for(Entity entity : result) { String city = entity.getProperty("city").getFirstValueObject().toString(); entity.setProperty("city", "unknown"); entity.setProperty("bigdatafield", htmlData); bag.updateEntity(entity); changeCityCount(city, cityCounts, false); changeCityCount("unknown", cityCounts, true); } } assertCityIndexes(bag, cities, cityCounts); } finally { JasDBMain.shutdown(); } }
@Test public void testPersisterRemove() throws Exception { int testSize = 1000; DBSession session = sessionFactory.createSession(); EntityBag bag = session.createOrGetBag("testbag"); bag.ensureIndex(new SimpleIndexField("city", new StringKeyType(100)), false); bag.ensureIndex(new SimpleIndexField("testField", new LongKeyType()), true); Random rnd = new Random(); for(int i=0; i<testSize; i++) { int cityIdx = rnd.nextInt(SimpleBaseTest.possibleCities.length); String city = SimpleBaseTest.possibleCities[cityIdx]; SimpleEntity entity = new SimpleEntity(); entity.addProperty("city", city); entity.addProperty("testField", (long)i); bag.addEntity(entity); } for(String city : SimpleBaseTest.possibleCities) { QueryResult result = bag.find(QueryBuilder.createBuilder().field("city").value(city)).execute(); for(Entity foundEntity : result) { Long testFieldValue = foundEntity.getProperty("testField").getFirstValueObject(); bag.removeEntity(foundEntity); assertFalse("There should no longer be a result", bag.find(QueryBuilder.createBuilder().field("testField").value(testFieldValue)).execute().hasNext()); } result = bag.find(QueryBuilder.createBuilder().field("city").value(city)).execute(); assertEquals("There should no longer be any entity", (long) 0, result.size()); } }
@Test public void testPersistIndexNonUniqueQuery() throws JasDBException, InterruptedException { DBSession session = sessionFactory.createSession(); EntityBag bag = session.createOrGetBag("testbag"); bag.addEntity(new SimpleEntity().addProperty("city", "Amsterdam")); bag.addEntity(new SimpleEntity().addProperty("city", "Amsterdam")); bag.addEntity(new SimpleEntity().addProperty("city", "Rotterdam")); bag.addEntity(new SimpleEntity().addProperty("city", "Utrecht")); bag.addEntity(new SimpleEntity().addProperty("city", "Utrecht")); QueryResult result = bag.find(QueryBuilder.createBuilder().field("city").value("Amsterdam")).execute(); assertThat(result.size(), is(2L)); result.close(); bag.ensureIndex(new SimpleIndexField("city", new StringKeyType()), false); //let's give the index some time to build Thread.sleep(5000); result = bag.find(QueryBuilder.createBuilder().field("city").value("Amsterdam")).execute(); assertThat(result.size(), is(2L)); result.close(); } }
@Test public void testNotEqualsMultiIndexes() throws Exception { try { DBSession session = sessionFactory.createSession(); EntityBag bag = session.createOrGetBag("websites"); bag.ensureIndex(new SimpleIndexField("url", new StringKeyType()), false); bag.ensureIndex( new SimpleCompositeIndexField( new SimpleIndexField("stepid", new StringKeyType()), new SimpleIndexField("workflow", new LongKeyType()) ),false); bag.addEntity(new SimpleEntity().addProperty("url", "").addProperty("stepid", 1L).addProperty("workflow", 1L)); bag.addEntity(new SimpleEntity().addProperty("url", "").addProperty("stepid", 1L).addProperty("workflow", 1L)); bag.addEntity(new SimpleEntity().addProperty("url", "").addProperty("stepid", 1L).addProperty("workflow", 1L)); bag.addEntity(new SimpleEntity().addProperty("url", "http://someurl.nl/1").addProperty("stepid", 1L).addProperty("workflow", 1L)); bag.addEntity(new SimpleEntity().addProperty("url", "http://someurl.nl/2").addProperty("stepid", 1L).addProperty("workflow", 1L)); QueryResult r = bag.find(QueryBuilder.createBuilder() .field("stepid").value(1L) .field("workflow").value(1L) .field("url").notEquals("")).execute(); assertThat(r.size(), is(2L)); } finally { JasDBMain.shutdown(); } }
EntityBag bag = pojoDb.createOrGetBag("homeautotest"); bag.ensureIndex( new SimpleCompositeIndexField( new SimpleIndexField("controllerId", new StringKeyType()),