Skip to content

Commit

Permalink
User seperate ports for rabbitmq source sink integration tests (apach…
Browse files Browse the repository at this point in the history
…e#9879)

Co-authored-by: Ali Ahmed <[email protected]>
  • Loading branch information
aahmed-se and Ali Ahmed authored Mar 11, 2021
1 parent 96c1402 commit d09dd9b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@

public class RabbitMQBrokerManager {

private final String PORT = "5672";
private final Broker broker = new Broker();


public void startBroker() throws Exception {
BrokerOptions brokerOptions = getBrokerOptions();
public void startBroker(String port) throws Exception {
BrokerOptions brokerOptions = getBrokerOptions(port);
broker.startup(brokerOptions);
}

public void stopBroker() {
broker.shutdown();
}

BrokerOptions getBrokerOptions() throws Exception {
BrokerOptions getBrokerOptions(String port) throws Exception {
Path tmpFolder = Files.createTempDirectory("qpidWork");
Path homeFolder = Files.createTempDirectory("qpidHome");
File etc = new File(homeFolder.toFile(), "etc");
Expand All @@ -53,7 +51,7 @@ BrokerOptions getBrokerOptions() throws Exception {
BrokerOptions brokerOptions = new BrokerOptions();

brokerOptions.setConfigProperty("qpid.work_dir", tmpFolder.toAbsolutePath().toString());
brokerOptions.setConfigProperty("qpid.amqp_port", PORT);
brokerOptions.setConfigProperty("qpid.amqp_port", port);
brokerOptions.setConfigProperty("qpid.home_dir", homeFolder.toAbsolutePath().toString());
String configPath = getFile("qpid.json").getAbsolutePath();
brokerOptions.setInitialConfigurationLocation(configPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final void loadFromYamlFileTest() throws IOException {
RabbitMQSinkConfig config = RabbitMQSinkConfig.load(path);
assertNotNull(config);
assertEquals("localhost", config.getHost());
assertEquals(Integer.parseInt("5672"), config.getPort());
assertEquals(Integer.parseInt("5673"), config.getPort());
assertEquals("/", config.getVirtualHost());
assertEquals("guest", config.getUsername());
assertEquals("guest", config.getPassword());
Expand All @@ -58,7 +58,7 @@ public final void loadFromYamlFileTest() throws IOException {
public final void loadFromMapTest() throws IOException {
Map<String, Object> map = new HashMap<>();
map.put("host", "localhost");
map.put("port", "5672");
map.put("port", "5673");
map.put("virtualHost", "/");
map.put("username", "guest");
map.put("password", "guest");
Expand All @@ -74,7 +74,7 @@ public final void loadFromMapTest() throws IOException {
RabbitMQSinkConfig config = RabbitMQSinkConfig.load(map);
assertNotNull(config);
assertEquals("localhost", config.getHost());
assertEquals(Integer.parseInt("5672"), config.getPort());
assertEquals(Integer.parseInt("5673"), config.getPort());
assertEquals("/", config.getVirtualHost());
assertEquals("guest", config.getUsername());
assertEquals("guest", config.getPassword());
Expand All @@ -92,7 +92,7 @@ public final void loadFromMapTest() throws IOException {
public final void validValidateTest() throws IOException {
Map<String, Object> map = new HashMap<>();
map.put("host", "localhost");
map.put("port", "5672");
map.put("port", "5673");
map.put("virtualHost", "/");
map.put("username", "guest");
map.put("password", "guest");
Expand All @@ -114,7 +114,7 @@ public final void validValidateTest() throws IOException {
public final void missingExchangeValidateTest() throws IOException {
Map<String, Object> map = new HashMap<>();
map.put("host", "localhost");
map.put("port", "5672");
map.put("port", "5673");
map.put("virtualHost", "/");
map.put("username", "guest");
map.put("password", "guest");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ public class RabbitMQSinkTest {
@BeforeMethod
public void setUp() throws Exception {
rabbitMQBrokerManager = new RabbitMQBrokerManager();
rabbitMQBrokerManager.startBroker();
rabbitMQBrokerManager.startBroker("5673");
}

@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception {
public void tearDown() {
rabbitMQBrokerManager.stopBroker();
}

@Test
public void TestOpenAndWriteSink() throws Exception {
Map<String, Object> configs = new HashMap<>();
configs.put("host", "localhost");
configs.put("port", "5672");
configs.put("port", "5673");
configs.put("virtualHost", "default");
configs.put("username", "guest");
configs.put("password", "guest");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;

/**
Expand All @@ -52,8 +53,8 @@ public final void loadFromYamlFileTest() throws IOException {
assertEquals(Integer.parseInt("10000"), config.getHandshakeTimeout());
assertEquals(Integer.parseInt("60"), config.getRequestedHeartbeat());
assertEquals(Integer.parseInt("0"), config.getPrefetchCount());
assertEquals(Boolean.parseBoolean("false"), config.isPrefetchGlobal());
assertEquals(Boolean.parseBoolean("false"), config.isPassive());
assertFalse(config.isPrefetchGlobal());
assertFalse(config.isPassive());
}

@Test
Expand Down Expand Up @@ -90,9 +91,9 @@ public final void loadFromMapTest() throws IOException {
assertEquals(Integer.parseInt("10000"), config.getHandshakeTimeout());
assertEquals(Integer.parseInt("60"), config.getRequestedHeartbeat());
assertEquals(Integer.parseInt("0"), config.getPrefetchCount());
assertEquals(Boolean.parseBoolean("false"), config.isPrefetchGlobal());
assertEquals(Boolean.parseBoolean("false"), config.isPrefetchGlobal());
assertEquals(Boolean.parseBoolean("true"), config.isPassive());
assertEquals(false, config.isPrefetchGlobal());
assertEquals(false, config.isPrefetchGlobal());
assertEquals(true, config.isPassive());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ public class RabbitMQSourceTest {
@BeforeMethod
public void setUp() throws Exception {
rabbitMQBrokerManager = new RabbitMQBrokerManager();
rabbitMQBrokerManager.startBroker();
rabbitMQBrokerManager.startBroker("5672");
}

@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception {
public void tearDown() {
rabbitMQBrokerManager.stopBroker();
}

@Test
public void TestOpenAndWriteSink() throws Exception {
public void TestOpenAndWriteSink() {
Map<String, Object> configs = new HashMap<>();
configs.put("host", "localhost");
configs.put("port", "5672");
Expand Down
2 changes: 1 addition & 1 deletion pulsar-io/rabbitmq/src/test/resources/sinkConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

{
"host": "localhost",
"port": "5672",
"port": "5673",
"virtualHost": "/",
"username": "guest",
"password": "guest",
Expand Down

0 comments on commit d09dd9b

Please sign in to comment.