Skip to content

Commit

Permalink
Update PerformanceAnalyzerAppTest
Browse files Browse the repository at this point in the history
Signed-off-by: Khushboo Rajput <[email protected]>
  • Loading branch information
khushbr committed Aug 14, 2023
1 parent 882b99a commit 7904c0f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public static Thread startGrpcServerThread(
return grpcServerThread;
}

public static Thread startReaderThread(
public static void startReaderThread(
final AppContext appContext, final ThreadProvider threadProvider) {
PluginSettings settings = PluginSettings.instance();
final Thread readerThread =
Expand Down Expand Up @@ -273,7 +273,6 @@ public static Thread startReaderThread(
},
PerformanceAnalyzerThreads.PA_READER);
readerThread.start();
return readerThread;
}

private static void handleReaderThreadFailed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,17 @@ public void testStartReaderThreadOneAttemptFailed() throws Exception {
ThreadProvider threadProvider = new ThreadProvider();
AppContext appContext = new AppContext();

Thread readerThread = PerformanceAnalyzerApp.startReaderThread(appContext, threadProvider);
readerThread.interrupt();
PowerMockito.mockStatic(ESLocalhostConnection.class);
ReaderMetricsProcessor readerMetricsProcessor = mock(ReaderMetricsProcessor.class);
doThrow(new RuntimeException("Force Crashing Reader Thread"))
.doNothing()
.when(readerMetricsProcessor)
.run();
PowerMockito.whenNew(ReaderMetricsProcessor.class)
.withAnyArguments()
.thenReturn(readerMetricsProcessor);

PerformanceAnalyzerApp.startReaderThread(appContext, threadProvider);
Assert.assertTrue(
"READER_RESTART_PROCESSING metric missing",
RcaTestHelper.verifyStatException(
Expand Down Expand Up @@ -112,12 +121,15 @@ public void testStartReaderThreadAllAttemptFail() throws Exception {
.thenReturn(200);
PerformanceAnalyzerApp.startReaderThread(appContext, threadProvider);
Assert.assertTrue(
"READER_RESTART_PROCESSING metric missing",
RcaTestHelper.verifyStatException(
StatExceptionCode.READER_RESTART_PROCESSING.toString()));
Assert.assertTrue(
"READER_ERROR_PA_DISABLE_SUCCESS metric missing",
RcaTestHelper.verifyStatException(
StatExceptionCode.READER_ERROR_PA_DISABLE_SUCCESS.toString()));
Assert.assertTrue(
"READER_ERROR_RCA_AGENT_STOPPED metric missing",
RcaTestHelper.verifyStatException(
StatExceptionCode.READER_ERROR_RCA_AGENT_STOPPED.toString()));
exit.expectSystemExitWithStatus(1);
Expand All @@ -129,12 +141,15 @@ public void testStartReaderThreadAllAttemptFail() throws Exception {
.thenReturn(500);
PerformanceAnalyzerApp.startReaderThread(appContext, threadProvider);
Assert.assertTrue(
"READER_RESTART_PROCESSING metric missing",
RcaTestHelper.verifyStatException(
StatExceptionCode.READER_RESTART_PROCESSING.toString()));
Assert.assertTrue(
"READER_ERROR_PA_DISABLE_FAILED metric missing",
RcaTestHelper.verifyStatException(
StatExceptionCode.READER_ERROR_PA_DISABLE_FAILED.toString()));
Assert.assertTrue(
"READER_ERROR_RCA_AGENT_STOPPED metric missing",
RcaTestHelper.verifyStatException(
StatExceptionCode.READER_ERROR_RCA_AGENT_STOPPED.toString()));
exit.expectSystemExitWithStatus(1);
Expand Down

0 comments on commit 7904c0f

Please sign in to comment.