Added "preload all" functionality and unit tests for same

This commit is contained in:
Michael Lieberman
2015-02-09 16:08:10 -05:00
parent 37157a0093
commit ec13b05459
3 changed files with 30 additions and 9 deletions

View File

@@ -155,11 +155,12 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
// any "preloaded" properties now, which saves us a round-trip
// to Accumulo later.
String[] preload = globals.getConfig().getPreloadedProperties();
if (preload == null) {
if (preload == null && !globals.getConfig().getPreloadAllProperties()) {
preload = new String[]{};
}
Map<String, Object> props = globals.getVertexWrapper().readProperties(vertex, preload);
Map<String, Object> props = globals.getVertexWrapper()
.readProperties(vertex, preload);
if (props == null) {
return null;
}

View File

@@ -1036,17 +1036,17 @@ implements Serializable {
}
}
if (timeout <= 0 && conf.getProperty(Keys.PRELOADED_PROPERTIES) != null) {
throw new IllegalArgumentException("You cannot preload properties "
+ "without first setting #propertyCacheTimeout(String property, int millis) "
+ "to a positive value.");
}
if (getPreloadAllProperties() && getPreloadedProperties() != null) {
throw new IllegalArgumentException("Cannot preload all properties"
+ " and specified properties simultaneously");
}
}
if (timeout <= 0 && (getPreloadedProperties() != null || getPreloadAllProperties())) {
throw new IllegalArgumentException("You cannot preload properties "
+ "without first setting #propertyCacheTimeout(String property, int millis) "
+ "to a positive value.");
}
}
private void checkPropertyValue(String prop, String val, boolean canBeEmpty) {
if (val == null) {

View File

@@ -221,6 +221,26 @@ public class ElementPropertyCachingTest {
graph.shutdown();
}
@Test
public void testPreloadAllProperties() {
AccumuloGraphConfiguration cfg =
AccumuloGraphTestUtils.generateGraphConfig("preloadAllProperties");
cfg.setPropertyCacheTimeout(null, TIMEOUT);
cfg.setPreloadAllProperties(true);
Graph graph = open(cfg);
AccumuloVertex v = (AccumuloVertex) graph.addVertex("V");
v.setProperty(NON_CACHED, true);
v.setProperty(CACHED, true);
v = (AccumuloVertex) graph.getVertex("V");
assertEquals(true, v.getPropertyInMemory(NON_CACHED));
assertEquals(true, v.getPropertyInMemory(CACHED));
graph.shutdown();
}
@Test
public void testPreloadSomeProperties() {
AccumuloGraphConfiguration cfg =