You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by do...@apache.org on 2023/02/27 17:41:09 UTC
[accumulo-proxy] branch main updated: Simplify logic in attachIteratorsWithScans() test (#79)
This is an automated email from the ASF dual-hosted git repository.
domgarguilo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo-proxy.git
The following commit(s) were added to refs/heads/main by this push:
new 0f92cb3 Simplify logic in attachIteratorsWithScans() test (#79)
0f92cb3 is described below
commit 0f92cb359b6db9eef4219a766c069e89f69c8bcf
Author: Dom G <do...@apache.org>
AuthorDate: Mon Feb 27 12:41:03 2023 -0500
Simplify logic in attachIteratorsWithScans() test (#79)
* simplifies the logic in attachIteratorsWithScans()
* corrects the use of try-with-resources in importExportTable()
---
.../apache/accumulo/proxy/its/SimpleProxyBase.java | 53 +++++++++-------------
1 file changed, 22 insertions(+), 31 deletions(-)
diff --git a/src/test/java/org/apache/accumulo/proxy/its/SimpleProxyBase.java b/src/test/java/org/apache/accumulo/proxy/its/SimpleProxyBase.java
index d07cd7c..0d71d4e 100644
--- a/src/test/java/org/apache/accumulo/proxy/its/SimpleProxyBase.java
+++ b/src/test/java/org/apache/accumulo/proxy/its/SimpleProxyBase.java
@@ -43,6 +43,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
@@ -1177,44 +1178,32 @@ public abstract class SimpleProxyBase extends SharedMiniClusterBase {
t.start();
// look for the scan many times
- List<ActiveScan> scans = new ArrayList<>();
- for (int i = 0; i < 100 && scans.isEmpty(); i++) {
+ Optional<ActiveScan> scanFromClient = Optional.empty();
+ for (int i = 0; i < 100 && scanFromClient.isEmpty(); i++) {
for (String tserver : client.getTabletServers(sharedSecret)) {
- List<ActiveScan> scansForServer = client.getActiveScans(sharedSecret, tserver);
- for (ActiveScan scan : scansForServer) {
- if (clientPrincipal.equals(scan.getUser())) {
- scans.add(scan);
- }
- }
+ scanFromClient = client.getActiveScans(sharedSecret, tserver).stream()
+ .filter(scan -> clientPrincipal.equals(scan.getUser())).findAny();
- if (!scans.isEmpty()) {
+ if (scanFromClient.isPresent()) {
break;
}
- sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
}
+ sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
}
t.join();
- assertFalse(scans.isEmpty(), "Expected to find scans, but found none");
- boolean found = false;
- Map<String,String> map;
- for (int i = 0; i < scans.size() && !found; i++) {
- ActiveScan scan = scans.get(i);
- if (clientPrincipal.equals(scan.getUser())) {
- assertTrue(
- ScanState.RUNNING.equals(scan.getState()) || ScanState.QUEUED.equals(scan.getState()));
- assertEquals(ScanType.SINGLE, scan.getType());
- assertEquals("slow", scan.getTable());
-
- map = client.tableIdMap(sharedSecret);
- assertEquals(map.get("slow"), scan.getExtent().tableId);
- assertNull(scan.getExtent().endRow);
- assertNull(scan.getExtent().prevEndRow);
- found = true;
- }
- }
+ assertTrue(scanFromClient.isPresent(), "Could not find any scan matching the client principal");
+
+ ActiveScan scan = scanFromClient.get();
+
+ assertTrue(
+ ScanState.RUNNING.equals(scan.getState()) || ScanState.QUEUED.equals(scan.getState()));
+ assertEquals(ScanType.SINGLE, scan.getType());
+ assertEquals("slow", scan.getTable());
- assertTrue(found, "Could not find a scan against the 'slow' table");
+ assertEquals(client.tableIdMap(sharedSecret).get("slow"), scan.getExtent().tableId);
+ assertNull(scan.getExtent().endRow);
+ assertNull(scan.getExtent().prevEndRow);
}
@Test
@@ -1766,8 +1755,10 @@ public abstract class SimpleProxyBase extends SharedMiniClusterBase {
client.offlineTable(sharedSecret, tableName, false);
client.exportTable(sharedSecret, tableName, dir.toString());
// copy files to a new location
- FSDataInputStream is = fs.open(new Path(dir, "distcp.txt"));
- try (BufferedReader r = new BufferedReader(new InputStreamReader(is, UTF_8))) {
+ Path f = new Path(dir, "distcp.txt");
+ try (FSDataInputStream is = fs.open(f);
+ InputStreamReader isr = new InputStreamReader(is, UTF_8);
+ BufferedReader r = new BufferedReader(isr)) {
while (true) {
String line = r.readLine();
if (line == null) {