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

Commit

Permalink
Merge pull request #29 from patientsknowbest/PHR-6960_move_all_testsu…
Browse files Browse the repository at this point in the history
…pport_pulsar

Move all TestSupport functions to Pulsar PHR-6960
  • Loading branch information
karsaig authored Aug 20, 2020
2 parents f9ebfd1 + 924feaf commit b019a9a
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 119 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<changelist>-SNAPSHOT</changelist>
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
<javax.inject.version>1</javax.inject.version>
<phr-pulsar.version>8-5b37c53-65399</phr-pulsar.version>
<phr-pulsar.version>10-48a4bac-83953</phr-pulsar.version>
<restassured.version>3.0.7-PKB</restassured.version>
</properties>

Expand Down Expand Up @@ -134,6 +134,11 @@
<artifactId>testlogging</artifactId>
<version>${revision}${changelist}</version>
</dependency>
<dependency>
<groupId>com.pkb.pkbcommon</groupId>
<artifactId>config</artifactId>
<version>${revision}${changelist}</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
Expand Down
9 changes: 9 additions & 0 deletions testsupport/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
<groupId>com.pkb.pkbcommon</groupId>
<artifactId>testlogging</artifactId>
</dependency>
<dependency>
<groupId>com.pkb.pkbcommon</groupId>
<artifactId>config</artifactId>
</dependency>
<dependency>
<groupId>com.pkb.pkbcommon</groupId>
<artifactId>infrastructure</artifactId>
<version>${revision}${changelist}</version>
</dependency>
<dependency>
<groupId>com.pkb</groupId>
<artifactId>pulsar</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.pkb.common.testsupport;

import com.pkb.common.ClearableInternalState;
import com.pkb.common.config.ConfigStorage;
import com.pkb.common.datetime.DateTimeService;
import com.pkb.pulsar.payload.ClearTestStatesRequest;
import com.pkb.pulsar.payload.ClearTestStatesResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Set;

class ClearTestStatesService {

private static final Logger LOGGER = LoggerFactory.getLogger(java.lang.invoke.MethodHandles.lookup().lookupClass());

private final DateTimeService dateTimeService;
private final ConfigStorage configStorage;
private final Set<ClearableInternalState> clearables;

ClearTestStatesService(DateTimeService dateTimeService, ConfigStorage configStorage, Set<ClearableInternalState> clearables) {
this.dateTimeService = dateTimeService;
this.configStorage = configStorage;
this.clearables = clearables;
}

ClearTestStatesResponse process(ClearTestStatesRequest message) {
LOGGER.info("ClearTestStatesService.process message received");

boolean clearFixedTimestamp = message.getClearFixedTimestamp();
if (clearFixedTimestamp) {
dateTimeService.forgetFixedCurrentTimeForTesting();
}

if (configStorage.isMutableConfigEnabled()) {
configStorage.reset();
}

clearables.forEach(ClearableInternalState::clearState);

LOGGER.info("ClearTestStatesService.process done.");

return ClearTestStatesResponse.newBuilder().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.pkb.common.testsupport;

import com.pkb.common.config.ConfigStorage;
import com.pkb.pulsar.payload.InjectConfigRequest;
import com.pkb.pulsar.payload.InjectConfigResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class InjectConfigValueService {

private static final Logger LOGGER = LoggerFactory.getLogger(java.lang.invoke.MethodHandles.lookup().lookupClass());

private ConfigStorage configStorage;

public InjectConfigValueService(ConfigStorage configStorage) {
this.configStorage = configStorage;
}

public InjectConfigResponse process(InjectConfigRequest message) {
LOGGER.info("InjectConfigValueService.process message received");
String key = message.getKey();
String value = message.getValue();
LOGGER.info(String.format("InjectConfigValueService.process setting key %s to value %s", key, value));

boolean success = true;
if (configStorage.isMutableConfigEnabled()) {
configStorage.setValue(key, value);
} else {
success = false;
}

LOGGER.info("InjectConfigValueService.process done.");
return InjectConfigResponse.newBuilder().setKey(key).setValue(value).setSuccess(success).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.pkb.common.testsupport;

import com.pkb.common.config.BaseConfig;
import com.pkb.pulsar.payload.LogTestNameRequest;
import com.pkb.pulsar.payload.LogTestNameResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class LogTestNameService {

private static final Logger LOGGER = LoggerFactory.getLogger(java.lang.invoke.MethodHandles.lookup().lookupClass());

private final BaseConfig config;

LogTestNameService(BaseConfig config) {
this.config = config;
}

LogTestNameResponse process(LogTestNameRequest message) {
LOGGER.info("LogTestNameService.process message received");
String testName = message.getTestName();
boolean success = true;
if (config.isFakeDateTimeServiceEnabled()) {
LOGGER.info("test name is now {}", testName);
} else {
success = false;
}

LOGGER.info("LogTestNameService.process done.");

return LogTestNameResponse.newBuilder().setTestName(testName).setSuccess(success).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,35 @@ public class TestControlRequestService implements MessageListener<TestControlReq
private final String serviceName;
private final SetFixedTimestampService setFixedTimestampService;
private final PulsarNamespaceChangeService pulsarNamespaceChangeService;
private final InjectConfigValueService injectConfigValueService;
private final ClearTestStatesService clearTestStatesService;
private final LogTestNameService logTestNameService;
private final ToggleDetailedLoggingService toggleDetailedLoggingService;

public TestControlRequestService(
@NotNull Producer<TestControlResponse> testControlResponseProducer,
@NotNull String serviceName,
@NotNull PulsarNamespaceChangeService pulsarNamespaceChangeService,
@NotNull SetFixedTimestampService setFixedTimestampService) {
@NotNull SetFixedTimestampService setFixedTimestampService,
@NotNull InjectConfigValueService injectConfigValueService,
@NotNull ClearTestStatesService clearTestStatesService,
@NotNull LogTestNameService logTestNameService,
@NotNull ToggleDetailedLoggingService toggleDetailedLoggingService) {
this.testControlResponseProducer = testControlResponseProducer;
this.serviceName = serviceName;
this.pulsarNamespaceChangeService = pulsarNamespaceChangeService;
this.setFixedTimestampService = setFixedTimestampService;
this.injectConfigValueService = injectConfigValueService;
this.clearTestStatesService = clearTestStatesService;
this.logTestNameService = logTestNameService;
this.toggleDetailedLoggingService = toggleDetailedLoggingService;
}

@Override
public void received(Consumer<TestControlRequest> consumer, Message<TestControlRequest> message) {
try {
consumer.acknowledge(message); // because the testSupprot framework is exercising closed loop control we can acknowledge here
LOGGER.info("TestControlRequestService message recieved");
LOGGER.info("TestControlRequestService message received");
MessageType messageType = message.getValue().getMessageType();
LOGGER.info(String.format("messageType %s", messageType));
TestControlResponse.Builder response = TestControlResponse.newBuilder()
Expand All @@ -48,10 +60,21 @@ public void received(Consumer<TestControlRequest> consumer, Message<TestControlR
case SET_NAMESPACE:
response.setNamespaceChangeResponse(pulsarNamespaceChangeService.process(message.getValue().getNamespaceChangeRequest()));
break;

case SET_FIXED_TIMESTAMP:
response.setSetFixedTimestampResponse(setFixedTimestampService.process(message.getValue().getSetFixedTimestampRequest()));
break;
case INJECT_CONFIG_VALUE:
response.setInjectConfigResponse(injectConfigValueService.process(message.getValue().getInjectConfigRequest()));
break;
case CLEAR_TEST_STATES:
response.setClearTestStatesResponse(clearTestStatesService.process(message.getValue().getClearTestStatesRequest()));
break;
case LOG_TEST_NAME:
response.setLogTestNameResponse(logTestNameService.process(message.getValue().getLogTestNameRequest()));
break;
case TOGGLE_DETAILED_LOGGING:
response.setToggleDetailedLoggingResponse(toggleDetailedLoggingService.process(message.getValue().getToggleDetailedLoggingRequest()));
break;
}
testControlResponseProducer.newMessage().value(response.build()).send();
LOGGER.info("TestControlRequestService response sent");
Expand Down
Loading

0 comments on commit b019a9a

Please sign in to comment.