Skip to content

Commit

Permalink
Remove unnecessary compiler warning (apache#16475)
Browse files Browse the repository at this point in the history
  • Loading branch information
teabot authored Jul 13, 2022
1 parent 8002756 commit b8d52bf
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ public void testValidationWhenPublicKeyAlgIsInvalid() throws IOException {
}


// Deprecation warning suppressed as this test targets deprecated methods
@SuppressWarnings("deprecation")
@Test
public void testExpiringToken() throws Exception {
SecretKey secretKey = AuthTokenUtils.createSecretKey(SignatureAlgorithm.HS256);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*/
public class MultipleListenerValidatorTest {

// Deprecation warning suppressed as this test targets deprecated methods
@SuppressWarnings("deprecation")
@Test
public void testGetAppliedAdvertised() throws Exception {
ServiceConfiguration config = new ServiceConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertThrows;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -40,7 +40,7 @@
import org.testng.annotations.Test;

public class PulsarConfigurationLoaderTest {
public class MockConfiguration implements PulsarConfiguration {
public static class MockConfiguration implements PulsarConfiguration {
private Properties properties = new Properties();

private String metadataStoreUrl = "zk:localhost:2181";
Expand All @@ -49,7 +49,10 @@ public class MockConfiguration implements PulsarConfiguration {
private Optional<Integer> brokerServicePortTls = Optional.of(7651);
private Optional<Integer> webServicePort = Optional.of(9080);
private Optional<Integer> webServicePortTls = Optional.of(9443);
private int notExistFieldInServiceConfig = 0;

// This unused field is intentionally included to test the ignoreNonExistentMember feature of
// PulsarConfigurationLoader.convertFrom()
private String A_FIELD_THAT_IS_NOT_DECLARED_IN_ServiceConfiguration = "x";

@Override
public Properties getProperties() {
Expand All @@ -63,7 +66,7 @@ public void setProperties(Properties properties) {
}

@Test
public void testConfigurationConverting() throws Exception {
public void testConfigurationConverting() {
MockConfiguration mockConfiguration = new MockConfiguration();
ServiceConfiguration serviceConfiguration = PulsarConfigurationLoader.convertFrom(mockConfiguration);

Expand All @@ -74,18 +77,18 @@ public void testConfigurationConverting() throws Exception {
assertEquals(serviceConfiguration.getBrokerServicePortTls().get(), Integer.valueOf((7651)));
assertEquals(serviceConfiguration.getWebServicePort().get(), Integer.valueOf((9080)));
assertEquals(serviceConfiguration.getWebServicePortTls().get(), Integer.valueOf((9443)));
}

// check whether exception causes
try {
PulsarConfigurationLoader.convertFrom(mockConfiguration, false);
fail();
} catch (Exception e) {
assertEquals(e.getClass(), IllegalArgumentException.class);
}
@Test
public void testConfigurationConverting_checkNonExistMember() {
assertThrows(IllegalArgumentException.class,
() -> PulsarConfigurationLoader.convertFrom(new MockConfiguration(), false));
}

// Deprecation warning suppressed as this test targets deprecated methods
@SuppressWarnings("deprecation")
@Test
public void testPulsarConfiguraitonLoadingStream() throws Exception {
public void testPulsarConfigurationLoadingStream() throws Exception {
File testConfigFile = new File("tmp." + System.currentTimeMillis() + ".properties");
if (testConfigFile.exists()) {
testConfigFile.delete();
Expand Down Expand Up @@ -120,6 +123,7 @@ public void testPulsarConfiguraitonLoadingStream() throws Exception {
assertNotNull(serviceConfig);
assertEquals(serviceConfig.getMetadataStoreUrl(), metadataStoreUrl);
assertTrue(serviceConfig.isBrokerDeleteInactiveTopicsEnabled());

assertEquals(serviceConfig.getBacklogQuotaDefaultLimitGB(), 18);
assertEquals(serviceConfig.getClusterName(), "usc");
assertEquals(serviceConfig.getBrokerClientAuthenticationParameters(), "role:my-role");
Expand All @@ -136,7 +140,7 @@ public void testPulsarConfiguraitonLoadingStream() throws Exception {
}

@Test
public void testPulsarConfiguraitonLoadingProp() throws Exception {
public void testPulsarConfigurationLoadingProp() throws Exception {
final String zk = "zk:localhost:2184";
final Properties prop = new Properties();
prop.setProperty("metadataStoreUrl", zk);
Expand All @@ -146,17 +150,12 @@ public void testPulsarConfiguraitonLoadingProp() throws Exception {
}

@Test
public void testPulsarConfiguraitonComplete() throws Exception {
public void testPulsarConfigurationComplete() throws Exception {
final String zk = "zk:localhost:2184";
final Properties prop = new Properties();
prop.setProperty("metadataStoreUrl", zk);
final ServiceConfiguration serviceConfig = PulsarConfigurationLoader.create(prop, ServiceConfiguration.class);
try {
isComplete(serviceConfig);
fail("it should fail as config is not complete");
} catch (IllegalArgumentException e) {
// Ok
}
assertThrows(IllegalArgumentException.class, () -> isComplete(serviceConfig));
}

@Test
Expand Down Expand Up @@ -221,43 +220,19 @@ public void testBackwardCompatibility() throws IOException {

@Test
public void testComplete() throws Exception {
TestCompleteObject complete = this.new TestCompleteObject();
TestCompleteObject complete = new TestCompleteObject();
assertTrue(isComplete(complete));
}

@Test
public void testInComplete() throws IllegalAccessException {

try {
isComplete(this.new TestInCompleteObjectRequired());
fail("Should fail w/ illegal argument exception");
} catch (IllegalArgumentException iae) {
// OK, expected
}

try {
isComplete(this.new TestInCompleteObjectMin());
fail("Should fail w/ illegal argument exception");
} catch (IllegalArgumentException iae) {
// OK, expected
}

try {
isComplete(this.new TestInCompleteObjectMax());
fail("Should fail w/ illegal argument exception");
} catch (IllegalArgumentException iae) {
// OK, expected
}

try {
isComplete(this.new TestInCompleteObjectMix());
fail("Should fail w/ illegal argument exception");
} catch (IllegalArgumentException iae) {
// OK, expected
}
public void testIncomplete() throws IllegalAccessException {
assertThrows(IllegalArgumentException.class, () -> isComplete(new TestInCompleteObjectRequired()));
assertThrows(IllegalArgumentException.class, () -> isComplete(new TestInCompleteObjectMin()));
assertThrows(IllegalArgumentException.class, () -> isComplete(new TestInCompleteObjectMax()));
assertThrows(IllegalArgumentException.class, () -> isComplete(new TestInCompleteObjectMix()));
}

class TestCompleteObject {
static class TestCompleteObject {
@FieldContext(required = true)
String required = "I am not null";
@FieldContext(required = false)
Expand All @@ -268,25 +243,24 @@ class TestCompleteObject {
int minValue = 2;
@FieldContext(minValue = 1, maxValue = 3)
int minMaxValue = 2;

}

class TestInCompleteObjectRequired {
static class TestInCompleteObjectRequired {
@FieldContext(required = true)
String inValidRequired;
}

class TestInCompleteObjectMin {
static class TestInCompleteObjectMin {
@FieldContext(minValue = 1, maxValue = 3)
long inValidMin = 0;
}

class TestInCompleteObjectMax {
static class TestInCompleteObjectMax {
@FieldContext(minValue = 1, maxValue = 3)
long inValidMax = 4;
}

class TestInCompleteObjectMix {
static class TestInCompleteObjectMix {
@FieldContext(required = true)
String inValidRequired;
@FieldContext(minValue = 1, maxValue = 3)
Expand Down
Loading

0 comments on commit b8d52bf

Please sign in to comment.