Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ dependencies {

// Test
testImplementation("org.junit.jupiter:junit-jupiter-engine:6.0.3")
testImplementation("org.junit.vintage:junit-vintage-engine:5.14.1")
testImplementation("org.junit.platform:junit-platform-launcher:1.14.1")
testRuntimeOnly("org.junit.platform:junit-platform-surefire-provider:1.3.2")
testImplementation("org.mock-server:mockserver-netty:5.15.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@
import co.elastic.support.diagnostics.chain.DiagnosticContext;
import co.elastic.support.util.JsonYamlUtils;
import co.elastic.support.util.ResourceCache;
import org.junit.jupiter.api.*;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.io.TempDir;
import org.mockserver.configuration.ConfigurationProperties;
import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.Header;
import org.mockserver.model.HttpRequest;

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -35,12 +44,13 @@
class TestDiagnosticService {
private ClientAndServer mockServer;

private TemporaryFolder folder;
@TempDir
private Path folder;

static private String headerKey1 = "k1";
static private String headerVal1 = "v1";
static private String headerKey2 = "k2";
static private String headerVal2 = "v2";
private static final String headerKey1 = "k1";
private static final String headerVal1 = "v1";
private static final String headerKey2 = "k2";
private static final String headerVal2 = "v2";

@BeforeAll
public void globalSetup() {
Expand All @@ -56,17 +66,6 @@ public void globalTeardown() {
mockServer.stop();
}

@BeforeEach
public void setup() throws IOException {
folder = new TemporaryFolder();
folder.create();
}

@AfterEach
public void tearDown() {
folder.delete();
}

private DiagConfig newDiagConfig() {
try {
return new DiagConfig(
Expand All @@ -82,7 +81,7 @@ private DiagnosticInputs newDiagnosticInputs() {
diagnosticInputs.port = 9880;
diagnosticInputs.diagType = Constants.api;
try {
File outputDir = folder.newFolder();
Path outputDir = Files.createTempDirectory(folder, "diag");
diagnosticInputs.outputDir = outputDir.toString();
} catch (IOException e) {
fail("Unable to create temp directory", e);
Expand Down Expand Up @@ -146,7 +145,7 @@ public HashMap<String, ZipEntry> zipFileContents(File result) throws IOException
public void checkResult(File result, Boolean withLogFile) {
assertTrue(result.toString().matches(".*\\.zip$"), result.toString());
try {
HashMap<String, ZipEntry> contents = zipFileContents(result);
Map<String, ZipEntry> contents = zipFileContents(result);

assertTrue(contents.containsKey("diagnostic_manifest.json"),
() -> contents.keySet().stream().collect(Collectors.joining(", ")));
Expand Down Expand Up @@ -228,9 +227,8 @@ public void run() {
}
};

Thread[] threads = new Thread[3];
Arrays.setAll(threads, i -> new Thread(task.apply(i)));
Arrays.stream(threads).forEach(Thread::start);
List<Thread> threads = List.of(new Thread(task.apply(0)), new Thread(task.apply(1)), new Thread(task.apply(2)));
threads.forEach(Thread::start);

for (Thread t : threads) {
try {
Expand All @@ -244,7 +242,7 @@ public void run() {
}
}
}
assertEquals(results.size(), threads.length);
assertEquals(results.size(), threads.size());
results.forEach((i, result) -> checkResult(result, false));
try {
Enumeration<File> resultFiles = results.elements();
Expand Down