What is the best practice for writing test cases when working with a stable data warehouse such as MongoDB?
My current setup is Mongodb with a setting of 3 / w630> Master / Slave / Slave with slave-ok set to true. This means that the Node wizard is used for writing only, and the two Node slaves are used for reading only.
The time required to reconcile data on the slaves is relatively small and depends on the size of the operation and the data. For example, ~ 3 ms for delete operations and ~ 200 ms for batch insertion of 1000 objects.
My goal is to check the actions on my Dao. They can be simple, such as getById, delete, insert, or complex, such as findByExample. I need to make sure that they work correctly, with a possible sequence, when the allowable time limit expires.
This is what I have to check the delete operation, for example:
@Test public void deleteTest() throws InstantiationException, IllegalAccessException { MyObject obj = new MyObject(); obj.setName("test object"); obj.save(obj); MyObject found = dao.findById(obj.getId()); logger.info ("before: " + found); Assert.assertEquals(obj, found); dao.delete(obj.getId()); MyObject deleted = null; long start = System.nanoTime(); do { //TBD: need to add escape condition/timeout, else may be infinite loop.... deleted = dao.findById(obj.getId()); logger.info ("While: " + deleted); } while (deleted!=null); logger.info("It took " + ((System.nanoTime()-start)/1000000.00) + " ms for delete to be consistent"); Assert.assertEquals(null, d1); }
source share