This is an automated email from the ASF dual-hosted git repository.
ctubbsii pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/3.1 by this push:
new ec14b3ae65 Remove redundant table/namespace id/name lookup (#4942)
ec14b3ae65 is described below
commit ec14b3ae65164e56e681f86292389dd20f804494
Author: Christopher Tubbs <[email protected]>
AuthorDate: Thu Oct 10 12:36:37 2024 -0400
Remove redundant table/namespace id/name lookup (#4942)
* Remove redundant code to look up table and namespace names and ids
that were only used for ZooPropEditor/ZooInfoViewer
* Update corresponding tests
* Add implementation for namespace ID lookup (currently not implemented
the same as the table ID lookup, but should form the basis for
follow-on work)
---
.../accumulo/core/clientImpl/ClientContext.java | 4 +
.../accumulo/server/conf/util/ZooInfoViewer.java | 47 ++++++------
.../accumulo/server/conf/util/ZooPropEditor.java | 45 ++++-------
.../accumulo/server/conf/util/ZooPropUtils.java | 56 --------------
.../server/conf/util/ZooInfoViewerTest.java | 87 +++++++++-------------
5 files changed, 76 insertions(+), 163 deletions(-)
diff --git
a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java
b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java
index cc93f79d00..899bad6c10 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java
@@ -634,6 +634,10 @@ public class ClientContext implements AccumuloClient {
return tableZooHelper().getTableMap().getNameToIdMap();
}
+ public Map<NamespaceId,String> getNamespaceIdToNameMap() {
+ return Namespaces.getIdToNameMap(this);
+ }
+
public Map<TableId,String> getTableIdToNameMap() {
return tableZooHelper().getTableMap().getIdtoNameMap();
}
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooInfoViewer.java
b/server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooInfoViewer.java
index c45b0b8832..535a0899f6 100644
---
a/server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooInfoViewer.java
+++
b/server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooInfoViewer.java
@@ -21,8 +21,6 @@ package org.apache.accumulo.server.conf.util;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.accumulo.core.Constants.ZINSTANCES;
import static org.apache.accumulo.core.Constants.ZROOT;
-import static
org.apache.accumulo.server.conf.util.ZooPropUtils.getNamespaceIdToNameMap;
-import static
org.apache.accumulo.server.conf.util.ZooPropUtils.getTableIdToName;
import static
org.apache.accumulo.server.conf.util.ZooPropUtils.readInstancesFromZk;
import static
org.apache.accumulo.server.zookeeper.ZooAclUtil.checkWritableAuth;
import static org.apache.accumulo.server.zookeeper.ZooAclUtil.extractAuthName;
@@ -117,16 +115,12 @@ public class ZooInfoViewer implements KeywordExecutable {
var conf = opts.getSiteConfiguration();
- ZooReader zooReader = new ZooReaderWriter(conf);
-
try (ServerContext context = new ServerContext(conf)) {
- InstanceId iid = context.getInstanceID();
- generateReport(iid, opts, zooReader);
+ generateReport(context, opts);
}
}
- void generateReport(final InstanceId iid, final ZooInfoViewer.Opts opts,
- final ZooReader zooReader) throws Exception {
+ void generateReport(final ServerContext context, final ZooInfoViewer.Opts
opts) throws Exception {
OutputStream outStream;
@@ -145,27 +139,29 @@ public class ZooInfoViewer implements KeywordExecutable {
writer.println("Report Time: " + tsFormat.format(Instant.now()));
writer.println("-----------------------------------------------");
if (opts.printInstanceIds) {
- Map<String,InstanceId> instanceMap = readInstancesFromZk(zooReader);
+ Map<String,InstanceId> instanceMap =
readInstancesFromZk(context.getZooReader());
printInstanceIds(instanceMap, writer);
}
if (opts.printIdMap) {
- printIdMapping(iid, zooReader, writer);
+ printIdMapping(context, writer);
}
if (opts.printProps) {
- printProps(iid, zooReader, opts, writer);
+ printProps(context, opts, writer);
}
if (opts.printAcls) {
- printAcls(iid, opts, writer);
+ printAcls(context, opts, writer);
}
writer.println("-----------------------------------------------");
}
}
- private void printProps(final InstanceId iid, final ZooReader zooReader,
final Opts opts,
- final PrintWriter writer) throws Exception {
+ private void printProps(final ServerContext context, final Opts opts, final
PrintWriter writer)
+ throws Exception {
+ var iid = context.getInstanceID();
+ var zooReader = context.getZooReader();
if (opts.printAllProps()) {
log.info("all: {}", opts.printAllProps());
@@ -184,7 +180,7 @@ public class ZooInfoViewer implements KeywordExecutable {
}
if (opts.printNamespaceProps()) {
- Map<NamespaceId,String> id2NamespaceMap = getNamespaceIdToNameMap(iid,
zooReader);
+ Map<NamespaceId,String> id2NamespaceMap =
context.getNamespaceIdToNameMap();
Map<String,VersionedProperties> nsProps =
fetchNamespaceProps(iid, zooReader, id2NamespaceMap,
opts.getNamespaces());
@@ -195,16 +191,17 @@ public class ZooInfoViewer implements KeywordExecutable {
}
if (opts.printTableProps()) {
- Map<String,VersionedProperties> tProps = fetchTableProps(iid,
opts.getTables(), zooReader);
+ Map<String,VersionedProperties> tProps = fetchTableProps(context,
opts.getTables());
writer.println("Tables: ");
printSortedProps(writer, tProps);
}
writer.println();
}
- private void printIdMapping(InstanceId iid, ZooReader zooReader, PrintWriter
writer) {
+ private void printIdMapping(ServerContext context, PrintWriter writer) {
+ var iid = context.getInstanceID();
// namespaces
- Map<NamespaceId,String> id2NamespaceMap = getNamespaceIdToNameMap(iid,
zooReader);
+ Map<NamespaceId,String> id2NamespaceMap =
context.getNamespaceIdToNameMap();
writer.println("ID Mapping (id => name) for instance: " + iid);
writer.println("Namespace ids:");
for (Map.Entry<NamespaceId,String> e : id2NamespaceMap.entrySet()) {
@@ -213,7 +210,7 @@ public class ZooInfoViewer implements KeywordExecutable {
}
writer.println();
// tables
- Map<TableId,String> id2TableMap = getTableIdToName(iid, id2NamespaceMap,
zooReader);
+ Map<TableId,String> id2TableMap = context.getTableIdToNameMap();
writer.println("Table ids:");
for (Map.Entry<TableId,String> e : id2TableMap.entrySet()) {
writer.printf("%s%-9s => %24s\n", INDENT, e.getKey(), e.getValue());
@@ -221,7 +218,8 @@ public class ZooInfoViewer implements KeywordExecutable {
writer.println();
}
- private void printAcls(final InstanceId iid, final Opts opts, final
PrintWriter writer) {
+ private void printAcls(final ServerContext context, final Opts opts, final
PrintWriter writer) {
+ var iid = context.getInstanceID();
Map<String,List<ACL>> aclMap = new TreeMap<>();
@@ -344,13 +342,14 @@ public class ZooInfoViewer implements KeywordExecutable {
return results;
}
- private Map<String,VersionedProperties> fetchTableProps(final InstanceId iid,
- final List<String> tables, final ZooReader zooReader) {
+ private Map<String,VersionedProperties> fetchTableProps(final ServerContext
context,
+ final List<String> tables) {
+ var iid = context.getInstanceID();
+ var zooReader = context.getZooReader();
Set<String> cmdOptTables = new TreeSet<>(tables);
- Map<NamespaceId,String> id2NamespaceMap = getNamespaceIdToNameMap(iid,
zooReader);
- Map<TableId,String> allIds = getTableIdToName(iid, id2NamespaceMap,
zooReader);
+ Map<TableId,String> allIds = context.getTableIdToNameMap();
Map<TableId,String> filteredIds;
if (cmdOptTables.isEmpty()) {
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooPropEditor.java
b/server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooPropEditor.java
index ff277202fa..8d394cb0d6 100644
---
a/server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooPropEditor.java
+++
b/server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooPropEditor.java
@@ -19,8 +19,6 @@
package org.apache.accumulo.server.conf.util;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static
org.apache.accumulo.server.conf.util.ZooPropUtils.getNamespaceIdToNameMap;
-import static
org.apache.accumulo.server.conf.util.ZooPropUtils.getTableIdToName;
import java.io.BufferedWriter;
import java.io.IOException;
@@ -34,7 +32,6 @@ import java.util.TreeMap;
import org.apache.accumulo.core.cli.ConfigOpts;
import org.apache.accumulo.core.conf.Property;
-import org.apache.accumulo.core.data.InstanceId;
import org.apache.accumulo.core.data.NamespaceId;
import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.fate.zookeeper.ZooReader;
@@ -89,10 +86,7 @@ public class ZooPropEditor implements KeywordExecutable {
var siteConfig = opts.getSiteConfiguration();
try (ServerContext context = new ServerContext(siteConfig)) {
-
- InstanceId iid = context.getInstanceID();
-
- PropStoreKey<?> propKey = getPropKey(iid, opts, zrw);
+ PropStoreKey<?> propKey = getPropKey(context, opts);
switch (opts.getCmdMode()) {
case SET:
setProperty(context, propKey, opts);
@@ -120,7 +114,7 @@ public class ZooPropEditor implements KeywordExecutable {
}
String targetName = "'invalid'";
try {
- targetName = getDisplayName(propKey, context.getInstanceID(),
context.getZooReader());
+ targetName = getDisplayName(propKey, context);
Map<String,String> prev = context.getPropStore().get(propKey).asMap();
String[] tokens = opts.setOpt.split("=");
@@ -155,7 +149,7 @@ public class ZooPropEditor implements KeywordExecutable {
return;
}
PropUtil.removeProperties(context, propKey, List.of(p));
- String targetName = getDisplayName(propKey, context.getInstanceID(),
context.getZooReader());
+ String targetName = getDisplayName(propKey, context);
LOG.info("{}: deleted {}", targetName, p);
}
@@ -183,8 +177,7 @@ public class ZooPropEditor implements KeywordExecutable {
writer.printf(": Instance Id: %s\n", context.getInstanceID());
writer.printf(": Property scope: %s\n", scope);
writer.printf(": ZooKeeper path: %s\n", propKey.getPath());
- writer.printf(": Name: %s\n",
- getDisplayName(propKey, context.getInstanceID(),
context.getZooReader()));
+ writer.printf(": Name: %s\n", getDisplayName(propKey, context));
writer.printf(": Id: %s\n", propKey.getId());
writer.printf(": Data version: %d\n", props.getDataVersion());
writer.printf(": Timestamp: %s\n", props.getTimestampISO());
@@ -208,18 +201,18 @@ public class ZooPropEditor implements KeywordExecutable {
}
}
- private PropStoreKey<?> getPropKey(final InstanceId iid, final
ZooPropEditor.Opts opts,
- final ZooReader zooReader) {
+ private PropStoreKey<?> getPropKey(final ServerContext context, final
ZooPropEditor.Opts opts) {
+ var iid = context.getInstanceID();
// either tid or table name option provided, get the table id
if (!opts.tableOpt.isEmpty() || !opts.tableIdOpt.isEmpty()) {
- TableId tid = getTableId(iid, opts, zooReader);
+ TableId tid = getTableId(context, opts);
return TablePropKey.of(iid, tid);
}
// either nid of namespace name provided, get the namespace id.
if (!opts.namespaceOpt.isEmpty() || !opts.namespaceIdOpt.isEmpty()) {
- NamespaceId nid = getNamespaceId(iid, opts, zooReader);
+ NamespaceId nid = getNamespaceId(context, opts);
return NamespacePropKey.of(iid, nid);
}
@@ -227,41 +220,33 @@ public class ZooPropEditor implements KeywordExecutable {
return SystemPropKey.of(iid);
}
- private TableId getTableId(final InstanceId iid, final ZooPropEditor.Opts
opts,
- final ZooReader zooReader) {
+ private TableId getTableId(final ServerContext context, final
ZooPropEditor.Opts opts) {
if (!opts.tableIdOpt.isEmpty()) {
return TableId.of(opts.tableIdOpt);
}
- Map<NamespaceId,String> nids = getNamespaceIdToNameMap(iid, zooReader);
-
- Map<TableId,String> tids = getTableIdToName(iid, nids, zooReader);
+ Map<TableId,String> tids = context.getTableIdToNameMap();
return tids.entrySet().stream().filter(entry ->
opts.tableOpt.equals(entry.getValue()))
.map(Map.Entry::getKey).findAny()
.orElseThrow(() -> new IllegalArgumentException("Could not find table
" + opts.tableOpt));
}
- private NamespaceId getNamespaceId(final InstanceId iid, final
ZooPropEditor.Opts opts,
- final ZooReader zooReader) {
+ private NamespaceId getNamespaceId(final ServerContext context, final
ZooPropEditor.Opts opts) {
if (!opts.namespaceIdOpt.isEmpty()) {
return NamespaceId.of(opts.namespaceIdOpt);
}
- Map<NamespaceId,String> nids = getNamespaceIdToNameMap(iid, zooReader);
+ Map<NamespaceId,String> nids = context.getNamespaceIdToNameMap();
return nids.entrySet().stream().filter(entry ->
opts.namespaceOpt.equals(entry.getValue()))
.map(Map.Entry::getKey).findAny().orElseThrow(
() -> new IllegalArgumentException("Could not find namespace " +
opts.namespaceOpt));
}
- private String getDisplayName(final PropStoreKey<?> propStoreKey, final
InstanceId iid,
- final ZooReader zooReader) {
+ private String getDisplayName(final PropStoreKey<?> propStoreKey, final
ServerContext context) {
if (propStoreKey instanceof TablePropKey) {
- Map<NamespaceId,String> nids = getNamespaceIdToNameMap(iid, zooReader);
- return getTableIdToName(iid, nids, zooReader).getOrDefault((TableId)
propStoreKey.getId(),
- "unknown");
+ return context.getTableIdToNameMap().getOrDefault(propStoreKey.getId(),
"unknown");
}
if (propStoreKey instanceof NamespacePropKey) {
- return getNamespaceIdToNameMap(iid, zooReader)
- .getOrDefault((NamespaceId) propStoreKey.getId(), "unknown");
+ return
context.getNamespaceIdToNameMap().getOrDefault(propStoreKey.getId(), "unknown");
}
if (propStoreKey instanceof SystemPropKey) {
return "system";
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooPropUtils.java
b/server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooPropUtils.java
index f403a12fa1..a892ca64a9 100644
---
a/server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooPropUtils.java
+++
b/server/base/src/main/java/org/apache/accumulo/server/conf/util/ZooPropUtils.java
@@ -20,25 +20,15 @@ package org.apache.accumulo.server.conf.util;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.accumulo.core.Constants.ZINSTANCES;
-import static org.apache.accumulo.core.Constants.ZNAMESPACES;
-import static org.apache.accumulo.core.Constants.ZNAMESPACE_NAME;
import static org.apache.accumulo.core.Constants.ZROOT;
-import static org.apache.accumulo.core.Constants.ZTABLES;
-import static org.apache.accumulo.core.Constants.ZTABLE_NAME;
-import static org.apache.accumulo.core.Constants.ZTABLE_NAMESPACE;
import java.util.List;
import java.util.Map;
-import java.util.SortedMap;
import java.util.TreeMap;
import java.util.UUID;
-import org.apache.accumulo.core.clientImpl.Namespace;
import org.apache.accumulo.core.data.InstanceId;
-import org.apache.accumulo.core.data.NamespaceId;
-import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.fate.zookeeper.ZooReader;
-import org.apache.accumulo.core.fate.zookeeper.ZooUtil;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -91,50 +81,4 @@ public class ZooPropUtils {
}
}
- public static Map<NamespaceId,String> getNamespaceIdToNameMap(final
InstanceId iid,
- final ZooReader zooReader) {
- SortedMap<NamespaceId,String> namespaceToName = new TreeMap<>();
- String zooNsRoot = ZooUtil.getRoot(iid) + ZNAMESPACES;
- try {
- List<String> nsids = zooReader.getChildren(zooNsRoot);
- for (String id : nsids) {
- String path = zooNsRoot + "/" + id + ZNAMESPACE_NAME;
- String name = new String(zooReader.getData(path), UTF_8);
- namespaceToName.put(NamespaceId.of(id), name);
- }
- } catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new IllegalStateException("Interrupted reading namespace ids from
ZooKeeper", ex);
- } catch (KeeperException ex) {
- throw new IllegalStateException("Failed to read namespace ids from
ZooKeeper", ex);
- }
- return namespaceToName;
- }
-
- public static Map<TableId,String> getTableIdToName(InstanceId iid,
- Map<NamespaceId,String> id2NamespaceMap, ZooReader zooReader) {
- SortedMap<TableId,String> idToName = new TreeMap<>();
-
- String zooTables = ZooUtil.getRoot(iid) + ZTABLES;
- try {
- List<String> tids = zooReader.getChildren(zooTables);
- for (String t : tids) {
- String path = zooTables + "/" + t;
- String tname = new String(zooReader.getData(path + ZTABLE_NAME),
UTF_8);
- NamespaceId tNsId =
- NamespaceId.of(new String(zooReader.getData(path +
ZTABLE_NAMESPACE), UTF_8));
- if (tNsId.equals(Namespace.DEFAULT.id())) {
- idToName.put(TableId.of(t), tname);
- } else {
- idToName.put(TableId.of(t), id2NamespaceMap.get(tNsId) + "." +
tname);
- }
- }
- } catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new IllegalStateException("Interrupted reading table ids from
ZooKeeper", ex);
- } catch (KeeperException ex) {
- throw new IllegalStateException("Failed reading table id info from
ZooKeeper");
- }
- return idToName;
- }
}
diff --git
a/server/base/src/test/java/org/apache/accumulo/server/conf/util/ZooInfoViewerTest.java
b/server/base/src/test/java/org/apache/accumulo/server/conf/util/ZooInfoViewerTest.java
index 9ea587a320..0fb5e9ab76 100644
---
a/server/base/src/test/java/org/apache/accumulo/server/conf/util/ZooInfoViewerTest.java
+++
b/server/base/src/test/java/org/apache/accumulo/server/conf/util/ZooInfoViewerTest.java
@@ -20,11 +20,8 @@ package org.apache.accumulo.server.conf.util;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.accumulo.core.Constants.ZINSTANCES;
-import static org.apache.accumulo.core.Constants.ZNAMESPACES;
-import static org.apache.accumulo.core.Constants.ZNAMESPACE_NAME;
import static org.apache.accumulo.core.Constants.ZROOT;
import static org.apache.accumulo.core.Constants.ZTABLES;
-import static org.apache.accumulo.core.Constants.ZTABLE_NAME;
import static org.apache.accumulo.core.Constants.ZTABLE_NAMESPACE;
import static org.easymock.EasyMock.capture;
import static org.easymock.EasyMock.createMock;
@@ -51,6 +48,7 @@ import org.apache.accumulo.core.data.NamespaceId;
import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.fate.zookeeper.ZooReader;
import org.apache.accumulo.core.fate.zookeeper.ZooUtil;
+import org.apache.accumulo.server.MockServerContext;
import org.apache.accumulo.server.conf.codec.VersionedPropCodec;
import org.apache.accumulo.server.conf.codec.VersionedProperties;
import org.apache.accumulo.server.conf.store.NamespacePropKey;
@@ -138,13 +136,14 @@ public class ZooInfoViewerTest {
@Test
public void instanceIdOutputTest() throws Exception {
String uuid = UUID.randomUUID().toString();
-
+ var context = MockServerContext.getWithZK(InstanceId.of(uuid), "fakeHost",
2000);
ZooReader zooReader = createMock(ZooReader.class);
+ expect(context.getZooReader()).andReturn(zooReader).anyTimes();
var instanceName = "test";
expect(zooReader.getChildren(eq(ZROOT +
ZINSTANCES))).andReturn(List.of(instanceName)).once();
expect(zooReader.getData(eq(ZROOT + ZINSTANCES + "/" + instanceName)))
.andReturn(uuid.getBytes(UTF_8)).once();
- replay(zooReader);
+ replay(context, zooReader);
String testFileName = "./target/zoo-info-viewer-" +
System.currentTimeMillis() + ".txt";
@@ -153,9 +152,9 @@ public class ZooInfoViewerTest {
new String[] {"--print-instances", "--outfile", testFileName});
ZooInfoViewer viewer = new ZooInfoViewer();
- viewer.generateReport(InstanceId.of(uuid), opts, zooReader);
+ viewer.generateReport(context, opts);
- verify(zooReader);
+ verify(context, zooReader);
String line;
try (Scanner scanner = new Scanner(new File(testFileName))) {
@@ -175,13 +174,14 @@ public class ZooInfoViewerTest {
@Test
public void instanceNameOutputTest() throws Exception {
String uuid = UUID.randomUUID().toString();
-
+ var context = MockServerContext.getWithZK(InstanceId.of(uuid), "fakeHost",
2000);
ZooReader zooReader = createMock(ZooReader.class);
+ expect(context.getZooReader()).andReturn(zooReader).anyTimes();
var instanceName = "test";
expect(zooReader.getChildren(eq(ZROOT +
ZINSTANCES))).andReturn(List.of(instanceName)).once();
expect(zooReader.getData(eq(ZROOT + ZINSTANCES + "/" + instanceName)))
.andReturn(uuid.getBytes(UTF_8)).once();
- replay(zooReader);
+ replay(context, zooReader);
String testFileName = "./target/zoo-info-viewer-" +
System.currentTimeMillis() + ".txt";
@@ -190,9 +190,9 @@ public class ZooInfoViewerTest {
new String[] {"--print-instances", "--outfile", testFileName});
ZooInfoViewer viewer = new ZooInfoViewer();
- viewer.generateReport(InstanceId.of(uuid), opts, zooReader);
+ viewer.generateReport(context, opts);
- verify(zooReader);
+ verify(context, zooReader);
String line;
try (Scanner scanner = new Scanner(new File(testFileName))) {
@@ -215,8 +215,9 @@ public class ZooInfoViewerTest {
public void propTest() throws Exception {
String uuid = UUID.randomUUID().toString();
InstanceId iid = InstanceId.of(uuid);
-
+ var context = MockServerContext.getWithZK(iid, "fakeHost", 2000);
ZooReader zooReader = createMock(ZooReader.class);
+ expect(context.getZooReader()).andReturn(zooReader).anyTimes();
var instanceName = "test";
expect(zooReader.getChildren(eq(ZROOT +
ZINSTANCES))).andReturn(List.of(instanceName))
.anyTimes();
@@ -237,10 +238,9 @@ public class ZooInfoViewerTest {
return sysPropBytes;
}).once();
- var nsBasePath = ZooUtil.getRoot(iid) + ZNAMESPACES;
-
expect(zooReader.getChildren(nsBasePath)).andReturn(List.of("a")).anyTimes();
- expect(zooReader.getData(eq(nsBasePath + "/a" + ZNAMESPACE_NAME)))
- .andReturn("a_name".getBytes(UTF_8)).anyTimes();
+ var mockNamespaceIdMap = Map.of(NamespaceId.of("a"), "a_name");
+ expect(context.getNamespaceIdToNameMap()).andReturn(mockNamespaceIdMap);
+
var nsPropBytes =
propCodec.toBytes(new VersionedProperties(123, Instant.now(),
Map.of("n1", "nv1")));
NamespaceId nsId = NamespaceId.of("a");
@@ -256,10 +256,10 @@ public class ZooInfoViewerTest {
return nsPropBytes;
}).once();
+ var mockTableIdMap = Map.of(TableId.of("t"), "t_table");
+ expect(context.getTableIdToNameMap()).andReturn(mockTableIdMap).once();
+
var tBasePath = ZooUtil.getRoot(iid) + ZTABLES;
-
expect(zooReader.getChildren(tBasePath)).andReturn(List.of("t")).anyTimes();
- expect(zooReader.getData(eq(tBasePath + "/t" + ZTABLE_NAME)))
- .andReturn("t_table".getBytes(UTF_8)).anyTimes();
var tProps = new VersionedProperties(123, Instant.now(), Map.of("t1",
"tv1"));
var tPropBytes = propCodec.toBytes(tProps);
@@ -279,7 +279,7 @@ public class ZooInfoViewerTest {
expect(zooReader.getData(tBasePath + "/t" + ZTABLE_NAMESPACE))
.andReturn("+default".getBytes(UTF_8)).anyTimes();
- replay(zooReader);
+ replay(context, zooReader);
NamespacePropKey nsKey = NamespacePropKey.of(iid, nsId);
log.trace("namespace base path: {}", nsKey.getPath());
@@ -291,9 +291,9 @@ public class ZooInfoViewerTest {
new String[] {"--print-props", "--outfile", testFileName});
ZooInfoViewer viewer = new ZooInfoViewer();
- viewer.generateReport(InstanceId.of(uuid), opts, zooReader);
+ viewer.generateReport(context, opts);
- verify(zooReader);
+ verify(context, zooReader);
Map<String,String> props = new HashMap<>();
try (Scanner scanner = new Scanner(new File(testFileName))) {
@@ -317,34 +317,15 @@ public class ZooInfoViewerTest {
String uuid = UUID.randomUUID().toString();
InstanceId iid = InstanceId.of(uuid);
- ZooReader zooReader = createMock(ZooReader.class);
- var instanceName = "test";
- expect(zooReader.getChildren(eq(ZROOT +
ZINSTANCES))).andReturn(List.of(instanceName))
- .anyTimes();
- expect(zooReader.getData(eq(ZROOT + ZINSTANCES + "/" + instanceName)))
- .andReturn(uuid.getBytes(UTF_8)).anyTimes();
-
- var nsBasePath = ZooUtil.getRoot(iid) + ZNAMESPACES;
- String aNamespaceId = "a_nsid";
- expect(zooReader.getChildren(nsBasePath))
- .andReturn(List.of("+accumulo", "+default", aNamespaceId)).anyTimes();
- expect(zooReader.getData(eq(nsBasePath + "/+default" + ZNAMESPACE_NAME)))
- .andReturn("".getBytes(UTF_8)).anyTimes();
- expect(zooReader.getData(eq(nsBasePath + "/+accumulo" + ZNAMESPACE_NAME)))
- .andReturn("accumulo".getBytes(UTF_8)).anyTimes();
- expect(zooReader.getData(eq(nsBasePath + "/" + aNamespaceId +
ZNAMESPACE_NAME)))
- .andReturn("a_namespace_name".getBytes(UTF_8)).anyTimes();
-
- var tBasePath = ZooUtil.getRoot(iid) + ZTABLES;
- String aTableId = "t_tid";
-
expect(zooReader.getChildren(tBasePath)).andReturn(List.of(aTableId)).anyTimes();
- expect(zooReader.getData(eq(tBasePath + "/" + aTableId + ZTABLE_NAME)))
- .andReturn("t_tablename".getBytes(UTF_8)).anyTimes();
-
- expect(zooReader.getData(tBasePath + "/" + aTableId + ZTABLE_NAMESPACE))
- .andReturn("+default".getBytes(UTF_8)).anyTimes();
+ var mockNamespaceIdMap = Map.of(NamespaceId.of("+accumulo"), "accumulo",
+ NamespaceId.of("+default"), "", NamespaceId.of("a_nsid"),
"a_namespace_name");
+ var mockTableIdMap = Map.of(TableId.of("t_tid"), "t_tablename");
+ var context = MockServerContext.get();
+ expect(context.getInstanceID()).andReturn(iid).once();
+ expect(context.getNamespaceIdToNameMap()).andReturn(mockNamespaceIdMap);
+ expect(context.getTableIdToNameMap()).andReturn(mockTableIdMap).once();
- replay(zooReader);
+ replay(context);
String testFileName = "./target/zoo-info-viewer-" +
System.currentTimeMillis() + ".txt";
@@ -353,9 +334,9 @@ public class ZooInfoViewerTest {
new String[] {"--print-id-map", "--outfile", testFileName});
ZooInfoViewer viewer = new ZooInfoViewer();
- viewer.generateReport(InstanceId.of(uuid), opts, zooReader);
+ viewer.generateReport(context, opts);
- verify(zooReader);
+ verify(context);
String line;
Map<String,String> ids = new HashMap<>();
@@ -370,8 +351,8 @@ public class ZooInfoViewerTest {
}
log.debug("ids found in output: {}", ids);
- assertEquals(Map.of("+default", "\"\"", "+accumulo", "accumulo",
aNamespaceId,
- "a_namespace_name", aTableId, "t_tablename"), ids);
+ assertEquals(Map.of("+default", "\"\"", "+accumulo", "accumulo",
"a_nsid", "a_namespace_name",
+ "t_tid", "t_tablename"), ids);
}
}
}