Skip to content

Commit

Permalink
a) local.yml hs internal values, fixed them
Browse files Browse the repository at this point in the history
    b) static final attributes made UPPER_SNAKE format
    c) Removed logback since dw has it already
    d) Removed the unnecessary AfterEach
    e) Fixed exception handling for junit5
    f) Moved build-check.yml java version to 17 from 11
  • Loading branch information
koushikr committed Dec 6, 2023
1 parent e8a2e24 commit a54b195
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 80 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
cache: maven
- name: Build with Maven
run: mvn -B clean package --file pom.xml
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
cache: maven
distribution: 'temurin'
- name: Build with Maven
run: mvn -B clean package --file pom.xml
33 changes: 24 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
<wiremock.version>3.3.1</wiremock.version>
<mockito.version>4.2.0</mockito.version>

<logback.version>1.2.10</logback.version>
<dropwizard.version>2.1.10</dropwizard.version>
</properties>

Expand Down Expand Up @@ -149,12 +148,6 @@
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jackson</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down Expand Up @@ -190,10 +183,15 @@
<release>${java.release.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<version>0.8.8</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -227,7 +225,10 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<version>3.6.3</version>
<configuration>
<doclint>all,-missing</doclint>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down Expand Up @@ -286,6 +287,20 @@
</plugins>
</build>
</profile>
<!-- The following are required for dns cache manipulator.
Ref: https://github.com/alibaba/java-dns-cache-manipulator#jvm-settings-for-java-16 -->
<profile>
<id>add-java-open-options-for-jdk16+</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<properties>
<argLine>
--add-opens java.base/java.net=ALL-UNNAMED
--add-opens java.base/sun.net=ALL-UNNAMED
</argLine>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,23 @@ protected NodeDataSink<T, TestSerializer<T>> dataSink(Service service) {

@Test
void testInvalidServiceProvider() {
try {
new TestServiceProviderBuilder<>()
.withServiceName("test-service")
.withNamespace("test")
.withHostname("localhost-1")
.withPort(9000)
.build();
} catch (NullPointerException exception) {
Assertions.assertTrue(true, "NPE has been caught");
}
Assertions.assertThrowsExactly(NullPointerException.class, () -> new TestServiceProviderBuilder<>()
.withServiceName("test-service")
.withNamespace("test")
.withHostname("localhost-1")
.withPort(9000)
.build());
}

@Test
void testInvalidServiceProviderNoHealthCheck() {
try {
new TestServiceProviderBuilder<>()
.withServiceName("test-service")
.withNamespace("test")
.withHostname("localhost-1")
.withPort(9000)
.withSerializer(new TestSerializerImpl())
.build();
} catch (Exception exception) {
Assertions.assertTrue(exception instanceof IllegalArgumentException, "Illegal Argument Exception should be thrown");
}
Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> new TestServiceProviderBuilder<>()
.withServiceName("test-service")
.withNamespace("test")
.withHostname("localhost-1")
.withPort(9000)
.withSerializer(new TestSerializerImpl())
.build());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"iterations" : 4,
"threads" : 1,
"forks" : 3,
"mean_ops" : 639973.1997503598
"mean_ops" : 644166.1778513143
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"iterations" : 4,
"threads" : 1,
"forks" : 3,
"mean_ops" : 501189.9391797681
"mean_ops" : 502644.4941310657
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -53,7 +52,7 @@ public abstract class BaseRangerHttpClientTest {
.build();

@BeforeEach
public void startTestCluster() throws Exception {
public void prepareHttpMocks() throws Exception {
val testNode = TestNodeData.builder().shardId(1).build();
val node = ServiceNode.<TestNodeData>builder().host("127.0.0.1").port(80).nodeData(testNode).build();
node.setHealthcheckStatus(HealthcheckStatus.healthy);
Expand Down Expand Up @@ -87,11 +86,6 @@ public void startTestCluster() throws Exception {
log.debug("Started http subsystem");
}

@AfterEach
public void stopTestCluster() {
log.debug("Stopping http subsystem");
}

protected ServiceNodesResponse<TestNodeData> read(final byte[] data) {
try {
return getObjectMapper().readValue(data, new TypeReference<ServiceNodesResponse<TestNodeData>>() {});
Expand Down
5 changes: 0 additions & 5 deletions ranger-http-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@

public class RangerServerBundleTest {

private static final JerseyEnvironment jerseyEnvironment = mock(JerseyEnvironment.class);
private static final MetricRegistry metricRegistry = mock(MetricRegistry.class);
private static final LifecycleEnvironment lifecycleEnvironment = new LifecycleEnvironment(metricRegistry);
private static final Environment environment = mock(Environment.class);
private static final Bootstrap<?> bootstrap = mock(Bootstrap.class);
private static final Configuration configuration = mock(Configuration.class);
private static final JerseyEnvironment JERSEY_ENVIRONMENT = mock(JerseyEnvironment.class);
private static final MetricRegistry METRIC_REGISTRY = mock(MetricRegistry.class);
private static final LifecycleEnvironment LIFECYCLE_ENVIRONMENT = new LifecycleEnvironment(METRIC_REGISTRY);
private static final Environment ENVIRONMENT = mock(Environment.class);
private static final Bootstrap<?> BOOTSTRAP = mock(Bootstrap.class);
private static final Configuration CONFIGURATION = mock(Configuration.class);

private static final RangerServerBundle<TestNodeData, ListBasedServiceRegistry<TestNodeData>, Configuration>
rangerServerBundle = new RangerServerBundle<>() {
RANGER_SERVER_BUNDLE = new RangerServerBundle<>() {

@Override
protected List<RangerHubClient<TestNodeData, ListBasedServiceRegistry<TestNodeData>>> withHubs(Configuration configuration) {
Expand All @@ -68,29 +68,29 @@ protected List<HealthCheck> withHealthChecks(Configuration configuration) {

@BeforeAll
public static void setup() throws Exception {
when(jerseyEnvironment.getResourceConfig()).thenReturn(new DropwizardResourceConfig());
when(environment.jersey()).thenReturn(jerseyEnvironment);
when(environment.lifecycle()).thenReturn(lifecycleEnvironment);
when(environment.getObjectMapper()).thenReturn(new ObjectMapper());
when(JERSEY_ENVIRONMENT.getResourceConfig()).thenReturn(new DropwizardResourceConfig());
when(ENVIRONMENT.jersey()).thenReturn(JERSEY_ENVIRONMENT);
when(ENVIRONMENT.lifecycle()).thenReturn(LIFECYCLE_ENVIRONMENT);
when(ENVIRONMENT.getObjectMapper()).thenReturn(new ObjectMapper());
val adminEnvironment = mock(AdminEnvironment.class);
doNothing().when(adminEnvironment).addTask(any());
when(environment.admin()).thenReturn(adminEnvironment);
when(ENVIRONMENT.admin()).thenReturn(adminEnvironment);

val healthCheckRegistry = mock(HealthCheckRegistry.class);
doNothing().when(healthCheckRegistry).register(anyString(), any());
when(environment.healthChecks()).thenReturn(healthCheckRegistry);
when(ENVIRONMENT.healthChecks()).thenReturn(healthCheckRegistry);

rangerServerBundle.initialize(bootstrap);
rangerServerBundle.run(configuration, environment);
for (val lifeCycle : lifecycleEnvironment.getManagedObjects()) {
RANGER_SERVER_BUNDLE.initialize(BOOTSTRAP);
RANGER_SERVER_BUNDLE.run(CONFIGURATION, ENVIRONMENT);
for (val lifeCycle : LIFECYCLE_ENVIRONMENT.getManagedObjects()) {
lifeCycle.start();
}
}


@Test
void testRangerBundle() {
var hub = rangerServerBundle.getHubs().get(0);
var hub = RANGER_SERVER_BUNDLE.getHubs().get(0);
Assertions.assertTrue(hub instanceof RangerTestHub);
var node = hub.getNode(service).orElse(null);
Assertions.assertNotNull(node);
Expand All @@ -105,7 +105,7 @@ void testRangerBundle() {

@AfterAll
public static void tearDown() throws Exception {
for (LifeCycle lifeCycle : lifecycleEnvironment.getManagedObjects()) {
for (LifeCycle lifeCycle : LIFECYCLE_ENVIRONMENT.getManagedObjects()) {
lifeCycle.stop();
}
}
Expand Down
9 changes: 4 additions & 5 deletions ranger-zk-server/config/local.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
name: ranger-server

rangerConfiguration:
namespace: phonepe
zookeeper: stg-appzk001.phonepe.nb6:2181,stg-appzk002.phonepe.nb6:2181,stg-appzk003.phonepe.nb6:2181
disablePushUpdaters: true
namespace: test
zookeeper: localhost:2181

server:
maxThreads: 1024
minThreads: 1024
maxThreads: 128
minThreads: 128
applicationConnectors:
- type: http
port: 7080
Expand Down
5 changes: 0 additions & 5 deletions ranger-zk-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>

</project>

0 comments on commit a54b195

Please sign in to comment.