You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2020/10/20 14:18:06 UTC

[GitHub] [zookeeper] belugabehr commented on a change in pull request #882: ZOOKEEPER-3342: Use StandardCharsets

belugabehr commented on a change in pull request #882:
URL: https://github.com/apache/zookeeper/pull/882#discussion_r508548510



##########
File path: zookeeper-recipes/zookeeper-recipes-queue/src/test/java/org/apache/zookeeper/recipes/queue/DistributedQueueTest.java
##########
@@ -27,243 +28,260 @@
 import org.junit.Test;
 
 /**
- * Tests for {@link DistributedQueue}.
+ * DistributedQueueTest test.
  */
 public class DistributedQueueTest extends ClientBase {
 
-    @After
-    public void tearDown() throws Exception {
-        super.tearDown();
+  @After
+  public void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  @Test
+  public void testOffer1() throws Exception {
+    String dir = "/testOffer1";
+    String testString = "Hello World";
+    final int numClients = 1;
+    ZooKeeper[] clients = new ZooKeeper[numClients];
+    DistributedQueue[] queueHandles = new DistributedQueue[numClients];
+    for (int i = 0; i < clients.length; i++) {
+      clients[i] = createClient();
+      queueHandles[i] = new DistributedQueue(clients[i], dir, null);
     }
 
-    @Test
-    public void testOffer1() throws Exception {
-        String dir = "/testOffer1";
-        String testString = "Hello World";
-        final int numClients = 1;
-        ZooKeeper[] clients = new ZooKeeper[numClients];
-        DistributedQueue[] queueHandles = new DistributedQueue[numClients];
-        for (int i = 0; i < clients.length; i++) {
-            clients[i] = createClient();
-            queueHandles[i] = new DistributedQueue(clients[i], dir, null);
-        }
-
-        queueHandles[0].offer(testString.getBytes());
-
-        byte[] dequeuedBytes = queueHandles[0].remove();
-        Assert.assertEquals(new String(dequeuedBytes), testString);
+    queueHandles[0].offer(testString.getBytes(UTF_8));
+
+    byte[] dequeuedBytes = queueHandles[0].remove();
+    Assert.assertEquals(new String(dequeuedBytes, UTF_8), testString);
+  }
+
+  @Test
+  public void testOffer2() throws Exception {
+    String dir = "/testOffer2";
+    String testString = "Hello World";
+    final int numClients = 2;
+    ZooKeeper[] clients = new ZooKeeper[numClients];
+    DistributedQueue[] queueHandles = new DistributedQueue[numClients];
+    for (int i = 0; i < clients.length; i++) {
+      clients[i] = createClient();
+      queueHandles[i] = new DistributedQueue(clients[i], dir, null);
     }
 
-    @Test
-    public void testOffer2() throws Exception {
-        String dir = "/testOffer2";
-        String testString = "Hello World";
-        final int numClients = 2;
-        ZooKeeper[] clients = new ZooKeeper[numClients];
-        DistributedQueue[] queueHandles = new DistributedQueue[numClients];
-        for (int i = 0; i < clients.length; i++) {
-            clients[i] = createClient();
-            queueHandles[i] = new DistributedQueue(clients[i], dir, null);
-        }
-
-        queueHandles[0].offer(testString.getBytes());
-
-        byte[] dequeuedBytes = queueHandles[1].remove();
-        Assert.assertEquals(new String(dequeuedBytes), testString);
+    queueHandles[0].offer(testString.getBytes(UTF_8));
+
+    byte[] dequeuedBytes = queueHandles[1].remove();
+    Assert.assertEquals(new String(dequeuedBytes, UTF_8), testString);
+  }
+
+  @Test
+  public void testTake1() throws Exception {
+    String dir = "/testTake1";
+    String testString = "Hello World";
+    final int numClients = 1;
+    ZooKeeper[] clients = new ZooKeeper[numClients];
+    DistributedQueue[] queueHandles = new DistributedQueue[numClients];
+    for (int i = 0; i < clients.length; i++) {
+      clients[i] = createClient();
+      queueHandles[i] = new DistributedQueue(clients[i], dir, null);
     }
 
-    @Test
-    public void testTake1() throws Exception {
-        String dir = "/testTake1";
-        String testString = "Hello World";
-        final int numClients = 1;
-        ZooKeeper[] clients = new ZooKeeper[numClients];
-        DistributedQueue[] queueHandles = new DistributedQueue[numClients];
-        for (int i = 0; i < clients.length; i++) {
-            clients[i] = createClient();
-            queueHandles[i] = new DistributedQueue(clients[i], dir, null);
-        }
-
-        queueHandles[0].offer(testString.getBytes());
-
-        byte[] dequeuedBytes = queueHandles[0].take();
-        Assert.assertEquals(new String(dequeuedBytes), testString);
+    queueHandles[0].offer(testString.getBytes(UTF_8));
+
+    byte[] dequeuedBytes = queueHandles[0].take();
+    Assert.assertEquals(new String(dequeuedBytes, UTF_8), testString);
+  }
+
+  @Test
+  public void testRemove1() throws Exception {
+    String dir = "/testRemove1";
+    String testString = "Hello World";
+    final int numClients = 1;
+    ZooKeeper[] clients = new ZooKeeper[numClients];
+    DistributedQueue[] queueHandles = new DistributedQueue[numClients];
+    for (int i = 0; i < clients.length; i++) {
+      clients[i] = createClient();
+      queueHandles[i] = new DistributedQueue(clients[i], dir, null);
     }
 
-    @Test
-    public void testRemove1() throws Exception {
-        String dir = "/testRemove1";
-        final int numClients = 1;
-        ZooKeeper[] clients = new ZooKeeper[numClients];
-        DistributedQueue[] queueHandles = new DistributedQueue[numClients];
-        for (int i = 0; i < clients.length; i++) {
-            clients[i] = createClient();
-            queueHandles[i] = new DistributedQueue(clients[i], dir, null);
-        }
-
-        try {
-            queueHandles[0].remove();
-        } catch (NoSuchElementException e) {
-            return;
-        }
-
-        Assert.fail();
+    try {
+      queueHandles[0].remove();
+    } catch (NoSuchElementException e) {
+      return;
+    }
+    Assert.assertTrue(false);

Review comment:
       @ctubbsii Thanks for the review.  I'm not sure how these changes came to be. I don't think I changed them manually and instead came from something I did merging this relatively old branch into master branch.  I am working on taking into account some of your feedback now and these types of changes were reverted when I tried to rebase on master again.  Thanks.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org