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

[#noissue] Apply junit AutoClose #11762

Merged
merged 1 commit into from
Nov 22, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.navercorp.pinpoint.bootstrap.context.ServerMetaData;
import com.navercorp.pinpoint.bootstrap.context.ServiceInfo;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AutoClose;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -41,22 +41,19 @@
*/
public class DefaultServerMetaDataRegistryServiceTest {

private static final int THREAD_COUNT = 500;
private static final int THREAD_COUNT = 32;

private static final String SERVER_INFO = "testContainerInfo";
private static final List<String> VM_ARGS = Collections.singletonList("testVmArgs");

@AutoClose("shutdown")
private ExecutorService executorService;

@BeforeEach
public void setUp() {
this.executorService = Executors.newFixedThreadPool(THREAD_COUNT);
}

@AfterEach
public void cleanUp() {
this.executorService.shutdown();
}

@Test
public void testRaceConditionWhenAddingConnectors() throws InterruptedException {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.navercorp.pinpoint.web.applicationmap;

import com.google.common.util.concurrent.MoreExecutors;
import com.navercorp.pinpoint.common.server.bo.SimpleAgentKey;
import com.navercorp.pinpoint.common.server.util.AgentLifeCycleState;
import com.navercorp.pinpoint.common.server.util.time.Range;
Expand All @@ -41,18 +40,17 @@
import com.navercorp.pinpoint.web.vo.agent.AgentInfo;
import com.navercorp.pinpoint.web.vo.agent.AgentStatus;
import com.navercorp.pinpoint.web.vo.agent.AgentStatusQuery;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AutoClose;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -68,9 +66,11 @@
*/
public class ApplicationMapBuilderTest {

private final ExecutorService serialExecutor = Executors.newSingleThreadExecutor();
@AutoClose("shutdown")
private static final Executor serialExecutor = Executors.newSingleThreadExecutor();

private final ExecutorService parallelExecutor = Executors.newFixedThreadPool(8);
@AutoClose("shutdown")
private static final Executor parallelExecutor = Executors.newFixedThreadPool(8);

private MapResponseNodeHistogramDataSource mapResponseNodeHistogramDataSource;

Expand Down Expand Up @@ -152,18 +152,6 @@ public List<Optional<AgentStatus>> answer(InvocationOnMock invocation) throws Th
}).when(agentInfoService).getAgentStatus(any());
}

@AfterEach
public void cleanUp() {
shutdownExecutor(serialExecutor);
shutdownExecutor(parallelExecutor);
}

private void shutdownExecutor(ExecutorService executor) {
if (executor != null) {
MoreExecutors.shutdownAndAwaitTermination(executor, Duration.ofSeconds(3));
}
}

@Test
public void testNoCallData() {
Range range = Range.between(0, 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.navercorp.pinpoint.web.applicationmap.appender.histogram;

import com.google.common.util.concurrent.MoreExecutors;
import com.navercorp.pinpoint.common.server.util.time.Range;
import com.navercorp.pinpoint.common.trace.HistogramSlot;
import com.navercorp.pinpoint.common.trace.ServiceType;
Expand All @@ -34,16 +33,15 @@
import com.navercorp.pinpoint.web.vo.Application;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.AutoClose;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.time.Duration;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -61,9 +59,8 @@ public class NodeHistogramAppenderTest {

private final Logger logger = LogManager.getLogger(getClass());

private final ExecutorService executor = Executors.newFixedThreadPool(4);

private final NodeHistogramAppenderFactory nodeHistogramAppenderFactory = new NodeHistogramAppenderFactory(executor);
@AutoClose("shutdown")
private static final Executor executor = Executors.newFixedThreadPool(4);

private WasNodeHistogramDataSource wasNodeHistogramDataSource;

Expand All @@ -75,12 +72,8 @@ public class NodeHistogramAppenderTest {
public void setUp() {
wasNodeHistogramDataSource = mock(WasNodeHistogramDataSource.class);
NodeHistogramFactory nodeHistogramFactory = new DefaultNodeHistogramFactory(wasNodeHistogramDataSource);
nodeHistogramAppender = nodeHistogramAppenderFactory.create(nodeHistogramFactory);
}

@AfterEach
public void cleanUp() {
MoreExecutors.shutdownAndAwaitTermination(executor, Duration.ofSeconds(3));
NodeHistogramAppenderFactory factory = new NodeHistogramAppenderFactory(executor);
nodeHistogramAppender = factory.create(nodeHistogramFactory);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package com.navercorp.pinpoint.web.applicationmap.service;

import com.google.common.util.concurrent.MoreExecutors;
import com.navercorp.pinpoint.common.server.bo.SpanBo;
import com.navercorp.pinpoint.common.server.bo.SpanEventBo;
import com.navercorp.pinpoint.common.server.util.json.JsonField;
Expand Down Expand Up @@ -54,8 +53,8 @@
import com.navercorp.pinpoint.web.view.TimeViewModel;
import com.navercorp.pinpoint.web.view.id.AgentNameView;
import com.navercorp.pinpoint.web.vo.Application;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.AutoClose;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -64,14 +63,13 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.util.CollectionUtils;

import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -93,8 +91,8 @@ public class FilteredMapServiceImplTest {

private static final Random RANDOM = new Random();

private final ExecutorService executor = Executors.newFixedThreadPool(8);

@AutoClose("shutdown")
private static final Executor executor = Executors.newFixedThreadPool(8);

@Mock
private TraceDao traceDao;
Expand Down Expand Up @@ -151,11 +149,6 @@ public void init() {

}

@AfterEach
public void cleanUp() {
MoreExecutors.shutdownAndAwaitTermination(executor, Duration.ofSeconds(3));
}

/**
* USER -> ROOT_APP -> APP_A -> CACHE
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.navercorp.pinpoint.web.task;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.AutoClose;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
Expand All @@ -31,14 +32,15 @@
* @author HyunGil Jeong
*/
public class ChainedTaskDecoratorTest {

@AutoClose
private SimpleAsyncTaskExecutor executor;

@BeforeEach
public void setup() {
executor = new SimpleAsyncTaskExecutor("Test-Worker-");
}


@Test
public void chainedDecoratorsShouldBeCalled() throws InterruptedException {
// Given
Expand All @@ -54,7 +56,7 @@ public void chainedDecoratorsShouldBeCalled() throws InterruptedException {
for (int i = 0; i < testCount; i++) {
executor.execute(new TestWorker(completeLatch));
}
completeLatch.await(5L, TimeUnit.SECONDS);
Assertions.assertTrue(completeLatch.await(5L, TimeUnit.SECONDS));
// Then
Assertions.assertEquals(testCount, decorator1.getCount());
Assertions.assertEquals(testCount, decorator2.getCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.AutoClose;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -38,13 +39,15 @@
public class RequestContextPropagatingTaskDecoratorTest {

private final RequestContextPropagatingTaskDecorator decorator = new RequestContextPropagatingTaskDecorator();
private final SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor("Test-Worker-");
@AutoClose
private SimpleAsyncTaskExecutor executor;

@Mock
private RequestAttributes requestAttributes;

@BeforeEach
public void setup() {
executor = new SimpleAsyncTaskExecutor("Test-Worker-");
executor.setTaskDecorator(decorator);
}

Expand Down Expand Up @@ -72,7 +75,7 @@ public void onError() {
for (int i = 0; i < testCount; i++) {
executor.execute(new TestWorker(completeLatch, workerCallback));
}
completeLatch.await(5, TimeUnit.SECONDS);
Assertions.assertTrue(completeLatch.await(5, TimeUnit.SECONDS));
// Then
boolean testVerified = verifiedFlag.get();
Assertions.assertTrue(testVerified, "RequestContext has not been propagated");
Expand Down
Loading