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 6b1f549 Make TestProxyClient AutoClosable (#76) 6b1f549 is described below commit 6b1f549dee859d1d1af2622eefcdb71a24cf7023 Author: Dom G <domgargu...@apache.org> AuthorDate: Wed Feb 15 13:52:14 2023 -0500 Make TestProxyClient AutoClosable (#76) * Make TestProxyClient AutoClosable Co-authored-by: Christopher Tubbs <ctubb...@apache.org> --- .../accumulo/proxy/its/ProxyDurabilityIT.java | 70 +++++++++++----------- .../apache/accumulo/proxy/its/SimpleProxyBase.java | 21 +------ .../apache/accumulo/proxy/its/TestProxyClient.java | 14 ++--- 3 files changed, 46 insertions(+), 59 deletions(-) diff --git a/src/test/java/org/apache/accumulo/proxy/its/ProxyDurabilityIT.java b/src/test/java/org/apache/accumulo/proxy/its/ProxyDurabilityIT.java index 791ecfd..83fca91 100644 --- a/src/test/java/org/apache/accumulo/proxy/its/ProxyDurabilityIT.java +++ b/src/test/java/org/apache/accumulo/proxy/its/ProxyDurabilityIT.java @@ -98,7 +98,7 @@ public class ProxyDurabilityIT extends ConfigurableMacBase { proxyProps.put("tokenClass", PasswordToken.class.getName()); proxyProps.putAll(getClientProperties()); - String sharedSecret = "sharedSecret"; + String sharedSecret = "superSecret"; proxyProps.put("sharedSecret", sharedSecret); @@ -111,39 +111,41 @@ public class ProxyDurabilityIT extends ConfigurableMacBase { while (!proxyServer.isServing()) { sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } - Client client = new TestProxyClient("localhost", proxyPort, protocol).proxy(); - - String tableName = getUniqueNames(1)[0]; - client.createTable(sharedSecret, tableName, true, TimeType.MILLIS); - assertTrue(c.tableOperations().exists(tableName)); - - WriterOptions options = new WriterOptions(); - options.setDurability(Durability.NONE); - String writer = client.createWriter(sharedSecret, tableName, options); - Map<ByteBuffer,List<ColumnUpdate>> cells = new TreeMap<>(); - ColumnUpdate column = new ColumnUpdate(bytes("cf"), bytes("cq")); - column.setValue("value".getBytes()); - cells.put(bytes("row"), Collections.singletonList(column)); - client.update(writer, cells); - client.closeWriter(writer); - assertEquals(1, count(c, tableName)); - restartTServer(); - assertEquals(0, count(c, tableName)); - - ConditionalWriterOptions cfg = new ConditionalWriterOptions(); - cfg.setDurability(Durability.SYNC); - String cwriter = client.createConditionalWriter(sharedSecret, tableName, cfg); - ConditionalUpdates updates = new ConditionalUpdates(); - updates.addToConditions(new Condition(new Column(bytes("cf"), bytes("cq"), bytes("")))); - updates.addToUpdates(column); - Map<ByteBuffer,ConditionalStatus> status = - client.updateRowsConditionally(cwriter, Collections.singletonMap(bytes("row"), updates)); - assertEquals(ConditionalStatus.ACCEPTED, status.get(bytes("row"))); - assertEquals(1, count(c, tableName)); - restartTServer(); - assertEquals(1, count(c, tableName)); - - proxyServer.stop(); + try (var proxyClient = new TestProxyClient("localhost", proxyPort, protocol)) { + Client client = proxyClient.proxy(); + String tableName = getUniqueNames(1)[0]; + client.createTable(sharedSecret, tableName, true, TimeType.MILLIS); + assertTrue(c.tableOperations().exists(tableName)); + + WriterOptions options = new WriterOptions(); + options.setDurability(Durability.NONE); + String writer = client.createWriter(sharedSecret, tableName, options); + Map<ByteBuffer,List<ColumnUpdate>> cells = new TreeMap<>(); + ColumnUpdate column = new ColumnUpdate(bytes("cf"), bytes("cq")); + column.setValue("value".getBytes()); + cells.put(bytes("row"), Collections.singletonList(column)); + client.update(writer, cells); + client.closeWriter(writer); + assertEquals(1, count(c, tableName)); + restartTServer(); + assertEquals(0, count(c, tableName)); + + ConditionalWriterOptions cfg = new ConditionalWriterOptions(); + cfg.setDurability(Durability.SYNC); + String cwriter = client.createConditionalWriter(sharedSecret, tableName, cfg); + ConditionalUpdates updates = new ConditionalUpdates(); + updates.addToConditions(new Condition(new Column(bytes("cf"), bytes("cq"), bytes("")))); + updates.addToUpdates(column); + Map<ByteBuffer,ConditionalStatus> status = client.updateRowsConditionally(cwriter, + Collections.singletonMap(bytes("row"), updates)); + assertEquals(ConditionalStatus.ACCEPTED, status.get(bytes("row"))); + assertEquals(1, count(c, tableName)); + restartTServer(); + assertEquals(1, count(c, tableName)); + + } finally { + proxyServer.stop(); + } } } 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 c39ad31..d07cd7c 100644 --- a/src/test/java/org/apache/accumulo/proxy/its/SimpleProxyBase.java +++ b/src/test/java/org/apache/accumulo/proxy/its/SimpleProxyBase.java @@ -1165,21 +1165,13 @@ public abstract class SimpleProxyBase extends SharedMiniClusterBase { // scan Thread t = new Thread(() -> { - String scanner; - TestProxyClient proxyClient2 = null; - try { - proxyClient2 = new TestProxyClient(hostname, proxyPort, factory); - + try (TestProxyClient proxyClient2 = new TestProxyClient(hostname, proxyPort, factory)) { Client client2 = proxyClient2.proxy(); - scanner = client2.createScanner(sharedSecret, "slow", null); + String scanner = client2.createScanner(sharedSecret, "slow", null); client2.nextK(scanner, 10); client2.closeScanner(scanner); } catch (Exception e) { throw new RuntimeException(e); - } finally { - if (proxyClient2 != null) { - proxyClient2.close(); - } } }); t.start(); @@ -1246,18 +1238,11 @@ public abstract class SimpleProxyBase extends SharedMiniClusterBase { // start a compaction Thread t = new Thread(() -> { - TestProxyClient proxyClient2 = null; - try { - proxyClient2 = new TestProxyClient(hostname, proxyPort, factory); - + try (TestProxyClient proxyClient2 = new TestProxyClient(hostname, proxyPort, factory)) { Client client2 = proxyClient2.proxy(); client2.compactTable(sharedSecret, "slow", null, null, null, true, true, null, null); } catch (Exception e) { throw new RuntimeException(e); - } finally { - if (proxyClient2 != null) { - proxyClient2.close(); - } } }); t.start(); diff --git a/src/test/java/org/apache/accumulo/proxy/its/TestProxyClient.java b/src/test/java/org/apache/accumulo/proxy/its/TestProxyClient.java index f3488a8..9fe5cc3 100644 --- a/src/test/java/org/apache/accumulo/proxy/its/TestProxyClient.java +++ b/src/test/java/org/apache/accumulo/proxy/its/TestProxyClient.java @@ -48,9 +48,9 @@ import org.apache.thrift.transport.layered.TFramedTransport; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -public class TestProxyClient { +public class TestProxyClient implements AutoCloseable { - protected TProtocolFactory factory; + protected TProtocolFactory tProtocolFactory; protected TTransport transport; public TestProxyClient(String host, int port) throws TTransportException { @@ -62,7 +62,7 @@ public class TestProxyClient { final TSocket socket = new TSocket(host, port); socket.setTimeout(600000); transport = new TFramedTransport(socket); - factory = protoFactory; + tProtocolFactory = protoFactory; transport.open(); } @@ -77,7 +77,7 @@ public class TestProxyClient { // UGI transport will perform the doAs for us transport.open(); - factory = protoFactory; + tProtocolFactory = protoFactory; } public synchronized void close() { @@ -88,9 +88,9 @@ public class TestProxyClient { } public AccumuloProxy.Client proxy() { - AccumuloProxy.Client.Factory factory1 = new AccumuloProxy.Client.Factory(); - final TProtocol protocol = factory.getProtocol(transport); - return factory1.getClient(protocol); + AccumuloProxy.Client.Factory proxyClientFactory = new AccumuloProxy.Client.Factory(); + final TProtocol protocol = tProtocolFactory.getProtocol(transport); + return proxyClientFactory.getClient(protocol); } @SuppressFBWarnings(value = "HARD_CODE_PASSWORD", justification = "test password is okay")