aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-server-common/src/test/java')
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/platform/serverid/MacAddressProviderTest.java43
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/platform/serverid/ServerIdGeneratorTest.java59
2 files changed, 102 insertions, 0 deletions
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/platform/serverid/MacAddressProviderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/platform/serverid/MacAddressProviderTest.java
new file mode 100644
index 00000000000..6babb49a4cb
--- /dev/null
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/platform/serverid/MacAddressProviderTest.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.serverid;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MacAddressProviderTest {
+
+ @Test
+ public void getSecureMungedAddress() {
+ byte[] address = MacAddressProvider.getSecureMungedAddress();
+ assertThat(address)
+ .isNotEmpty()
+ .hasSize(6);
+ }
+
+ @Test
+ public void constructDummyMulticastAddress() {
+ byte[] address = MacAddressProvider.constructDummyMulticastAddress();
+ assertThat(address)
+ .isNotEmpty()
+ .hasSize(6);
+ }
+}
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/platform/serverid/ServerIdGeneratorTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/platform/serverid/ServerIdGeneratorTest.java
new file mode 100644
index 00000000000..dcb13c12b60
--- /dev/null
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/platform/serverid/ServerIdGeneratorTest.java
@@ -0,0 +1,59 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2024 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.serverid;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ServerIdGeneratorTest {
+ private final ServerIdGenerator underTest = new ServerIdGenerator();
+
+ @Test
+ public void generate_concurrent_test() throws InterruptedException {
+ int rounds = 500;
+ List<String> ids1 = new ArrayList<>(rounds);
+ List<String> ids2 = new ArrayList<>(rounds);
+ Thread t1 = new Thread(() -> {
+ for (int i = 0; i < rounds; i++) {
+ ids1.add(underTest.generate());
+ }
+ });
+ Thread t2 = new Thread(() -> {
+ for (int i = 0; i < rounds; i++) {
+ ids2.add(underTest.generate());
+ }
+ });
+ t1.start();
+ t2.start();
+ t1.join();
+ t2.join();
+
+ Set<String> ids = new HashSet<>(rounds * 2);
+ ids.addAll(ids1);
+ ids.addAll(ids2);
+ assertThat(ids).hasSize(rounds * 2);
+ }
+
+}