-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added unit tests testing EntityTaskScheduler and also EdgeCommandForwraderActor "ordering" aspect * added metric name for EntityTaskScheduler counters * removed WARN log which would get triggered by tasks scheduled basically at the same time * added some more debug logs Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
- Loading branch information
Showing
10 changed files
with
397 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...c/test/java/org/eclipse/ditto/edge/service/dispatching/EdgeCommandForwarderActorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.edge.service.dispatching; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import org.eclipse.ditto.base.model.headers.DittoHeaders; | ||
import org.eclipse.ditto.json.JsonPointer; | ||
import org.eclipse.ditto.json.JsonValue; | ||
import org.eclipse.ditto.policies.model.PolicyId; | ||
import org.eclipse.ditto.things.model.Thing; | ||
import org.eclipse.ditto.things.model.ThingId; | ||
import org.eclipse.ditto.things.model.signals.commands.modify.CreateThing; | ||
import org.eclipse.ditto.things.model.signals.commands.modify.ModifyAttribute; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import com.typesafe.config.ConfigFactory; | ||
|
||
import akka.actor.ActorRef; | ||
import akka.actor.ActorSystem; | ||
import akka.actor.Props; | ||
import akka.testkit.TestProbe; | ||
import akka.testkit.javadsl.TestKit; | ||
|
||
/** | ||
* Unit tests for {@link EdgeCommandForwarderActor}. | ||
*/ | ||
public final class EdgeCommandForwarderActorTest { | ||
|
||
public static final PolicyId POLICY_ID = PolicyId.of("foo:bar"); | ||
public static final ThingId THING_ID = ThingId.of("foo:bar"); | ||
@Nullable private static ActorSystem actorSystem; | ||
|
||
@BeforeClass | ||
public static void init() { | ||
actorSystem = ActorSystem.create("AkkaTestSystem", ConfigFactory.load("test")); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() { | ||
if (actorSystem != null) { | ||
TestKit.shutdownActorSystem(actorSystem); | ||
} | ||
} | ||
|
||
@Test | ||
public void ensureCommandOrderIsMaintainedForSlowSignalTransformations() { | ||
assert actorSystem != null; | ||
new TestKit(actorSystem) {{ | ||
final ShardRegions shardRegionsMock = Mockito.mock(ShardRegions.class); | ||
final TestProbe thingsProbe = new TestProbe(actorSystem); | ||
Mockito.when(shardRegionsMock.things()).thenReturn(thingsProbe.ref()); | ||
|
||
final Props props = EdgeCommandForwarderActor.props(getRef(), shardRegionsMock); | ||
final ActorRef underTest = actorSystem.actorOf(props); | ||
|
||
final CreateThing createThing = CreateThing.of(Thing.newBuilder() | ||
.setId(THING_ID) | ||
.setPolicyId(POLICY_ID) | ||
.build(), | ||
null, | ||
DittoHeaders.newBuilder().correlationId("cid-1-create").build() | ||
); | ||
final ModifyAttribute modifyAttribute = ModifyAttribute.of(THING_ID, | ||
JsonPointer.of("foo"), | ||
JsonValue.of(42), | ||
DittoHeaders.newBuilder().correlationId("cid-2-modify").build() | ||
); | ||
|
||
underTest.tell(createThing, getRef()); | ||
underTest.tell(modifyAttribute, getRef()); | ||
|
||
thingsProbe.expectMsg(createThing); | ||
thingsProbe.expectMsg(modifyAttribute); | ||
}}; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...clipse/ditto/edge/service/dispatching/EdgeCommandForwarderActorTestSignalTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.edge.service.dispatching; | ||
|
||
import java.time.Duration; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.eclipse.ditto.base.model.signals.Signal; | ||
import org.eclipse.ditto.base.service.signaltransformer.SignalTransformer; | ||
import org.eclipse.ditto.things.model.signals.commands.modify.CreateThing; | ||
|
||
import com.typesafe.config.Config; | ||
|
||
import akka.actor.ActorSystem; | ||
|
||
/** | ||
* Signal transformer used for {@link EdgeCommandForwarderActorTest} to artificially delay certain commands in their | ||
* signal transformation. | ||
*/ | ||
public final class EdgeCommandForwarderActorTestSignalTransformer implements SignalTransformer { | ||
|
||
private static final Duration CREATE_THING_TRANSFORMATION_DURATION = Duration.ofMillis(200); | ||
|
||
EdgeCommandForwarderActorTestSignalTransformer(final ActorSystem actorSystem, final Config config) { | ||
} | ||
|
||
@Override | ||
public CompletionStage<Signal<?>> apply(final Signal<?> signal) { | ||
if (signal instanceof CreateThing) { | ||
return new CompletableFuture<Signal<?>>() | ||
.completeOnTimeout(signal, CREATE_THING_TRANSFORMATION_DURATION.toMillis(), TimeUnit.MILLISECONDS); | ||
} else { | ||
return CompletableFuture.completedStage(signal); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.