@Test public void testGetAllChildren() throws SQLException { final Map<String, String> expected = new HashMap<>(); expected.put("key1", "value1"); expected.put("key2", "value2"); expected.put("key3", "value3"); final PreparedStatement selectPreparedStatement = Mockito.mock(PreparedStatement.class); Mockito.doReturn(selectPreparedStatement).when(connection).prepareStatement( Mockito.eq("SELECT child,val FROM tableName WHERE path=? AND child!=?")); final ResultSet resultSet = Mockito.mock(ResultSet.class); Mockito.when(selectPreparedStatement.executeQuery()).thenReturn(resultSet); Mockito.when(resultSet.next()).thenReturn(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE, Boolean.FALSE); final List<String> keyList = new ArrayList<>(expected.keySet()); final Blob blob = Mockito.mock(Blob.class); Mockito.when(resultSet.getString(1)).thenReturn(keyList.get(0), keyList.get(1), keyList.get(2)); Mockito.when(resultSet.getObject(2, Blob.class)).thenReturn(blob); Mockito.when(blob.getBytes(Mockito.anyLong(), Mockito.anyInt())).thenReturn( LZFEncoder.encode(expected.get(keyList.get(0)).getBytes()), LZFEncoder.encode(expected.get(keyList.get(1)).getBytes()), LZFEncoder.encode(expected.get(keyList.get(2)).getBytes())); final Map<String, String> result = cachedDataStore.getAllChildren("key"); assertNotNull(result); expected.keySet().stream().forEach((key) -> { assertEquals(expected.get(key), result.get(key)); }); Mockito.verify(selectPreparedStatement, Mockito.atLeastOnce()).executeQuery(); Mockito.verify(selectPreparedStatement).setString(Mockito.eq(1), Mockito.eq("key")); Mockito.verify(selectPreparedStatement).setString(Mockito.eq(2), Mockito.eq("_root")); }
@Override public Map<String, String> getAllChildren(String path) { return dataStore.getAllChildren(path); }
CachedSpawnDataStore implements SpawnDataStore { @Override public Map<String, String> getAllChildren(String path) { return dataStore.getAllChildren(path); } }
CachedSpawnDataStore implements SpawnDataStore { @Override public Map<String, String> getAllChildren(String path) { return dataStore.getAllChildren(path); } CachedSpawnDataStore(SpawnDataStore dataStore, long dataStoreCacheSize); }
CachedSpawnDataStore implements SpawnDataStore { @Override public Map<String, String> getAllChildren(String path) { return dataStore.getAllChildren(path); } CachedSpawnDataStore(SpawnDataStore dataStore, long dataStoreCacheSize); @Override String getDescription(); @Override String get(String path); @Override Map<String, String> get(String[] paths); @Override void put(String path, String value); @Override void putAsChild(String parent, String childId, String value); @Override String getChild(String parent, String childId); @Override void deleteChild(String parent, String childId); @Override void delete(String path); @Override List<String> getChildrenNames(String path); @Override Map<String, String> getAllChildren(String path); @Override void close(); }
CachedSpawnDataStore implements SpawnDataStore { @Override public Map<String, String> getAllChildren(String path) { return dataStore.getAllChildren(path); } CachedSpawnDataStore(SpawnDataStore dataStore, long dataStoreCacheSize); @Override String getDescription(); @Override String get(String path); @Override Map<String, String> get(String[] paths); @Override void put(String path, String value); @Override void putAsChild(String parent, String childId, String value); @Override String getChild(String parent, String childId); @Override void deleteChild(String parent, String childId); @Override void delete(String path); @Override List<String> getChildrenNames(String path); @Override Map<String, String> getAllChildren(String path); @Override void close();  }