Skip to content

Commit

Permalink
fixed ignored unit test
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 1, 2022
1 parent b591839 commit abd48f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public Receive createReceive() {
}

@Override
protected Receive activeBehaviour(final FI.UnitApply<AbstractPersistenceSupervisor.Control> matchProcessNextTwinMessageBehavior,
protected Receive activeBehaviour(
final FI.UnitApply<AbstractPersistenceSupervisor.Control> matchProcessNextTwinMessageBehavior,
final FI.UnitApply<Object> matchAnyBehavior) {
return ReceiveBuilder.create()
.match(Config.class, this::onConnectivityConfigModified)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import org.eclipse.ditto.policies.model.signals.commands.query.RetrievePolicy;
import org.eclipse.ditto.policies.model.signals.commands.query.RetrievePolicyResponse;
import org.eclipse.ditto.things.api.Permission;
import org.eclipse.ditto.things.api.commands.sudo.SudoRetrieveThing;
import org.eclipse.ditto.things.api.commands.sudo.SudoRetrieveThingResponse;
import org.eclipse.ditto.things.model.Feature;
import org.eclipse.ditto.things.model.Thing;
Expand All @@ -89,7 +88,6 @@
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveAttributeResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThing;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThingResponse;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
Expand Down Expand Up @@ -395,7 +393,6 @@ public void enforceLiveChannelConditionOnModifyCommandFails() {
.setGrantedPermissions(PoliciesResourceType.thingResource(JsonPointer.empty()),
Permissions.newInstance(Permission.READ, Permission.WRITE))
.build();
final JsonObject policyJsonObject = policy.toJson(FieldType.all());

final SudoRetrieveThingResponse sudoRetrieveThingResponse =
SudoRetrieveThingResponse.of(newThingWithAttributeWithPolicyId(policyId), DittoHeaders.empty());
Expand Down Expand Up @@ -484,7 +481,6 @@ public void acceptCreateByImplicitPolicy() {
}

@Test
@Ignore("TODO: CR-11387 pre-enforcement can complete faster for some messages, thus f-ing up the message order")
public void testParallelEnforcementTaskScheduling() {
final Thing thing = newThing().build();
final PolicyId policyId = PolicyId.of(THING_ID);
Expand All @@ -498,8 +494,6 @@ public void testParallelEnforcementTaskScheduling() {
Permissions.newInstance(Permission.READ, Permission.WRITE))
.build();
final CreatePolicyResponse createPolicyResponse = CreatePolicyResponse.of(policyId, policy, headers());
final ThingNotAccessibleException thingNotAccessibleException =
ThingNotAccessibleException.newBuilder(THING_ID).build();
final SudoRetrieveThingResponse sudoRetrieveThingResponse =
SudoRetrieveThingResponse.of(
JsonObject.newBuilder()
Expand All @@ -508,8 +502,6 @@ public void testParallelEnforcementTaskScheduling() {
.set(Thing.JsonFields.REVISION, 1L)
.build(),
headers());
final SudoRetrievePolicyResponse sudoRetrievePolicyResponse =
SudoRetrievePolicyResponse.of(policyId, policy.toJson(FieldType.all()), headers());
final CreateThing createThing = CreateThing.of(thing, null, headers());
final CreateThingResponse createThingResponse = CreateThingResponse.of(thing, headers());
final RetrieveThing retrieveThing = RetrieveThing.of(THING_ID, headers());
Expand All @@ -527,6 +519,9 @@ public void testParallelEnforcementTaskScheduling() {
final RetrieveAttributeResponse retrieveAttributeResponse =
RetrieveAttributeResponse.of(THING_ID, JsonPointer.of("x"), JsonValue.of(5), headers());

when(policyEnforcerProvider.getPolicyEnforcer(policyId))
.thenReturn(CompletableFuture.completedStage(Optional.of(PolicyEnforcer.of(policy))));

new TestKit(system) {{
// GIVEN: all commands are sent in one batch
supervisor.tell(createThing, getRef());
Expand All @@ -535,52 +530,43 @@ public void testParallelEnforcementTaskScheduling() {
supervisor.tell(modifyAttribute, getRef());
supervisor.tell(retrieveAttribute, getRef());

// THEN: expect enforcement start: CreateThing
expectAndAnswerSudoRetrieveThing(thingNotAccessibleException);
policiesShardRegionProbe.expectMsgClass(CreatePolicy.class);

// THEN: no other message should come through before enforcement of CreateThing completes
thingPersistenceActorProbe.expectNoMessage(Duration.create(150, TimeUnit.MILLISECONDS));

// WHEN: CreateThing completes
policiesShardRegionProbe.reply(createPolicyResponse);

thingPersistenceActorProbe.expectMsgClass(CreateThing.class);
thingPersistenceActorProbe.reply(createThingResponse);

// THEN: the next commands are dispatched until authorization change happens again
expectAndAnswerSudoRetrieveThing(sudoRetrieveThingResponse);
expectMsgClass(CreateThingResponse.class);

thingPersistenceActorProbe.expectMsgClass(RetrieveThing.class);
final ActorRef retrieveThingSender = thingPersistenceActorProbe.lastSender();
thingPersistenceActorProbe.expectMsgClass(ModifyPolicyId.class);
final ActorRef modifyPolicyIdSender = thingPersistenceActorProbe.lastSender();

// THEN: the authorization-changing command causes a cache reload
thingPersistenceActorProbe.expectMsgClass(SudoRetrieveThing.class);
retrieveThingSender.tell(retrieveThingResponse, ActorRef.noSender());

// WHEN: cache reload completes
thingPersistenceActorProbe.reply(sudoRetrieveThingResponse);
expectAndAnswerSudoRetrievePolicy(policyId, sudoRetrievePolicyResponse);
expectAndAnswerSudoRetrieveThing(sudoRetrieveThingResponse);
expectMsgClass(RetrieveThingResponse.class);
expectAndAnswerSudoRetrieveThing(sudoRetrieveThingResponse);

thingPersistenceActorProbe.expectMsgClass(ModifyPolicyId.class);
final ActorRef modifyPolicyIdSender = thingPersistenceActorProbe.lastSender();
modifyPolicyIdSender.tell(modifyPolicyIdResponse, ActorRef.noSender());

// THEN: the other queued commands are dispatched
expectAndAnswerSudoRetrieveThing(sudoRetrieveThingResponse);
expectMsgClass(ModifyPolicyIdResponse.class);

thingPersistenceActorProbe.expectMsgClass(ModifyAttribute.class);
final ActorRef modifyAttributeSender = thingPersistenceActorProbe.lastSender();
thingPersistenceActorProbe.expectMsgClass(RetrieveAttribute.class);
final ActorRef retrieveAttributeSender = thingPersistenceActorProbe.lastSender();

// THEN: responses are delivered to the command sender
modifyAttributeSender.tell(modifyAttributeResponse, ActorRef.noSender());

// and THEN: order of command responses is preserved
expectMsgClass(CreateThingResponse.class);
expectMsgClass(ModifyPolicyIdResponse.class);
expectAndAnswerSudoRetrieveThing(sudoRetrieveThingResponse);
expectMsgClass(ModifyAttributeResponse.class);

// ThingQueryCommandResponses involve a detour. If sent together, arrival order won't be deterministic.
thingPersistenceActorProbe.expectMsgClass(RetrieveAttribute.class);
final ActorRef retrieveAttributeSender = thingPersistenceActorProbe.lastSender();
retrieveAttributeSender.tell(retrieveAttributeResponse, ActorRef.noSender());

expectAndAnswerSudoRetrieveThing(sudoRetrieveThingResponse);
expectMsgClass(RetrieveAttributeResponse.class);
retrieveThingSender.tell(retrieveThingResponse, ActorRef.noSender());
expectMsgClass(RetrieveThingResponse.class);
}};
}

Expand Down

0 comments on commit abd48f7

Please sign in to comment.