Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension to make multi-threaded calls run on a single thread for… #240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.extensions.implementation;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mockStatic;

import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.mockito.MockedStatic;

import software.aws.toolkits.eclipse.amazonq.extensions.api.StaticMockExtension;
import software.aws.toolkits.eclipse.amazonq.util.ThreadingUtils;

public final class ThreadingUtilsStaticMockExtension extends StaticMockExtension<ThreadingUtils>
implements BeforeAllCallback, AfterAllCallback {

private MockedStatic<ThreadingUtils> threadingUtilsStaticMock = null;

@Override
public MockedStatic<ThreadingUtils> getStaticMock() {
return threadingUtilsStaticMock;
}

@Override
public void beforeAll(final ExtensionContext context) {
threadingUtilsStaticMock = mockStatic(ThreadingUtils.class);

threadingUtilsStaticMock.when(() -> ThreadingUtils.executeAsyncTask(any(Runnable.class))).then(invocation -> {
Runnable task = invocation.getArgument(0);
task.run();
return null;
});
threadingUtilsStaticMock.when(() -> ThreadingUtils.executeAsyncTaskAndReturnFuture(any(Runnable.class)))
.then(invocation -> {
Runnable task = invocation.getArgument(0);
task.run();
return null;
});
}

@Override
public void afterAll(final ExtensionContext context) throws Exception {
if (threadingUtilsStaticMock != null) {
threadingUtilsStaticMock.close();
}
}

}