Skip to content

Commit

Permalink
Issue OpenLiberty#30638 test that requests server dump and captures i…
Browse files Browse the repository at this point in the history
…ntrospector output
  • Loading branch information
njr-11 committed Jan 24, 2025
1 parent 41bef40 commit 6b8b3cb
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
*******************************************************************************/
package test.jakarta.data.errpaths;

import static org.junit.Assert.assertEquals;

import java.io.BufferedInputStream;
import java.util.Scanner;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;

import com.ibm.websphere.simplicity.ProgramOutput;
import com.ibm.websphere.simplicity.ShrinkHelper;

import componenttest.annotation.MinimumJavaLevel;
Expand Down Expand Up @@ -102,10 +110,68 @@ public static void setUp() throws Exception {
// Cause errors that will log FFDC prior to running tests
// so that FFDC doesn't intermittently fail tests
FATServletClient.runTest(server, APP_NAME, "forceFFDC");

// @AfterClass is intentionally omitted so that the server continues running
// for the next class in the suite, which is DataIntrospectorTest.
}

/**
* Dump the server and collect the Jakarta Data introspector output
* for the DataIntrospectorTest to use. Then stop the server.
*/
@AfterClass
public static void tearDown() throws Exception {
ProgramOutput output = server.serverDump();
assertEquals(0, output.getReturnCode());
assertEquals("", output.getStderr());

// Parse standard output. Examples:
//
// Server io.openliberty.data.internal.fat.errpaths dump complete in
// /Users/user/lgit/open-liberty/dev/build.image/wlp/usr/
// servers/io.openliberty.data.internal.fat.errpaths/
// io.openliberty.data.internal.fat.errpaths.dump-18.04.11_14.30.55.zip.
//
// Server io.openliberty.data.internal.fat.errpaths dump complete in
// C:\\jazz-build-engines\\wasrtc-proxy.hursley.ibm.com\\
// EBC.PROD.WASRTC\\build\\dev\\image\\output\\wlp\\usr\\
// servers\\io.openliberty.data.internal.fat.errpaths\\
// io.openliberty.data.internal.fat.errpaths.dump-18.06.10_00.16.59.zip.

String out = output.getStdout();
int end = out.lastIndexOf('.');
int begin = out.lastIndexOf(' ', end) + 1;

String dumpFileName = out.substring(begin, end);

System.out.println("Dump file name: " + dumpFileName);

// Example of file within the zip:
// dump_18.04.11_14.30.55/introspections/JakartaDataIntrospector.txt

end = dumpFileName.indexOf(".zip");
String prefix = "io.openliberty.data.internal.fat.errpaths.dump-";
begin = dumpFileName.lastIndexOf(prefix, end) + prefix.length();

// TODO once it exists, switch to "/introspections/JakartaDataIntrospector.txt";
String introspectorFileName = "dump_" + dumpFileName.substring(begin, end) +
"/introspections/ThreadingIntrospector.txt";

System.out.println("Looking for introspector entry: " + introspectorFileName);

try (ZipFile dumpFile = new ZipFile(dumpFileName)) {
ZipEntry entry = dumpFile.getEntry(introspectorFileName);
System.out.println("Found: " + entry);
try (BufferedInputStream in = new BufferedInputStream(dumpFile.getInputStream(entry));
Scanner scanner = new Scanner(in)) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
System.out.println(line);
DataIntrospectorTest.introspectorOutput.add(line);
}
}
}

server.stopServer(EXPECTED_ERROR_MESSAGES);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package test.jakarta.data.errpaths;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;

import componenttest.custom.junit.runner.FATRunner;
import componenttest.topology.utils.FATServletClient;

/**
* Contains tests that make assertions on the Jakarta Data introspector output.
* The introspector runs at the end of DataErrPathsTest before stopping the server
* so that it contains the state of a running server, and guaranteeing that it is
* available to these tests.
*/
@RunWith(FATRunner.class)
public class DataIntrospectorTest extends FATServletClient {
/**
* Jakarta Data introspector output is captured during DataErrPathsTest.tearDown
*/
static final List<String> introspectorOutput = new ArrayList<>();

/**
* Verify that introspector output was obtained.
*/
@Test
public void testIntrospectorOutputObtained() {
assertEquals(false, introspectorOutput.isEmpty());

// To view output, from the test results page, follow the System.out link
// and search for "testIntrospectorOutputObtained"
for (String line : introspectorOutput)
System.out.println(line);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* Copyright (c) 2024,2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -21,7 +21,8 @@
@RunWith(Suite.class)
@SuiteClasses({
AlwaysPassesTest.class,
DataErrPathsTest.class
DataErrPathsTest.class,
DataIntrospectorTest.class
})
public class FATSuite {
}

0 comments on commit 6b8b3cb

Please sign in to comment.