Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #238 from galasa-dev/eventsservice-remote-only
Browse files Browse the repository at this point in the history
Only register KafkaEventsService if remote run
  • Loading branch information
jadecarino authored Jun 28, 2024
2 parents daeb91f + d36b870 commit 7a6df1c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
package dev.galasa.events.kafka.internal;

import java.net.URI;

import javax.validation.constraints.NotNull;

import org.osgi.service.component.annotations.Component;
Expand All @@ -27,13 +29,18 @@ public void initialise(@NotNull IFrameworkInitialisation frameworkInitialisation

try {

IFramework framework = frameworkInitialisation.getFramework();
URI cps = frameworkInitialisation.getBootstrapConfigurationPropertyStore();

// If the CPS is ETCD, then register this version of the EventsService
if (cps.getScheme().equals("etcd")) {
IFramework framework = frameworkInitialisation.getFramework();

SystemEnvironment env = new SystemEnvironment();
KafkaEventProducerFactory producerFactory = new KafkaEventProducerFactory(env);
IConfigurationPropertyStoreService cpsService = framework.getConfigurationPropertyService(NAMESPACE);
SystemEnvironment env = new SystemEnvironment();
KafkaEventProducerFactory producerFactory = new KafkaEventProducerFactory(env);
IConfigurationPropertyStoreService cpsService = framework.getConfigurationPropertyService(NAMESPACE);

frameworkInitialisation.registerEventsService(new KafkaEventsService(cpsService, producerFactory));
frameworkInitialisation.registerEventsService(new KafkaEventsService(cpsService, producerFactory));
}

} catch (Exception e) {
throw new KafkaException("Unable to register the Kafka Events Service", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import static org.assertj.core.api.Assertions.*;

import java.net.URI;
import java.util.List;

import dev.galasa.events.kafka.internal.KafkaEventsService;
Expand All @@ -24,11 +25,12 @@ public void TestCanCreateARegistrationOK() {
}

@Test
public void TestCanInitialiseARegistrationOK() throws Exception {
public void TestWhenRemoteRunCanInitialiseARegistrationOK() throws Exception {
// Given...
KafkaEventsServiceRegistration registration = new KafkaEventsServiceRegistration();

MockFrameworkInitialisation mockFrameworkInit = new MockFrameworkInitialisation();
URI uri = new URI("etcd://my.server/api");
MockFrameworkInitialisation mockFrameworkInit = new MockFrameworkInitialisation(uri);

// When...
registration.initialise(mockFrameworkInit);
Expand All @@ -38,5 +40,21 @@ public void TestCanInitialiseARegistrationOK() throws Exception {
assertThat(eventsServices).isNotNull().hasSize(1);
assertThat(eventsServices.get(0)).isInstanceOf(KafkaEventsService.class);
}

@Test
public void TestWhenLocalRunDoesNotInitialiseRegistration() throws Exception {
// Given...
KafkaEventsServiceRegistration registration = new KafkaEventsServiceRegistration();

URI uri = new URI("notetcd://my.server/api");
MockFrameworkInitialisation mockFrameworkInit = new MockFrameworkInitialisation(uri);

// When...
registration.initialise(mockFrameworkInit);

// Then...
List<IEventsService> eventsServices = mockFrameworkInit.getRegisteredEventsServices();
assertThat(eventsServices).isNotNull().hasSize(0);
}

}

0 comments on commit 7a6df1c

Please sign in to comment.