From: Alexandre Montplaisir Date: Wed, 1 Jun 2016 21:33:57 +0000 (-0400) Subject: Use a List instead of a Set for listEvents() X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=8f21b7d291f959184bdfecdce96f7b723c185cf4;p=lttng-ust-java-tests.git Use a List instead of a Set for listEvents() This way it will catch if there incorrectly are duplicate events. Signed-off-by: Alexandre Montplaisir --- diff --git a/lttng-tools-java/src/main/java/org/lttng/tools/ILttngSession.java b/lttng-tools-java/src/main/java/org/lttng/tools/ILttngSession.java index 704705f..414e3fb 100644 --- a/lttng-tools-java/src/main/java/org/lttng/tools/ILttngSession.java +++ b/lttng-tools-java/src/main/java/org/lttng/tools/ILttngSession.java @@ -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 listEvents(); + List listEvents(); /** * Enable an application context with the provided retriever/context names. diff --git a/lttng-tools-java/src/main/java/org/lttng/tools/LttngCommandLineSession.java b/lttng-tools-java/src/main/java/org/lttng/tools/LttngCommandLineSession.java index 3859e2f..3f8793b 100644 --- a/lttng-tools-java/src/main/java/org/lttng/tools/LttngCommandLineSession.java +++ b/lttng-tools-java/src/main/java/org/lttng/tools/LttngCommandLineSession.java @@ -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 listEvents() { + public List listEvents() { List 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 diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/ListEventsITBase.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/ListEventsITBase.java index dc3a10b..fdfbc4e 100644 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/ListEventsITBase.java +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/events/ListEventsITBase.java @@ -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 actualEvents = session.listEvents(); + List actualEvents = session.listEvents(); assertTrue(actualEvents.isEmpty()); } @@ -82,8 +82,11 @@ public abstract class ListEventsITBase { public void testManyLoggersSomeAttached() { attachHandlerToLogger(1, 1); - Set expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1)); - Set actualEvents = session.listEvents(); + List expectedEvents = Arrays.asList(LOGGER_NAME_1); + List 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 expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2, LOGGER_NAME_3)); - Set actualEvents = session.listEvents(); + List expectedEvents = Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2, LOGGER_NAME_3); + List 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 expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2)); - Set actualEvents = session.listEvents(); + List expectedEvents = Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2); + List 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 actualEvents = session.listEvents(); + List actualEvents = session.listEvents(); assertTrue(actualEvents.isEmpty()); } }