Use a List instead of a Set for listEvents()
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 1 Jun 2016 21:33:57 +0000 (17:33 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 1 Jun 2016 21:33:57 +0000 (17:33 -0400)
This way it will catch if there incorrectly are duplicate events.

Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
lttng-tools-java/src/main/java/org/lttng/tools/ILttngSession.java
lttng-tools-java/src/main/java/org/lttng/tools/LttngCommandLineSession.java
lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/ListEventsITBase.java

index 704705f25f99b1a9746570adbb469b90fb4e77c6..414e3fb03c19cd9dd42699f4c65f369e85885748 100644 (file)
@@ -19,7 +19,6 @@
 package org.lttng.tools;
 
 import java.util.List;
-import java.util.Set;
 
 /**
  * Java representation of a LTTng tracing session.
@@ -156,7 +155,7 @@ public interface ILttngSession extends AutoCloseable {
      *
      * @return The list of available events
      */
-    Set<String> listEvents();
+    List<String> listEvents();
 
     /**
      * Enable an application context with the provided retriever/context names.
index 3859e2fcd49ca11bd40ebe122ad833de1b8f299b..3f8793be9313bf0b0924c2bd2bd1290e27e516ee 100644 (file)
@@ -23,7 +23,6 @@ import static org.lttng.tools.utils.ShellUtils.executeCommand;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Set;
 import java.util.UUID;
 import java.util.stream.Collectors;
 
@@ -138,13 +137,13 @@ class LttngCommandLineSession implements ILttngSession {
     }
 
     @Override
-    public Set<String> listEvents() {
+    public List<String> listEvents() {
         List<String> output = ShellUtils.getOutputFromCommand(true, Arrays.asList("lttng", "list", domain.flag()));
         return output.stream()
                 .map(e -> e.trim())
                 .filter(e -> e.startsWith("- "))
                 .map(e -> e.substring(2))
-                .collect(Collectors.toSet());
+                .collect(Collectors.toList());
     }
 
     @Override
index dc3a10bb337615bfd97ab409b1c984c485f67153..fdfbc4ec3eaa55eeebc5965891c9205f351bd7cc 100644 (file)
@@ -22,8 +22,8 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.Collections;
+import java.util.List;
 
 import org.junit.After;
 import org.junit.Before;
@@ -70,7 +70,7 @@ public abstract class ListEventsITBase {
     @Test
     public void testManyLoggersNoneAttached() {
         /* Don't attach anything */
-        Set<String> actualEvents = session.listEvents();
+        List<String> actualEvents = session.listEvents();
         assertTrue(actualEvents.isEmpty());
     }
 
@@ -82,8 +82,11 @@ public abstract class ListEventsITBase {
     public void testManyLoggersSomeAttached() {
         attachHandlerToLogger(1, 1);
 
-        Set<String> expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1));
-        Set<String> actualEvents = session.listEvents();
+        List<String> expectedEvents = Arrays.asList(LOGGER_NAME_1);
+        List<String> actualEvents = session.listEvents();
+
+        Collections.sort(expectedEvents);
+        Collections.sort(actualEvents);
 
         assertEquals(expectedEvents, actualEvents);
     }
@@ -98,8 +101,11 @@ public abstract class ListEventsITBase {
         attachHandlerToLogger(2, 2);
         attachHandlerToLogger(2, 3);
 
-        Set<String> expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2, LOGGER_NAME_3));
-        Set<String> actualEvents = session.listEvents();
+        List<String> expectedEvents = Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2, LOGGER_NAME_3);
+        List<String> actualEvents = session.listEvents();
+
+        Collections.sort(expectedEvents);
+        Collections.sort(actualEvents);
 
         assertEquals(expectedEvents, actualEvents);
     }
@@ -116,8 +122,11 @@ public abstract class ListEventsITBase {
         detachHandlerFromLogger(2, 3);
         /* Only loggers 1 and 2 will be attached */
 
-        Set<String> expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2));
-        Set<String> actualEvents = session.listEvents();
+        List<String> expectedEvents = Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2);
+        List<String> actualEvents = session.listEvents();
+
+        Collections.sort(expectedEvents);
+        Collections.sort(actualEvents);
 
         assertEquals(expectedEvents, actualEvents);
     }
@@ -134,7 +143,7 @@ public abstract class ListEventsITBase {
         detachHandlerFromLogger(2, 2);
         detachHandlerFromLogger(2, 3);
 
-        Set<String> actualEvents = session.listEvents();
+        List<String> actualEvents = session.listEvents();
         assertTrue(actualEvents.isEmpty());
     }
 }
This page took 0.033985 seconds and 4 git commands to generate.