Skip to content

Commit

Permalink
[pinpoint-apm#9355] Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Nov 4, 2022
1 parent 092f3e1 commit 9a913e3
Show file tree
Hide file tree
Showing 23 changed files with 75 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class AlarmProcessorTest {
Expand Down Expand Up @@ -78,10 +86,10 @@ public void test() {
AppAlarmChecker appChecker = processor.process(application);

// Validations
verify(alarmService, times(1)).selectRuleByApplicationId(SERVICE_NAME);
verify(applicationIndexDao, times(1)).selectAgentIds(SERVICE_NAME);
verify(alarmService).selectRuleByApplicationId(SERVICE_NAME);
verify(applicationIndexDao).selectAgentIds(SERVICE_NAME);
verify(agentInfoService, times(3)).isActiveAgent(anyString(), any());
verify(dataCollectorFactory, times(1)).createDataCollector(any(), any(), any(), anyLong());
verify(dataCollectorFactory).createDataCollector(any(), any(), any(), anyLong());

assertNotNull(appChecker, "processed object is null");
assertEquals(2, appChecker.getChildren().size(), "rules should be propagated");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.util.Map;

import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -80,8 +80,8 @@ public void whenSequenceCountIsLessThanTimingCountDoSendAlarm() {
writer.write(List.of(new AppAlarmChecker(checkers)));

// then
verify(alarmMessageSender, times(1)).sendSms(checker, 1, null);
verify(alarmMessageSender, times(1)).sendEmail(checker, 1, null);
verify(alarmMessageSender).sendSms(checker, 1, null);
verify(alarmMessageSender).sendEmail(checker, 1, null);
}

@Test
Expand All @@ -101,8 +101,8 @@ public void whenSequenceCountIsEqualToTimingCountDoNotSendAlarm() {
writer.write(List.of(new AppAlarmChecker(checkers)));

// then
verify(alarmMessageSender, times(0)).sendSms(checker, 1, null);
verify(alarmMessageSender, times(0)).sendEmail(checker, 1, null);
verify(alarmMessageSender, never()).sendSms(checker, 1, null);
verify(alarmMessageSender, never()).sendEmail(checker, 1, null);
}

private void mockingAlarmService(CheckerResult beforeCheckerFixture) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import static com.navercorp.pinpoint.common.util.VarArgs.va;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -59,8 +58,8 @@ public void driverConnect() throws SQLException {
driverConnectInterceptor.prepareAfterTrace(driver, va(invalidJdbcUrl), setAccessor, null);
driverConnectInterceptor.doInAfterTrace(spanEventRecorder, driver, va(invalidJdbcUrl), getAccessor, null);

verify(setAccessor, times(1))._$PINPOINT$_setDatabaseInfo(UnKnownDatabaseInfo.INSTANCE);
verify(getAccessor, times(1))._$PINPOINT$_getDatabaseInfo();
verify(setAccessor)._$PINPOINT$_setDatabaseInfo(UnKnownDatabaseInfo.INSTANCE);
verify(getAccessor)._$PINPOINT$_getDatabaseInfo();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import java.util.ArrayList;
import java.util.concurrent.ThreadLocalRandom;

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.never;

/**
* @author Taejin Koo
Expand Down Expand Up @@ -88,7 +88,7 @@ public void skipTest() {
GrpcAgentStatHandlerV2 handler = createMockHandler(mockAgentUriStatService, false);
handler.handleSimple(mockServerRequest);

Mockito.verify(mockAgentUriStatService, times(0)).save(Mockito.any());
Mockito.verify(mockAgentUriStatService, never()).save(Mockito.any());
}

@Test
Expand All @@ -105,7 +105,7 @@ public void handleTest() {
GrpcAgentStatHandlerV2 handler = createMockHandler(mockAgentUriStatService, true);
handler.handleSimple(mockServerRequest);

Mockito.verify(mockAgentUriStatService, times(1)).save(Mockito.any());
Mockito.verify(mockAgentUriStatService).save(Mockito.any());
}

private PAgentUriStat createPAgentUriStat() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

/**
Expand Down Expand Up @@ -61,7 +60,7 @@ public void run() {
}
});

verify(runnableDecorator, times(1)).decorate(any(Runnable.class));
verify(runnableDecorator).decorate(any(Runnable.class));
}

@Test
Expand All @@ -73,7 +72,7 @@ public Object call() throws Exception {
}
});

verify(runnableDecorator, times(1)).decorate(any(Runnable.class));
verify(runnableDecorator).decorate(any(Runnable.class));
}

@Test
Expand All @@ -84,6 +83,6 @@ public void run() {
}
}, new Object());

verify(runnableDecorator, times(1)).decorate(any(Runnable.class));
verify(runnableDecorator).decorate(any(Runnable.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

/**
Expand Down Expand Up @@ -75,7 +74,7 @@ public void handler_should_handle_events_with_empty_message_body() {
ChannelProperties channelProperties = channelPropertiesFactory.newChannelProperties(TEST_CHANNEL_PROPERTIES);
AgentProperty agentProperty = new AgentPropertyChannelAdaptor(channelProperties);
this.agentEventAsyncTaskService.handleEvent(agentProperty, TEST_EVENT_TIMESTAMP, expectedEventType);
verify(this.agentEventService, times(1)).insert(argCaptor.capture());
verify(this.agentEventService).insert(argCaptor.capture());
// then
AgentEventBo actualAgentEventBo = argCaptor.getValue();
assertEquals(TEST_AGENT_ID, actualAgentEventBo.getAgentId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

/**
Expand Down Expand Up @@ -195,7 +194,7 @@ private void runAndVerifyAgentLifeCycle(ManagedAgentLifeCycle managedAgentLifeCy
AgentProperty agentProperty = new AgentPropertyChannelAdaptor(channelProperties);
long eventIdentifier = AgentLifeCycleAsyncTaskService.createEventIdentifier(TEST_SOCKET_ID, expectedEventCounter);
this.agentLifeCycleAsyncTaskService.handleLifeCycleEvent(agentProperty, TEST_EVENT_TIMESTAMP, expectedLifeCycleState, eventIdentifier);
verify(this.agentLifeCycleService, times(1)).insert(argCaptor.capture());
verify(this.agentLifeCycleService).insert(argCaptor.capture());

// then
AgentLifeCycleBo actualAgentLifeCycleBo = argCaptor.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void bug69_Inefficient_exception_is_created_nextElement() {
DelegateEnumeration<String> delegateEnumeration = new DelegateEnumeration<>(enumeration);

Assertions.assertNull(delegateEnumeration.nextElement());
verify(enumeration, times(1)).nextElement();
verify(enumeration).nextElement();

Assertions.assertNull(delegateEnumeration.nextElement());
verify(enumeration, times(2)).nextElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -63,7 +62,7 @@ public void shouldFilterTablesFromDifferentNamespace() {
String tableName = "table1";
HTableDescriptor sameNamespaceHtd = createHtd(namespace, tableName, "CF1");
HTableDescriptor differentNamespaceHtd = createHtd(differentNamespace, tableName, "CF1");
List<HTableDescriptor> htds = Arrays.asList(sameNamespaceHtd, differentNamespaceHtd);
List<HTableDescriptor> htds = List.of(sameNamespaceHtd, differentNamespaceHtd);
HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, htds);

ColumnFamilyChange createColumnFamilyChange = newColumnFamilyChange("CF2");
Expand All @@ -82,7 +81,7 @@ public void creatingExistingTableShouldFail() {
String namespace = "namespace";
String tableName = "table";
HTableDescriptor existingTable = createHtd(namespace, tableName, "CF");
HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, Arrays.asList(existingTable));
HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, List.of(existingTable));

TableChange createTableChange = newTableChange(ChangeType.CREATE, tableName);
ChangeSet createTableChangeSet = newChangeSet(createTableChange);
Expand All @@ -98,7 +97,7 @@ public void modifyingNonExistingTableShouldFail() {
String tableName = "table";
String nonExistingTableName = "anotherTable";
HTableDescriptor existingTable = createHtd(namespace, tableName, "CF");
HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, Arrays.asList(existingTable));
HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, List.of(existingTable));

TableChange modifyTableChange = newTableChange(ChangeType.MODIFY, nonExistingTableName);
ChangeSet modifyTableChangeSet = newChangeSet(modifyTableChange);
Expand Down Expand Up @@ -164,7 +163,7 @@ public void modifyingTheSameTableMultipleTimesShouldBeMerged() {
String newColumnFamily2 = "CF2";

HTableDescriptor existingHtd = createHtd(namespace, tableName, existingColumnFamily);
HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, Arrays.asList(new HTableDescriptor(existingHtd)));
HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, List.of(new HTableDescriptor(existingHtd)));

ChangeSet createColumnFamilyChangeSet1 = newChangeSet(newTableChange(ChangeType.MODIFY, tableName, newColumnFamilyChange(newColumnFamily1)));
ChangeSet createColumnFamilyChangeSet2 = newChangeSet(newTableChange(ChangeType.MODIFY, tableName, newColumnFamilyChange(newColumnFamily2)));
Expand Down Expand Up @@ -224,15 +223,15 @@ public void creatingAndModifyingTheSameTableShouldBeMerged() {
for (TableCommand tableCommand : manager.getCommands()) {
tableCommand.execute(mockHbaseAdminOperation);
}
verify(mockHbaseAdminOperation, times(1)).createTable(any(HTableDescriptor.class));
verify(mockHbaseAdminOperation).createTable(any(HTableDescriptor.class));
}

private ColumnFamilyChange newColumnFamilyChange(String cfName) {
return new CreateColumnFamilyChange(cfName, ColumnFamilyConfiguration.EMPTY_CONFIGURATION);
}

private TableChange newTableChange(ChangeType changeType, String tableName, ColumnFamilyChange... cfChanges) {
List<ColumnFamilyChange> columnFamilyChanges = Arrays.asList(cfChanges);
List<ColumnFamilyChange> columnFamilyChanges = List.of(cfChanges);
switch (changeType) {
case CREATE:
return new CreateTableChange(tableName, TableConfiguration.EMPTY_CONFIGURATION, columnFamilyChanges, CreateTableChange.SplitOption.NONE);
Expand All @@ -244,7 +243,7 @@ private TableChange newTableChange(ChangeType changeType, String tableName, Colu
}

private ChangeSet newChangeSet(TableChange... tableChanges) {
return new ChangeSet("id", "value", Arrays.asList(tableChanges));
return new ChangeSet("id", "value", List.of(tableChanges));
}

private HTableDescriptor createHtd(String namespace, String tableQualifier, String... columnFamilyNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.Date;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -59,7 +58,7 @@ public void saveMetricTag() {
MetricTag metricTag = new MetricTag("applicationId", "hostName", "metricName", "fieldName", new ArrayList<Tag>(), new Date().getTime());
metricTagCache.saveMetricTag(metricTag);

verify(metricTagDao, times(1)).insertMetricTag(metricTag);
verify(metricTagDao).insertMetricTag(metricTag);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.ArrayList;
import java.util.Calendar;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -50,7 +48,7 @@ public void saveMetricDataType2Test() {

MetricDataName metricDataName = new MetricDataName(systemMetric.getMetricName(), systemMetric.getFieldName());
MetricData metricData = new MetricData("metricName", "fieldName", MetricDataType.DOUBLE, metricDataName.getSaveTime());
verify(metricDataTypeCache, times(1)).saveMetricDataType(metricDataName, metricData);
verify(metricDataTypeCache).saveMetricDataType(metricDataName, metricData);
}

@Test
Expand All @@ -64,7 +62,7 @@ public void saveMetricDataType3Test() {

MetricDataName metricDataName = new MetricDataName(systemMetric.getMetricName(), systemMetric.getFieldName());
MetricData metricData = new MetricData("metricName", "fieldName", MetricDataType.DOUBLE, metricDataName.getSaveTime());
verify(metricDataTypeCache, times(1)).saveMetricDataType(metricDataName, metricData);
verify(metricDataTypeCache).saveMetricDataType(metricDataName, metricData);
}

@Test
Expand All @@ -78,6 +76,6 @@ public void saveMetricDataType4Test() {

MetricDataName metricDataName = new MetricDataName(systemMetric.getMetricName(), systemMetric.getFieldName());
MetricData metricData = new MetricData("metricName", "fieldName", MetricDataType.LONG, metricDataName.getSaveTime());
verify(metricDataTypeCache, times(0)).saveMetricDataType(any(MetricDataName.class), any(MetricData.class));
verify(metricDataTypeCache, never()).saveMetricDataType(any(MetricDataName.class), any(MetricData.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -55,8 +55,8 @@ public void saveMetricTag() {
metricTagList.add(metricTag);
MetricTagCollection metricTagCollection = new MetricTagCollection(applicationName, hostName, metricName, fieldName, metricTagList);

verify(metricTagCache, times(1)).updateCacheForMetricTag(metricTagKey, metricTagCollection);
verify(metricTagCache, times(1)).saveMetricTag(metricTag);
verify(metricTagCache).updateCacheForMetricTag(metricTagKey, metricTagCollection);
verify(metricTagCache).saveMetricTag(metricTag);
}

@Test
Expand All @@ -82,8 +82,8 @@ public void saveMetricTag2() {
SystemMetric systemMetric = new DoubleMetric(metricName, hostName, fieldName, 0, tagList, Long.MAX_VALUE);
systemMetricTagService.saveMetricTag(applicationName, systemMetric);

verify(metricTagCache, times(0)).updateCacheForMetricTag(any(MetricTagKey.class), any(MetricTagCollection.class));
verify(metricTagCache, times(0)).saveMetricTag(any(MetricTag.class));
verify(metricTagCache, never()).updateCacheForMetricTag(any(MetricTagKey.class), any(MetricTagCollection.class));
verify(metricTagCache, never()).saveMetricTag(any(MetricTag.class));
}


Expand All @@ -110,8 +110,8 @@ public void saveMetricTag3() {
SystemMetric systemMetric = new DoubleMetric(metricName, hostName, fieldName, 0, new ArrayList<>(), Long.MAX_VALUE);
systemMetricTagService.saveMetricTag(applicationName, systemMetric);

verify(metricTagCache, times(1)).updateCacheForMetricTag(any(MetricTagKey.class), any(MetricTagCollection.class));
verify(metricTagCache, times(1)).saveMetricTag(any(MetricTag.class));
verify(metricTagCache).updateCacheForMetricTag(any(MetricTagKey.class), any(MetricTagCollection.class));
verify(metricTagCache).saveMetricTag(any(MetricTag.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void testHeaderNOTExists() {
interceptor.before("target", new Object[]{request, response});
interceptor.after("target", new Object[]{request, response}, new Object(), null);

verify(traceContext, times(1)).newAsyncTraceObject(anyString());
verify(traceContext).newAsyncTraceObject(anyString());

interceptor.before("target", new Object[]{request, response});
interceptor.after("target", new Object[]{request, response}, new Object(), null);
Expand Down Expand Up @@ -215,7 +215,7 @@ public void testValidHeaderExists() {
interceptor.before("target", new Object[]{request, response});
interceptor.after("target", new Object[]{request, response}, new Object(), null);

verify(traceContext, times(1)).continueAsyncTraceObject((any(TraceId.class)));
verify(traceContext).continueAsyncTraceObject((any(TraceId.class)));

interceptor.before("target", new Object[]{request, response});
interceptor.after("target", new Object[]{request, response}, new Object(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.mockito.Mockito;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;


Expand Down Expand Up @@ -55,6 +54,6 @@ public void testAfter() throws Exception {
final Exception throwable = new Exception();
beanMethodInterceptor.after(thisObject, 10, null, null, throwable);

Mockito.verify(recorder, times(1)).recordException(true, throwable);
Mockito.verify(recorder).recordException(true, throwable);
}
}
Loading

0 comments on commit 9a913e3

Please sign in to comment.