Skip to content

Commit

Permalink
CAMEL-19609: fixed a cyclic dependency issue with camel-test-infra-hdfs
Browse files Browse the repository at this point in the history
  • Loading branch information
orpiske committed Jul 17, 2023
1 parent 4fdebeb commit 947d2ef
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.infra.hdfs.v2.services.HDFSService;
import org.apache.camel.test.infra.hdfs.v2.services.HDFSServiceFactory;
import org.apache.camel.test.junit5.CamelTestSupport;
Expand All @@ -40,7 +41,7 @@

public class HdfsAppendIT extends CamelTestSupport {
@RegisterExtension
public static HDFSService service = HDFSServiceFactory.createSingletonService();
public static HDFSService service = HDFSServiceFactory.createSingletonService(AvailablePortFinder.getNextAvailable());

private static final Logger LOG = LoggerFactory.getLogger(HdfsAppendIT.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.support.DefaultScheduledPollConsumerScheduler;
import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.infra.hdfs.v2.services.HDFSService;
import org.apache.camel.test.infra.hdfs.v2.services.HDFSServiceFactory;
import org.apache.camel.test.junit5.CamelTestSupport;
Expand Down Expand Up @@ -58,7 +59,7 @@

public class HdfsConsumerIntegrationIT extends CamelTestSupport {
@RegisterExtension
public static HDFSService service = HDFSServiceFactory.createSingletonService();
public static HDFSService service = HDFSServiceFactory.createSingletonService(AvailablePortFinder.getNextAvailable());

private static final int ITERATIONS = 200;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.infra.hdfs.v2.services.HDFSService;
import org.apache.camel.test.infra.hdfs.v2.services.HDFSServiceFactory;
import org.apache.camel.test.junit5.CamelTestSupport;
Expand All @@ -42,7 +43,7 @@

public class HdfsProducerConsumerIntegrationIT extends CamelTestSupport {
@RegisterExtension
public static HDFSService service = HDFSServiceFactory.createSingletonService();
public static HDFSService service = HDFSServiceFactory.createSingletonService(AvailablePortFinder.getNextAvailable());

private static final int ITERATIONS = 400;

Expand Down
6 changes: 0 additions & 6 deletions test-infra/camel-test-infra-hdfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@
<type>test-jar</type>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-junit5</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-minicluster</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class EmbeddedHDFSService implements HDFSService {
private static final Logger LOG = LoggerFactory.getLogger(EmbeddedHDFSService.class);
private final HDFSContainer container;

public EmbeddedHDFSService() {
container = new HDFSContainer();
public EmbeddedHDFSService(int port) {
container = new HDFSContainer(port);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.camel.test.infra.hdfs.v2.services;

import org.apache.camel.test.AvailablePortFinder;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.slf4j.Logger;
Expand All @@ -25,15 +24,19 @@
public class HDFSContainer {
private static final Logger LOG = LoggerFactory.getLogger(HDFSContainer.class);

private final int port;
private MiniDFSCluster cluster;

public HDFSContainer(int port) {
this.port = port;
}

public void start() {
try {
Configuration conf = new Configuration();
conf.set("dfs.namenode.fs-limits.max-directory-items", "1048576");
cluster = new MiniDFSCluster.Builder(conf)
.nameNodePort(AvailablePortFinder.getNextAvailable())
.nameNodePort(port)
.numDataNodes(3)
.format(true)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public int getPort() {
}
}

private static HDFSService INSTANCE;

private HDFSServiceFactory() {

}
Expand All @@ -46,16 +48,13 @@ public static SimpleTestServiceBuilder<HDFSService> builder() {
return new SimpleTestServiceBuilder<>("hdfs");
}

public static HDFSService createSingletonService() {
return SingletonServiceHolder.INSTANCE;
}

private static class SingletonServiceHolder {
static final HDFSService INSTANCE;
static {
public static HDFSService createSingletonService(int port) {
if (INSTANCE == null) {
SimpleTestServiceBuilder<HDFSService> instance = builder();
instance.addLocalMapping(() -> new SingletonHDFSService(new EmbeddedHDFSService(), "hdfs"));
instance.addLocalMapping(() -> new SingletonHDFSService(new EmbeddedHDFSService(port), "hdfs"));
INSTANCE = instance.build();
}

return INSTANCE;
}
}

0 comments on commit 947d2ef

Please sign in to comment.