summaryrefslogtreecommitdiffstats
path: root/zkfacade
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-07-08 12:57:08 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-07-08 12:57:08 +0200
commit55e1305da512f88b3825a413ab76695f2f7339ff (patch)
tree3df4611d0953f6d32cf857179e90b192f1046874 /zkfacade
parent08afd426d391fa66f51be424b1f6b2f593b8e116 (diff)
Truly test application delete
Diffstat (limited to 'zkfacade')
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/mock/MemoryFileSystem.java30
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/mock/MockCurator.java20
2 files changed, 42 insertions, 8 deletions
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/mock/MemoryFileSystem.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/mock/MemoryFileSystem.java
index 978827aebc2..2a598c8c4e0 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/mock/MemoryFileSystem.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/mock/MemoryFileSystem.java
@@ -92,6 +92,16 @@ class MemoryFileSystem extends FileSystem {
public void replaceRoot(Node newRoot) { this.root = newRoot; }
/**
+ * Lists the entire content of this file system as a multiline string.
+ * Useful for debugging.
+ */
+ public String dumpState() {
+ StringBuilder b = new StringBuilder();
+ root.writeRecursivelyTo(b, "");
+ return b.toString();
+ }
+
+ /**
* A node in this file system. Nodes may have children (a "directory"),
* content (a "file"), or both.
*/
@@ -103,7 +113,7 @@ class MemoryFileSystem extends FileSystem {
/** The local name of this node */
private final String name;
- /** The content of this node. This buffer is effectively immutable. */
+ /** The content of this node, never null. This buffer is effectively immutable. */
private byte[] content;
private Map<String, Node> children = new LinkedHashMap<>();
@@ -187,6 +197,24 @@ class MemoryFileSystem extends FileSystem {
/** Returns an unmodifiable map of the immediate children of this indexed by their local name */
public Map<String, Node> children() { return Collections.unmodifiableMap(children); }
+ /**
+ * Dumps the content of this and all children recursively to the given string builder.
+ * Useful for debugging.
+ *
+ * @param b the builder to write to
+ * @param pathPrefix, the path to this node, never ending by "/"
+ */
+ public void writeRecursivelyTo(StringBuilder b, String pathPrefix) {
+ String path = ( pathPrefix.equals("/") ? "" : pathPrefix ) + "/" + name;
+ b.append(path);
+ if (content.length > 0)
+ b.append(" [content: ").append(content.length).append(" bytes]");
+ b.append("\n");
+
+ for (Node child : children.values())
+ child.writeRecursivelyTo(b, path);
+ }
+
@Override
public String toString() {
return "directory '" + name() + "'";
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/mock/MockCurator.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/mock/MockCurator.java
index 9d347f8be7f..92db255a67f 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/mock/MockCurator.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/mock/MockCurator.java
@@ -130,6 +130,12 @@ public class MockCurator extends Curator {
curatorFramework.start();
}
+ /**
+ * Lists the entire content of this curator instance as a multiline string.
+ * Useful for debugging.
+ */
+ public String dumpState() { return fileSystem.dumpState(); }
+
/** Returns a started curator framework */
public CuratorFramework framework() { return curatorFramework; }
@@ -361,6 +367,7 @@ public class MockCurator extends Curator {
}
}
catch (Exception e) {
+ e.printStackTrace(); // TODO: Remove
throw new RuntimeException("Exception notifying listeners", e);
}
}
@@ -517,13 +524,12 @@ public class MockCurator extends Curator {
@Override
public List<ChildData> getCurrentData() {
- Node parent = fileSystem.root().getNode(Paths.get(path.toString()), false);
- if (parent == null) return Collections.emptyList(); // behavior in this case is unspecified
-
- List<ChildData> data = new ArrayList<>();
- collectData(parent, path, data);
- Collections.sort(data);
- return data;
+ List<ChildData> childData = new ArrayList<>();
+ for (String childName : getChildren(path)) {
+ Path childPath = path.append(childName);
+ childData.add(new ChildData(childPath.getAbsolute(), null, getData(childPath).get()));
+ }
+ return childData;
}
private void collectData(Node parent, Path parentPath, List<ChildData> data) {