Skip to content

Commit

Permalink
Cleanup code issues in test srcs (apache#9908)
Browse files Browse the repository at this point in the history
Co-authored-by: Ali Ahmed <[email protected]>
  • Loading branch information
aahmed-se and Ali Ahmed authored Mar 17, 2021
1 parent d0249e5 commit 53c7bdf
Show file tree
Hide file tree
Showing 50 changed files with 156 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.testng.IAnnotationTransformer;
import org.testng.annotations.ITestAnnotation;

@SuppressWarnings("rawtypes")
public class AnnotationListener implements IAnnotationTransformer {

private static final long DEFAULT_TEST_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(5);
Expand All @@ -35,7 +34,10 @@ public AnnotationListener() {
}

@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
public void transform(ITestAnnotation annotation,
Class testClass,
Constructor testConstructor,
Method testMethod) {
annotation.setRetryAnalyzer(RetryAnalyzer.class);

// Enforce default test timeout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class RetryAnalyzer implements IRetryAnalyzer {
private int count = 0;

// Only try again once
private static final int MAX_RETRIES = Integer.valueOf(System.getProperty("testRetryCount", "1"));
private static final int MAX_RETRIES = Integer.parseInt(System.getProperty("testRetryCount", "1"));

@Override
public boolean retry(ITestResult result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class TestRetrySupport {
private int failedSetupNumber = -1;
private int cleanedUpSetupNumber;

@BeforeMethod(groups = "setup")
@BeforeMethod(groups = { "setup", "flaky", "extra" })
public final void stateCheck(Method method) throws Exception {
// run cleanup and setup if the current setup number is the one where a failure happened
// this is to cleanup state before retrying
Expand All @@ -59,7 +59,7 @@ public final void stateCheck(Method method) throws Exception {
}
}

@AfterMethod(alwaysRun = true)
@AfterMethod(alwaysRun = true, groups = { "setup", "flaky", "extra" })
public final void failureCheck(ITestResult testResult, Method method) {
// track the setup number where the failure happened
if (!testResult.isSuccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.apache.bookkeeper.mledger.util.Errors.isNoSuchLedgerExistsException;
import static org.apache.bookkeeper.mledger.util.SafeRun.safeRun;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.BoundType;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -77,7 +76,6 @@
import org.apache.bookkeeper.client.LedgerHandle;
import org.apache.bookkeeper.client.api.ReadHandle;
import org.apache.bookkeeper.common.util.Backoff;
import org.apache.bookkeeper.common.util.JsonUtil;
import org.apache.bookkeeper.common.util.OrderedExecutor;
import org.apache.bookkeeper.common.util.OrderedScheduler;
import org.apache.bookkeeper.common.util.Retries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import org.apache.bookkeeper.client.PulsarMockBookKeeper;
import org.apache.bookkeeper.common.util.OrderedScheduler;
import org.apache.bookkeeper.conf.ClientConfiguration;
import org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig;
import org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl;
import org.apache.bookkeeper.util.ZkUtils;
Expand All @@ -37,6 +36,7 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

/**
* A class runs several bookie servers for testing.
Expand All @@ -54,8 +54,6 @@ public abstract class MockedBookKeeperTestCase {

protected ManagedLedgerFactoryImpl factory;

protected ClientConfiguration baseClientConf = new ClientConfiguration();

protected OrderedScheduler executor;
protected ExecutorService cachedExecutor;

Expand All @@ -68,7 +66,7 @@ public MockedBookKeeperTestCase(int numBookies) {
this.numBookies = numBookies;
}

@BeforeMethod
@BeforeMethod(groups = { "broker" })
public void setUp(Method method) throws Exception {
LOG.info(">>>>>> starting {}", method);
try {
Expand All @@ -85,7 +83,7 @@ public void setUp(Method method) throws Exception {
zkc.create("/managed-ledgers", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}

@AfterMethod(alwaysRun = true)
@AfterMethod(alwaysRun = true, groups = { "broker" })
public void tearDown(Method method) {
try {
LOG.info("@@@@@@@@@ stopping " + method);
Expand All @@ -99,16 +97,20 @@ public void tearDown(Method method) {
}
}

@BeforeClass
@BeforeClass(groups = { "broker" })
public void setUpClass() {
executor = OrderedScheduler.newSchedulerBuilder().numThreads(2).name("test").build();
cachedExecutor = Executors.newCachedThreadPool();
}

@AfterClass(alwaysRun = true)
@AfterClass(alwaysRun = true, groups = { "broker" })
public void tearDownClass() {
executor.shutdown();
cachedExecutor.shutdown();
if (executor != null) {
executor.shutdown();
}
if (cachedExecutor != null) {
cachedExecutor.shutdown();
}
}

/**
Expand All @@ -128,7 +130,7 @@ protected void startBookKeeper() throws Exception {
bkc = new PulsarMockBookKeeper(zkc, executor.chooseThread(this));
}

protected void stopBookKeeper() throws Exception {
protected void stopBookKeeper() {
bkc.shutdown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -1236,7 +1237,7 @@ public void testAuthTlsWithJsonParam() throws Exception {
// Ok
}

// validate Athentication-tls has been configured
// validate Authentication-tls has been configured
Field adminBuilderField = PulsarAdminTool.class.getDeclaredField("adminBuilder");
adminBuilderField.setAccessible(true);
PulsarAdminBuilderImpl builder = (PulsarAdminBuilderImpl) adminBuilderField.get(tool);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public class AuthenticationTest {
@Test
public void testConfigureDefaultFormat() {
try {
MockAuthentication testAuthentication = (MockAuthentication) AuthenticationFactory.create("org.apache.pulsar.client.impl.auth.MockAuthentication", "key1:value1,key2:value2");
MockAuthentication testAuthentication =
(MockAuthentication) AuthenticationFactory.create("org.apache.pulsar.client.impl.auth.MockAuthentication",
"key1:value1,key2:value2");
Assert.assertEquals(testAuthentication.authParamsMap.get("key1"), "value1");
Assert.assertEquals(testAuthentication.authParamsMap.get("key2"), "value2");
} catch (PulsarClientException.UnsupportedAuthenticationException e) {
Expand All @@ -41,7 +43,10 @@ public void testConfigureDefaultFormat() {
@Test
public void testConfigureWrongFormat() {
try {
MockAuthentication testAuthentication = (MockAuthentication) AuthenticationFactory.create("org.apache.pulsar.client.impl.auth.MockAuthentication", "foobar");
MockAuthentication testAuthentication =
(MockAuthentication) AuthenticationFactory.create(
"org.apache.pulsar.client.impl.auth.MockAuthentication",
"foobar");
Assert.assertTrue(testAuthentication.authParamsMap.isEmpty());
} catch (PulsarClientException.UnsupportedAuthenticationException e) {
e.printStackTrace();
Expand All @@ -52,7 +57,9 @@ public void testConfigureWrongFormat() {
@Test
public void testConfigureNull() {
try {
MockAuthentication testAuthentication = (MockAuthentication) AuthenticationFactory.create("org.apache.pulsar.client.impl.auth.MockAuthentication", (String) null);
MockAuthentication testAuthentication = (MockAuthentication) AuthenticationFactory.create(
"org.apache.pulsar.client.impl.auth.MockAuthentication",
(String) null);
Assert.assertTrue(testAuthentication.authParamsMap.isEmpty());
} catch (PulsarClientException.UnsupportedAuthenticationException e) {
e.printStackTrace();
Expand All @@ -63,7 +70,10 @@ public void testConfigureNull() {
@Test
public void testConfigureEmpty() {
try {
MockAuthentication testAuthentication = (MockAuthentication) AuthenticationFactory.create("org.apache.pulsar.client.impl.auth.MockAuthentication", "");
MockAuthentication testAuthentication =
(MockAuthentication) AuthenticationFactory.create(
"org.apache.pulsar.client.impl.auth.MockAuthentication",
"");
Assert.assertTrue(testAuthentication.authParamsMap.isEmpty());
} catch (PulsarClientException.UnsupportedAuthenticationException e) {
e.printStackTrace();
Expand All @@ -74,7 +84,10 @@ public void testConfigureEmpty() {
@Test
public void testConfigurePluginSide() {
try {
MockEncodedAuthenticationParameterSupport testAuthentication = (MockEncodedAuthenticationParameterSupport) AuthenticationFactory.create("org.apache.pulsar.client.impl.auth.MockEncodedAuthenticationParameterSupport", "key1:value1;key2:value2");
MockEncodedAuthenticationParameterSupport testAuthentication =
(MockEncodedAuthenticationParameterSupport) AuthenticationFactory.create(
"org.apache.pulsar.client.impl.auth.MockEncodedAuthenticationParameterSupport",
"key1:value1;key2:value2");
Assert.assertEquals(testAuthentication.authParamsMap.get("key1"), "value1");
Assert.assertEquals(testAuthentication.authParamsMap.get("key2"), "value2");
} catch (PulsarClientException.UnsupportedAuthenticationException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@
public class ConsumerIdTest {
private static final String TOPIC_TEST = "my-topic-1";
private static final String TOPIC_TEST_2 = "my-topic-2";
private static final String SUBCRIBTION_TEST = "my-sub-1";
private static final String SUBSCRIPTION_TEST = "my-sub-1";

@Test
public void getTopicTest() {
ConsumerId testConsumerId = new ConsumerId(TOPIC_TEST, SUBCRIBTION_TEST);
ConsumerId testConsumerId = new ConsumerId(TOPIC_TEST, SUBSCRIPTION_TEST);
assertEquals(TOPIC_TEST, testConsumerId.getTopic());
}

@Test
public void getSubscribtionTest() {
ConsumerId testConsumerId = new ConsumerId(TOPIC_TEST, SUBCRIBTION_TEST);
assertEquals(SUBCRIBTION_TEST, testConsumerId.getSubscription());
public void getSubscriptionTest() {
ConsumerId testConsumerId = new ConsumerId(TOPIC_TEST, SUBSCRIPTION_TEST);
assertEquals(SUBSCRIPTION_TEST, testConsumerId.getSubscription());
}

@Test
public void hashCodeTest() {
ConsumerId testConsumerId = new ConsumerId(TOPIC_TEST, SUBCRIBTION_TEST);
assertEquals(Objects.hashCode(TOPIC_TEST, SUBCRIBTION_TEST), testConsumerId.hashCode());
ConsumerId testConsumerId = new ConsumerId(TOPIC_TEST, SUBSCRIPTION_TEST);
assertEquals(Objects.hashCode(TOPIC_TEST, SUBSCRIPTION_TEST), testConsumerId.hashCode());
}

@Test
public void equalTest() {
ConsumerId testConsumerId1 = new ConsumerId(TOPIC_TEST, SUBCRIBTION_TEST);
ConsumerId testConsumerId2 = new ConsumerId(TOPIC_TEST, SUBCRIBTION_TEST);
ConsumerId testConsumerId3 = new ConsumerId(TOPIC_TEST_2, SUBCRIBTION_TEST);
ConsumerId testConsumerId1 = new ConsumerId(TOPIC_TEST, SUBSCRIPTION_TEST);
ConsumerId testConsumerId2 = new ConsumerId(TOPIC_TEST, SUBSCRIPTION_TEST);
ConsumerId testConsumerId3 = new ConsumerId(TOPIC_TEST_2, SUBSCRIPTION_TEST);

assertEquals(testConsumerId2, testConsumerId1);

Expand All @@ -65,9 +65,9 @@ public void equalTest() {

@Test
public void compareToTest() {
ConsumerId testConsumerId1 = new ConsumerId(TOPIC_TEST, SUBCRIBTION_TEST);
ConsumerId testConsumerId2 = new ConsumerId(TOPIC_TEST, SUBCRIBTION_TEST);
ConsumerId testConsumerId3 = new ConsumerId(TOPIC_TEST_2, SUBCRIBTION_TEST);
ConsumerId testConsumerId1 = new ConsumerId(TOPIC_TEST, SUBSCRIPTION_TEST);
ConsumerId testConsumerId2 = new ConsumerId(TOPIC_TEST, SUBSCRIPTION_TEST);
ConsumerId testConsumerId3 = new ConsumerId(TOPIC_TEST_2, SUBSCRIPTION_TEST);

assertEquals(0, testConsumerId1.compareTo(testConsumerId2));
assertEquals(-1, testConsumerId1.compareTo(testConsumerId3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void testImmediateBatchAckingTracker(boolean isNeedReceipt) throws Except
}

@Test(dataProvider = "isNeedReceipt")
public void testAckTrackerMultiAck(boolean isNeedReceipt) throws Exception {
public void testAckTrackerMultiAck(boolean isNeedReceipt) {
ConsumerConfigurationData<?> conf = new ConsumerConfigurationData<>();
conf.setAcknowledgementsGroupTimeMicros(TimeUnit.SECONDS.toMicros(10));
conf.setAckReceiptEnabled(isNeedReceipt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ void setupClientCnx() throws Exception {

@AfterTest(alwaysRun = true)
void cleanupClientCnx() {
eventLoop.shutdownNow();
if (eventLoop != null) {
eventLoop.shutdownGracefully();
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import static org.apache.pulsar.client.impl.ClientTestFixtures.createDelayedCompletedFuture;
import static org.apache.pulsar.client.impl.ClientTestFixtures.createExceptionFuture;
Expand Down Expand Up @@ -143,7 +142,7 @@ public void testBatchReceiveAsyncCanBeCancelled() {
}

@Test
public void testConsumerCleanupOnSubscribeFailure() throws InterruptedException, TimeoutException, ExecutionException {
public void testConsumerCleanupOnSubscribeFailure() {
ExecutorProvider executorProvider = mock(ExecutorProvider.class);
ConsumerConfigurationData<byte[]> consumerConfData = new ConsumerConfigurationData<>();
consumerConfData.setSubscriptionName("subscriptionName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testResolveBeforeUpdateServiceUrl() {
}

@Test(expectedExceptions = IllegalStateException.class)
public void testResolveUrlBeforeUpdateServiceUrl() throws Exception {
public void testResolveUrlBeforeUpdateServiceUrl() {
resolver.resolveHostUri();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public class UnAckedMessageTrackerTest {

@Test
public void testAddAndRemove() throws Exception {
public void testAddAndRemove() {
PulsarClientImpl client = mock(PulsarClientImpl.class);
Timer timer = new HashedWheelTimer(new DefaultThreadFactory("pulsar-timer", Thread.currentThread().isDaemon()),
1, TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testClone() throws Exception {
}

@Test
public void testToString() throws Exception {
public void testToString() {
DefaultCryptoKeyReaderConfigurationData conf = new DefaultCryptoKeyReaderConfigurationData();
assertEquals(conf.toString(),
"DefaultCryptoKeyReaderConfigurationData(defaultPublicKey=null, defaultPrivateKey=null, publicKeys={}, privateKeys={})");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DoubleSchemaTest {
@Test
public void testSchemaEncode() {
DoubleSchema schema = DoubleSchema.of();
Double data = new Double(12345678.1234);
double data = 12345678.1234;
long longData = Double.doubleToLongBits(data);
byte[] expected = new byte[] {
(byte) (longData >>> 56),
Expand All @@ -46,7 +46,7 @@ public void testSchemaEncode() {
@Test
public void testSchemaEncodeDecodeFidelity() {
DoubleSchema schema = DoubleSchema.of();
Double dbl = new Double(1234578.8754321);
Double dbl = 1234578.8754321;
ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(8);
byte[] bytes = schema.encode(dbl);
byteBuf.writeBytes(bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class FloatSchemaTest {
@Test
public void testSchemaEncode() {
FloatSchema schema = FloatSchema.of();
Float data = new Float(12345678.1234);
float data = (float) 12345678.1234;
long longData = Float.floatToRawIntBits(data);
byte[] expected = new byte[] {
(byte) (longData >>> 24),
Expand All @@ -43,7 +43,7 @@ public void testSchemaEncode() {
public void testSchemaEncodeDecodeFidelity() {
FloatSchema schema = FloatSchema.of();
ByteBuf byteBuf = ByteBufAllocator.DEFAULT.buffer(4);
Float dbl = new Float(1234578.8754321);
Float dbl = (float) 1234578.8754321;
byte[] bytes = schema.encode(dbl);
byteBuf.writeBytes(schema.encode(dbl));
Assert.assertEquals(dbl, schema.decode(bytes));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class ProtobufNativeSchemaUtilsTest {

@Test
public static void testSerialize() throws Exception {
public static void testSerialize() {
byte[] data = ProtobufNativeSchemaUtils.serialize(org.apache.pulsar.client.schema.proto.Test.TestMessage.getDescriptor());
Descriptors.Descriptor descriptor = ProtobufNativeSchemaUtils.deserialize(data);
Assert.assertNotNull(descriptor);
Expand All @@ -34,7 +34,7 @@ public static void testSerialize() throws Exception {
}

@Test
public static void testNestedMessage() throws Exception {
public static void testNestedMessage() {

}

Expand Down
Loading

0 comments on commit 53c7bdf

Please sign in to comment.