Skip to content

Commit

Permalink
fixed temporarily ignored unit tests + remaining passivation TODO
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Jul 4, 2022
1 parent 63e52cc commit 66950ca
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 50 deletions.
Expand Up @@ -596,14 +596,6 @@ private void interpretStagedCommand(final StagedCommand command) {
interpretStagedCommand(command.next());
break;
case PASSIVATE:
//TODO: Should be done correctly with connection enforcement. Right now the passivation is
// faster then the command response enforcement. Thus leading to undelivered messages to a dead
// enforcer Actor.
try {
Thread.sleep(1000);
} catch (Exception e) {
throw new IllegalStateException(e);
}
//This actor will stop. Subsequent actions are ignored.
log.debug("Passivating");
passivate();
Expand Down
Expand Up @@ -38,7 +38,6 @@
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import com.typesafe.config.ConfigValueFactory;
Expand Down Expand Up @@ -98,7 +97,6 @@ public void init() {
* is a ConnectionDeleted event.
*/
@Test
@Ignore("TODO TJ fix again")
public void testRecoveryOfDeletedConnectionsWithoutSnapshot() {
new TestKit(actorSystem) {{
final Queue<ConnectivityEvent<?>> existingEvents
Expand Down
Expand Up @@ -78,12 +78,12 @@
import org.eclipse.ditto.connectivity.service.messaging.TestConstants;
import org.eclipse.ditto.connectivity.service.messaging.WithMockServers;
import org.eclipse.ditto.internal.utils.akka.ActorSystemResource;
import org.eclipse.ditto.internal.utils.akka.PingCommand;
import org.eclipse.ditto.internal.utils.akka.controlflow.WithSender;
import org.eclipse.ditto.internal.utils.cluster.DistPubSubAccess;
import org.eclipse.ditto.internal.utils.test.Retry;
import org.eclipse.ditto.thingsearch.model.signals.commands.subscription.CreateSubscription;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

Expand All @@ -108,66 +108,68 @@ public final class ConnectionPersistenceActorTest extends WithMockServers {

@Rule
public final ActorSystemResource actorSystemResource1 = ActorSystemResource.newInstance(
ConfigFactory.parseMap(Map.of("ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.MockClientActorPropsFactory", "pre" +
"-enforcer-provider","org.eclipse.ditto.policies.enforcement.DefaultPreEnforcerProvider"))
.withFallback(TestConstants.CONFIG));
ConfigFactory.parseMap(Map.of(
"ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.MockClientActorPropsFactory"
)).withFallback(TestConstants.CONFIG));

@Rule
public final ActorSystemResource actorSystemResource2 = ActorSystemResource.newInstance(
ConfigFactory.parseMap(Map.of("ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.MockClientActorPropsFactory", "pre" +
"-enforcer-provider","org.eclipse.ditto.policies.enforcement.DefaultPreEnforcerProvider"))
.withFallback(TestConstants.CONFIG));
ConfigFactory.parseMap(Map.of(
"ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.MockClientActorPropsFactory"
)).withFallback(TestConstants.CONFIG));

@Rule
public final ActorSystemResource actorSystemResourceWithBlocklist = ActorSystemResource.newInstance(
ConfigFactory.parseMap(Map.of("ditto.connectivity.connection.client-actor-props-factory",
ConfigFactory.parseMap(Map.of(
"ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.MockClientActorPropsFactory",
"ditto.connectivity.connection.blocked-hostnames",
ConfigValueFactory.fromAnyRef("127.0.0.1"), "pre" +
"-enforcer-provider","org.eclipse.ditto.policies.enforcement.DefaultPreEnforcerProvider"))
ConfigValueFactory.fromAnyRef("127.0.0.1")
))
.withFallback(TestConstants.CONFIG)
);

@Rule
public final ActorSystemResource exceptionalClientProviderSystemResource = ActorSystemResource.newInstance(
ConfigFactory.parseMap(Map.of("ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.ExceptionClientActorPropsFactory", "pre" +
"-enforcer-provider","org.eclipse.ditto.policies.enforcement.DefaultPreEnforcerProvider"))
.withFallback(TestConstants.CONFIG));
ConfigFactory.parseMap(Map.of(
"ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.ExceptionClientActorPropsFactory"
)).withFallback(TestConstants.CONFIG));

@Rule
public final ActorSystemResource exceptionalCommandValidatorSystemResource = ActorSystemResource.newInstance(
ConfigFactory.parseMap(Map.of("ditto.connectivity.connection.client-actor-props-factory",
ConfigFactory.parseMap(Map.of(
"ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.MockClientActorPropsFactory",
"ditto.connectivity.connection.custom-command-interceptor-provider",
"org.eclipse.ditto.connectivity.service.messaging.ExceptionalCommandValidator", "pre" +
"-enforcer-provider","org.eclipse.ditto.policies.enforcement.DefaultPreEnforcerProvider"))
.withFallback(TestConstants.CONFIG));
"org.eclipse.ditto.connectivity.service.messaging.ExceptionalCommandValidator"
)).withFallback(TestConstants.CONFIG));

@Rule
public final ActorSystemResource failingClientProviderSystemResource = ActorSystemResource.newInstance(
ConfigFactory.parseMap(Map.of("ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.FailingActorProvider", "failingRetries",
TestConstants.CONNECTION_CONFIG.getClientActorRestartsBeforeEscalation(), "pre" +
"-enforcer-provider","org.eclipse.ditto.policies.enforcement.DefaultPreEnforcerProvider"))
.withFallback(TestConstants.CONFIG));
ConfigFactory.parseMap(Map.of(
"ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.FailingActorProvider",
"failingRetries",
TestConstants.CONNECTION_CONFIG.getClientActorRestartsBeforeEscalation()
)).withFallback(TestConstants.CONFIG));

@Rule
public final ActorSystemResource tooManyFailingClientProviderSystemResource = ActorSystemResource.newInstance(
ConfigFactory.parseMap(Map.of("ditto.connectivity.connection.client-actor-props-factory",
ConfigFactory.parseMap(Map.of(
"ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.FailingActorProvider", "failingRetries",
1 + TestConstants.CONNECTION_CONFIG.getClientActorRestartsBeforeEscalation(), "pre" +
"-enforcer-provider","org.eclipse.ditto.policies.enforcement.DefaultPreEnforcerProvider"))
.withFallback(TestConstants.CONFIG));
1 + TestConstants.CONNECTION_CONFIG.getClientActorRestartsBeforeEscalation()
)).withFallback(TestConstants.CONFIG));

@Rule
public final ActorSystemResource searchForwardingSystemResource = ActorSystemResource.newInstance(
ConfigFactory.parseMap(Map.of("ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.SearchForwardingClientActorPropsFactory", "pre" +
"-enforcer-provider","org.eclipse.ditto.policies.enforcement.DefaultPreEnforcerProvider"))
.withFallback(TestConstants.CONFIG));
ConfigFactory.parseMap(Map.of(
"ditto.connectivity.connection.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.SearchForwardingClientActorPropsFactory"
)).withFallback(TestConstants.CONFIG));

@Rule
public final TestNameCorrelationId testNameCorrelationId = TestNameCorrelationId.newInstance();
Expand Down Expand Up @@ -826,7 +828,6 @@ public void modifyConnectionClosesAndRestartsClientActor() {
}

@Test
@Ignore("TODO TJ fix again")
public void recoverOpenConnection() throws InterruptedException {
final var mockClientProbe = actorSystemResource1.newTestProbe();
var underTest = TestConstants.createConnectionSupervisorActor(connectionId,
Expand Down Expand Up @@ -855,6 +856,7 @@ public void recoverOpenConnection() throws InterruptedException {
actorSystemResource1.getActorSystem(),
commandForwarderActor,
pubSubMediator));
underTest.tell(PingCommand.of(connectionId, null, null), null);

Awaitility.await().untilAsserted(() -> {
publishChange(new MockClientActorPropsFactory.MockClientActor.ChangeActorRef(
Expand Down
Expand Up @@ -606,11 +606,9 @@ protected long getLatestSnapshotSequenceNumber() {
return confirmedSnapshotRevision;
}

private void notAccessible(final Object message) {
final DittoRuntimeExceptionBuilder<?> builder = newNotAccessibleExceptionBuilder();
if (message instanceof WithDittoHeaders) {
builder.dittoHeaders(((WithDittoHeaders) message).getDittoHeaders());
}
private void notAccessible(final WithDittoHeaders withDittoHeaders) {
final DittoRuntimeExceptionBuilder<?> builder = newNotAccessibleExceptionBuilder()
.dittoHeaders(withDittoHeaders.getDittoHeaders());
notifySender(builder.build());
}

Expand Down Expand Up @@ -641,7 +639,8 @@ protected Receive matchAnyAfterInitialization() {
*/
protected Receive matchAnyWhenDeleted() {
return ReceiveBuilder.create()
.matchAny(this::notAccessible)
.match(WithDittoHeaders.class, this::notAccessible)
.matchAny(m -> log.info("Received message in 'deleted' state - ignoring!: {}", m))
.build();
}

Expand Down

0 comments on commit 66950ca

Please sign in to comment.