Migrate to Junit 5 Jupiter
[lttng-ust-java-tests.git] / lttng-ust-java-tests-common / src / test / java / org / lttng / ust / agent / integration / client / TcpClientIT.java
index d89571d536b05f5aa52d3e895122a10fc4757800..0c0af7d68c9aa89ad5f3351440af8256e0992222 100644 (file)
 
 package org.lttng.ust.agent.integration.client;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
 import org.lttng.tools.ILttngSession;
 import org.lttng.tools.LttngToolsHelper;
 import org.lttng.ust.agent.ILttngAgent;
@@ -42,7 +42,7 @@ import org.lttng.ust.agent.session.LogLevelSelector;
 import org.lttng.ust.agent.session.LogLevelSelector.LogLevelType;
 import org.lttng.ust.agent.utils.EventRuleFactory;
 import org.lttng.ust.agent.utils.ILogLevelStrings;
-import org.lttng.ust.agent.utils.TestPrintRunner;
+import org.lttng.ust.agent.utils.TestPrintExtension;
 
 /**
  * Tests for the TCP client only, without using an agent.
@@ -53,7 +53,7 @@ import org.lttng.ust.agent.utils.TestPrintRunner;
  *
  * @author Alexandre Montplaisir
  */
-@RunWith(TestPrintRunner.class)
+@ExtendWith(TestPrintExtension.class)
 public class TcpClientIT {
 
     // ------------------------------------------------------------------------
@@ -72,7 +72,6 @@ public class TcpClientIT {
     /* Test configuration */
     private static final int DOMAIN_VALUE = ILttngAgent.Domain.JUL.value();
     private static final ILttngSession.Domain SESSION_DOMAIN = ILttngSession.Domain.JUL;
-    private static final boolean ROOT_SESSIOND = true;
 
     private static TcpClientDebugListener clientListener;
     private static LttngTcpSessiondClient client;
@@ -87,23 +86,40 @@ public class TcpClientIT {
     /**
      * Class setup
      */
-    @BeforeClass
+    @BeforeAll
     public static void setupClass() {
         LttngToolsHelper.destroyAllSessions();
 
         clientListener = new TcpClientDebugListener();
-        client = new LttngTcpSessiondClient(clientListener, DOMAIN_VALUE, ROOT_SESSIOND);
 
+        /* Try connecting to a root sessiond first */
+        client = new LttngTcpSessiondClient(clientListener, DOMAIN_VALUE, true);
         clientThread = new Thread(client);
         clientThread.start();
 
-        assumeTrue("Timed out waiting for root sessiond", client.waitForConnection(5));
+        if (client.waitForConnection(5)) {
+            return;
+        }
+
+        /* Connection was not established, try a user sessiond instead */
+        client.close();
+        try {
+            clientThread.join();
+        } catch (InterruptedException e) {
+            fail(e.getMessage());
+        }
+
+        client = new LttngTcpSessiondClient(clientListener, DOMAIN_VALUE, false);
+        clientThread = new Thread(client);
+        clientThread.start();
+
+        assertTrue(client.waitForConnection(5), "Timed out waiting for a sessiond");
     }
 
     /**
      * Class teardown
      */
-    @AfterClass
+    @AfterAll
     public static void teardownClass() {
         if (client != null) {
             client.close();
@@ -119,7 +135,7 @@ public class TcpClientIT {
     /**
      * Test setup
      */
-    @Before
+    @BeforeEach
     public void setup() {
         session = ILttngSession.createSession(null, SESSION_DOMAIN);
         clientListener.clearAllCommands();
@@ -128,7 +144,7 @@ public class TcpClientIT {
     /**
      * Test teardown
      */
-    @After
+    @AfterEach
     public void teardown() {
         session.close();
     }
@@ -255,7 +271,7 @@ public class TcpClientIT {
         List<String> expectedDisabledCommands = Arrays.asList(EVENT_NAME_A, EVENT_NAME_B);
 
         assertEquals(expectedEnabledCommands, clientListener.getEnabledEventCommands());
-        assertEquals(expectedDisabledCommands, clientListener.getDisabledEventCommands());
+        assertTrue(clientListener.getDisabledEventCommands().containsAll(expectedDisabledCommands));
     }
 
     /**
@@ -542,7 +558,7 @@ public class TcpClientIT {
     @Test
     public void testContextInFilterString() {
         try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) {
-            session2.enableEvent(EVENT_NAME_A, null, false, "$app." + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A + "=\"bozo\"");
+            session2.enableEvent(EVENT_NAME_A, null, false, "$app." + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A + "==\"bozo\"");
 
             List<String> expectedEnabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A);
             assertEquals(expectedEnabledCommands, clientListener.getEnabledAppContextCommands());
@@ -561,7 +577,7 @@ public class TcpClientIT {
     @Test
     public void testContextEnabledAndInFilterString() {
         try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) {
-            session2.enableEvent(EVENT_NAME_A, null, false, "$app." + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A + "=\"bozo\"");
+            session2.enableEvent(EVENT_NAME_A, null, false, "$app." + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A + "==\"bozo\"");
             session2.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A);
 
             List<String> expectedEnabledCommands = Collections.nCopies(2, CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A);
This page took 0.025623 seconds and 4 git commands to generate.