Skip to content

Commit 0394310

Browse files
authored
Merge pull request #2087 from beyonnex-io/log-thing-id-in-wot-validation-errors
add missing thingId to log of failed WoT validations
2 parents feebb83 + 5b56fb3 commit 0394310

File tree

45 files changed

+260
-233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+260
-233
lines changed

things/service/src/main/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/AbstractThingCommandStrategy.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public Result<ThingEvent<?>> apply(final Context<ThingId> context, @Nullable fin
9595
final long nextRevision, final C command) {
9696

9797
final var dittoHeaders = command.getDittoHeaders();
98-
final var dittoHeadersBuilder = dittoHeaders.toBuilder();
98+
final var dittoHeadersBuilder = dittoHeaders.toBuilder()
99+
.putHeader(DittoHeaderDefinition.ENTITY_ID.getKey(), context.getState().toString());
99100
final var loggerWithCorrelationId = context.getLog().withCorrelationId(command);
100101
final var thingConditionFailed = dittoHeaders.getCondition()
101102
.flatMap(condition -> ThingConditionValidator.validate(command, condition, entity));

things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/ETagTestUtils.java

+43-32
Large diffs are not rendered by default.

things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/ThingPersistenceActorCleanupTest.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
import java.util.List;
2020
import java.util.stream.Collectors;
2121

22+
import org.apache.pekko.actor.ActorRef;
23+
import org.apache.pekko.testkit.javadsl.TestKit;
2224
import org.eclipse.ditto.base.api.persistence.cleanup.CleanupPersistence;
2325
import org.eclipse.ditto.base.api.persistence.cleanup.CleanupPersistenceResponse;
26+
import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition;
2427
import org.eclipse.ditto.base.model.headers.DittoHeaders;
2528
import org.eclipse.ditto.base.model.signals.events.EventsourcedEvent;
2629
import org.eclipse.ditto.internal.utils.tracing.DittoTracingInitResource;
@@ -41,9 +44,6 @@
4144
import org.slf4j.Logger;
4245
import org.slf4j.LoggerFactory;
4346

44-
import org.apache.pekko.actor.ActorRef;
45-
import org.apache.pekko.testkit.javadsl.TestKit;
46-
4747
/**
4848
* Unit test for the cleanup of {@link ThingPersistenceActor}.
4949
*/
@@ -131,7 +131,10 @@ private EventsourcedEvent<?> sendModifyThing(final Thing modifiedThing, final Ac
131131
modifiedThing, null, dittoHeadersV2);
132132
underTest.tell(modifyThingCommand, getRef());
133133

134-
expectMsgEquals(modifyThingResponse(modifiedThing, dittoHeadersV2));
134+
expectMsgEquals(modifyThingResponse(modifiedThing, dittoHeadersV2.toBuilder().putHeader(
135+
DittoHeaderDefinition.ENTITY_ID.getKey(), modifiedThing.getEntityId().get().toString())
136+
.build()
137+
));
135138

136139
return toEvent(modifyThingCommand, modifiedThing);
137140
}
@@ -188,7 +191,8 @@ public void testDeletedThingIsCleanedUpCorrectly() {
188191

189192
private static ModifyThingResponse modifyThingResponse(final Thing modifiedThing,
190193
final DittoHeaders dittoHeaders) {
191-
final DittoHeaders dittoHeadersWithETag = ETagTestUtils.appendETagToDittoHeaders(modifiedThing, dittoHeaders);
194+
final DittoHeaders dittoHeadersWithETag = ETagTestUtils.appendEntityIdAndETagToDittoHeaders(
195+
modifiedThing.getEntityId().get(), modifiedThing, dittoHeaders);
192196
return ModifyThingResponse.modified(modifiedThing.getEntityId().get(), dittoHeadersWithETag);
193197
}
194198

things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/ThingPersistenceActorSnapshottingTest.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
import java.util.Arrays;
1717
import java.util.Collections;
1818

19+
import org.apache.pekko.actor.ActorRef;
20+
import org.apache.pekko.actor.PoisonPill;
21+
import org.apache.pekko.testkit.javadsl.TestKit;
1922
import org.assertj.core.api.Assertions;
2023
import org.eclipse.ditto.base.model.common.HttpStatus;
24+
import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition;
2125
import org.eclipse.ditto.base.model.signals.events.EventsourcedEvent;
2226
import org.eclipse.ditto.internal.utils.config.DittoConfigError;
2327
import org.eclipse.ditto.internal.utils.test.Retry;
@@ -48,10 +52,6 @@
4852
import com.typesafe.config.Config;
4953
import com.typesafe.config.ConfigValueFactory;
5054

51-
import org.apache.pekko.actor.ActorRef;
52-
import org.apache.pekko.actor.PoisonPill;
53-
import org.apache.pekko.testkit.javadsl.TestKit;
54-
5555
/**
5656
* Unit test for the snapshotting functionality of {@link ThingPersistenceActor}.
5757
*/
@@ -101,7 +101,9 @@ public void deletedThingIsSnapshotWithCorrectDataAndCanBeRecreated() {
101101

102102
final DeleteThing deleteThing = DeleteThing.of(thingId, dittoHeadersV2);
103103
underTest.tell(deleteThing, getRef());
104-
expectMsgEquals(DeleteThingResponse.of(thingId, dittoHeadersV2));
104+
expectMsgEquals(DeleteThingResponse.of(thingId, dittoHeadersV2.toBuilder()
105+
.putHeader(DittoHeaderDefinition.ENTITY_ID.getKey(), thingId.toString())
106+
.build()));
105107

106108
final Thing expectedDeletedSnapshot = toDeletedThing(2);
107109
assertSnapshots(thingId, Collections.singletonList(expectedDeletedSnapshot));

things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/ThingPersistenceActorTest.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,9 @@ public void deleteThingV2() {
595595

596596
final DeleteThing deleteThing = DeleteThing.of(getIdOrThrow(thing), dittoHeadersV2);
597597
underTest.tell(deleteThing, getRef());
598-
expectMsgEquals(DeleteThingResponse.of(getIdOrThrow(thing), dittoHeadersV2));
598+
expectMsgEquals(DeleteThingResponse.of(getIdOrThrow(thing), dittoHeadersV2.toBuilder()
599+
.putHeader(DittoHeaderDefinition.ENTITY_ID.getKey(), thing.getEntityId().get().toString())
600+
.build()));
599601
}
600602
};
601603
}
@@ -620,7 +622,9 @@ public void deleteAndRecreateThingWithMinimumData() {
620622

621623
final DeleteThing deleteThing = DeleteThing.of(thingId, dittoHeadersV2);
622624
underTest.tell(deleteThing, getRef());
623-
expectMsgEquals(DeleteThingResponse.of(thingId, dittoHeadersV2));
625+
expectMsgEquals(DeleteThingResponse.of(thingId, dittoHeadersV2.toBuilder()
626+
.putHeader(DittoHeaderDefinition.ENTITY_ID.getKey(), thingId.toString())
627+
.build()));
624628

625629
final Thing minimalThing = Thing.newBuilder()
626630
.setId(thingId)
@@ -834,7 +838,9 @@ public void deleteAttribute() {
834838
// Delete attribute as authorized subject.
835839
final ThingCommand authorizedCommand = DeleteAttribute.of(thingId, attributeKey, dittoHeadersV2);
836840
underTest.tell(authorizedCommand, getRef());
837-
expectMsgEquals(DeleteAttributeResponse.of(thingId, attributeKey, dittoHeadersV2));
841+
expectMsgEquals(DeleteAttributeResponse.of(thingId, attributeKey, dittoHeadersV2.toBuilder()
842+
.putHeader(DittoHeaderDefinition.ENTITY_ID.getKey(), thingId.toString())
843+
.build()));
838844
}
839845
};
840846
}
@@ -857,7 +863,9 @@ public void tryToRetrieveThingAfterDeletion() {
857863
assertThingInResponse(createThingResponse.getThingCreated().orElse(null), thing);
858864

859865
underTest.tell(deleteThingCommand, getRef());
860-
expectMsgEquals(DeleteThingResponse.of(thingId, dittoHeadersV2));
866+
expectMsgEquals(DeleteThingResponse.of(thingId, dittoHeadersV2.toBuilder()
867+
.putHeader(DittoHeaderDefinition.ENTITY_ID.getKey(), thingId.toString())
868+
.build()));
861869

862870
underTest.tell(retrieveThingCommand, getRef());
863871
expectMsgClass(ThingNotAccessibleException.class);
@@ -917,7 +925,9 @@ public void recoverThingDeleted() {
917925

918926
final DeleteThing deleteThing = DeleteThing.of(thingId, dittoHeadersV2);
919927
underTest.tell(deleteThing, getRef());
920-
expectMsgEquals(DeleteThingResponse.of(thingId, dittoHeadersV2));
928+
expectMsgEquals(DeleteThingResponse.of(thingId, dittoHeadersV2.toBuilder()
929+
.putHeader(DittoHeaderDefinition.ENTITY_ID.getKey(), thingId.toString())
930+
.build()));
921931

922932
// restart actor to recover thing state
923933
watch(underTest);

things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/AbstractCommandStrategyTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.assertj.core.api.CompletableFutureAssert;
2929
import org.eclipse.ditto.base.model.common.DittoSystemProperties;
3030
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
31+
import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition;
3132
import org.eclipse.ditto.base.model.headers.DittoHeaders;
3233
import org.eclipse.ditto.base.model.headers.WithDittoHeaders;
3334
import org.eclipse.ditto.base.model.signals.commands.Command;
@@ -177,6 +178,12 @@ protected static <C extends Command<?>> void assertUnhandledResult(
177178
verify(mock).onError(eq(expectedResponse), eq(command));
178179
}
179180

181+
protected static DittoHeaders provideHeaders(final CommandStrategy.Context<ThingId> context) {
182+
return DittoHeaders.newBuilder()
183+
.putHeader(DittoHeaderDefinition.ENTITY_ID.getKey(), context.getState().toString())
184+
.build();
185+
}
186+
180187
private static <T extends ThingModifiedEvent<?>> T assertModificationResult(final Result<ThingEvent<?>> result,
181188
final Class<T> eventClazz,
182189
final WithDittoHeaders expectedResponse,

things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/DeleteAttributeStrategyTest.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import org.apache.pekko.actor.ActorSystem;
1818
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
19-
import org.eclipse.ditto.base.model.headers.DittoHeaders;
2019
import org.eclipse.ditto.internal.utils.persistentactors.commands.CommandStrategy;
2120
import org.eclipse.ditto.json.JsonFactory;
2221
import org.eclipse.ditto.json.JsonObject;
@@ -49,7 +48,7 @@ public void setUp() {
4948
public void successfullyDeleteAttribute() {
5049
final JsonPointer attrPointer = JsonFactory.newPointer("/location/longitude");
5150
final CommandStrategy.Context<ThingId> context = getDefaultContext();
52-
final DeleteAttribute command = DeleteAttribute.of(context.getState(), attrPointer, DittoHeaders.empty());
51+
final DeleteAttribute command = DeleteAttribute.of(context.getState(), attrPointer, provideHeaders(context));
5352

5453
assertStagedModificationResult(underTest, THING_V2, command,
5554
AttributeDeleted.class,
@@ -61,7 +60,7 @@ public void successfullyDeleteAttribute() {
6160
public void deleteAttributeFromThingWithoutAttributes() {
6261
final JsonPointer attrPointer = JsonFactory.newPointer("/location/longitude");
6362
final CommandStrategy.Context<ThingId> context = getDefaultContext();
64-
final DeleteAttribute command = DeleteAttribute.of(context.getState(), attrPointer, DittoHeaders.empty());
63+
final DeleteAttribute command = DeleteAttribute.of(context.getState(), attrPointer, provideHeaders(context));
6564
final DittoRuntimeException expectedException =
6665
ExceptionFactory.attributeNotFound(context.getState(), attrPointer, command.getDittoHeaders());
6766

@@ -72,7 +71,7 @@ public void deleteAttributeFromThingWithoutAttributes() {
7271
public void deleteAttributeFromThingWithoutThatAttribute() {
7372
final JsonPointer attrPointer = JsonFactory.newPointer("/location/longitude");
7473
final CommandStrategy.Context<ThingId> context = getDefaultContext();
75-
final DeleteAttribute command = DeleteAttribute.of(context.getState(), attrPointer, DittoHeaders.empty());
74+
final DeleteAttribute command = DeleteAttribute.of(context.getState(), attrPointer, provideHeaders(context));
7675
final DittoRuntimeException expectedException =
7776
ExceptionFactory.attributeNotFound(context.getState(), attrPointer, command.getDittoHeaders());
7877

@@ -97,7 +96,7 @@ public void deleteFromComplexNestedAttributeWithoutThatPath() {
9796
// if it was an object and the object did not contain "non", then the test would fail trivially.
9897
final JsonPointer attrPointer = JsonFactory.newPointer("/complex/nested/non/existent/path");
9998
final CommandStrategy.Context<ThingId> context = getDefaultContext();
100-
final DeleteAttribute command = DeleteAttribute.of(context.getState(), attrPointer, DittoHeaders.empty());
99+
final DeleteAttribute command = DeleteAttribute.of(context.getState(), attrPointer, provideHeaders(context));
101100
final DittoRuntimeException expectedException =
102101
ExceptionFactory.attributeNotFound(context.getState(), attrPointer, command.getDittoHeaders());
103102

@@ -123,7 +122,7 @@ public void deleteFromFlatAttributeWithoutThatPath() {
123122

124123
final JsonPointer attrPointer = JsonFactory.newPointer("/flat/non/existent/path");
125124
final CommandStrategy.Context<ThingId> context = getDefaultContext();
126-
final DeleteAttribute command = DeleteAttribute.of(context.getState(), attrPointer, DittoHeaders.empty());
125+
final DeleteAttribute command = DeleteAttribute.of(context.getState(), attrPointer, provideHeaders(context));
127126
final DittoRuntimeException expectedException =
128127
ExceptionFactory.attributeNotFound(context.getState(), attrPointer, command.getDittoHeaders());
129128

things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/DeleteAttributesStrategyTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import org.apache.pekko.actor.ActorSystem;
1818
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
19-
import org.eclipse.ditto.base.model.headers.DittoHeaders;
2019
import org.eclipse.ditto.internal.utils.persistentactors.commands.CommandStrategy;
2120
import org.eclipse.ditto.things.model.ThingId;
2221
import org.eclipse.ditto.things.model.signals.commands.modify.DeleteAttributes;
@@ -43,7 +42,7 @@ public void setUp() {
4342
@Test
4443
public void successfullyDeleteAllAttributesFromThing() {
4544
final CommandStrategy.Context<ThingId> context = getDefaultContext();
46-
final DeleteAttributes command = DeleteAttributes.of(context.getState(), DittoHeaders.empty());
45+
final DeleteAttributes command = DeleteAttributes.of(context.getState(), provideHeaders(context));
4746

4847
assertStagedModificationResult(underTest, THING_V2, command,
4948
AttributesDeleted.class,
@@ -53,7 +52,7 @@ public void successfullyDeleteAllAttributesFromThing() {
5352
@Test
5453
public void deleteAttributesFromThingWithoutAttributes() {
5554
final CommandStrategy.Context<ThingId> context = getDefaultContext();
56-
final DeleteAttributes command = DeleteAttributes.of(context.getState(), DittoHeaders.empty());
55+
final DeleteAttributes command = DeleteAttributes.of(context.getState(), provideHeaders(context));
5756
final DittoRuntimeException expectedException =
5857
ExceptionFactory.attributesNotFound(context.getState(), command.getDittoHeaders());
5958

things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/DeleteFeatureDefinitionStrategyTest.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.apache.pekko.actor.ActorSystem;
2020
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
21-
import org.eclipse.ditto.base.model.headers.DittoHeaders;
2221
import org.eclipse.ditto.internal.utils.persistentactors.commands.CommandStrategy;
2322
import org.eclipse.ditto.things.model.Feature;
2423
import org.eclipse.ditto.things.model.ThingId;
@@ -48,7 +47,7 @@ public void successfullyDeleteFeatureDefinitionFromFeature() {
4847
final CommandStrategy.Context<ThingId> context = getDefaultContext();
4948
final String featureId = FLUX_CAPACITOR_ID;
5049
final DeleteFeatureDefinition command =
51-
DeleteFeatureDefinition.of(context.getState(), featureId, DittoHeaders.empty());
50+
DeleteFeatureDefinition.of(context.getState(), featureId, provideHeaders(context));
5251

5352
assertStagedModificationResult(underTest, THING_V2, command,
5453
FeatureDefinitionDeleted.class,
@@ -59,7 +58,7 @@ public void successfullyDeleteFeatureDefinitionFromFeature() {
5958
public void deleteFeatureDefinitionFromThingWithoutFeatures() {
6059
final CommandStrategy.Context<ThingId> context = getDefaultContext();
6160
final DeleteFeatureDefinition command =
62-
DeleteFeatureDefinition.of(context.getState(), FLUX_CAPACITOR_ID, DittoHeaders.empty());
61+
DeleteFeatureDefinition.of(context.getState(), FLUX_CAPACITOR_ID, provideHeaders(context));
6362
final DittoRuntimeException expectedException =
6463
ExceptionFactory.featureNotFound(context.getState(), command.getFeatureId(),
6564
command.getDittoHeaders());
@@ -72,7 +71,7 @@ public void deleteFeatureDefinitionFromThingWithoutThatFeature() {
7271
final String featureId = FLUX_CAPACITOR_ID;
7372
final CommandStrategy.Context<ThingId> context = getDefaultContext();
7473
final DeleteFeatureDefinition command =
75-
DeleteFeatureDefinition.of(context.getState(), featureId, DittoHeaders.empty());
74+
DeleteFeatureDefinition.of(context.getState(), featureId, provideHeaders(context));
7675
final DittoRuntimeException expectedException =
7776
ExceptionFactory.featureNotFound(context.getState(), command.getFeatureId(),
7877
command.getDittoHeaders());
@@ -85,7 +84,7 @@ public void deleteFeatureDefinitionFromFeatureWithoutDefinition() {
8584
final Feature feature = FLUX_CAPACITOR.removeDefinition();
8685
final CommandStrategy.Context<ThingId> context = getDefaultContext();
8786
final DeleteFeatureDefinition command =
88-
DeleteFeatureDefinition.of(context.getState(), feature.getId(), DittoHeaders.empty());
87+
DeleteFeatureDefinition.of(context.getState(), feature.getId(), provideHeaders(context));
8988
final DittoRuntimeException expectedException =
9089
ExceptionFactory.featureDefinitionNotFound(context.getState(), command.getFeatureId(),
9190
command.getDittoHeaders());

things/service/src/test/java/org/eclipse/ditto/things/service/persistence/actors/strategies/commands/DeleteFeatureDesiredPropertiesStrategyTest.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.apache.pekko.actor.ActorSystem;
2020
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
21-
import org.eclipse.ditto.base.model.headers.DittoHeaders;
2221
import org.eclipse.ditto.internal.utils.persistentactors.commands.CommandStrategy;
2322
import org.eclipse.ditto.things.model.Feature;
2423
import org.eclipse.ditto.things.model.ThingId;
@@ -48,7 +47,7 @@ public void successfullyDeleteFeatureDesiredPropertiesFromFeature() {
4847
final CommandStrategy.Context<ThingId> context = getDefaultContext();
4948
final String featureId = FLUX_CAPACITOR_ID;
5049
final DeleteFeatureDesiredProperties command =
51-
DeleteFeatureDesiredProperties.of(context.getState(), featureId, DittoHeaders.empty());
50+
DeleteFeatureDesiredProperties.of(context.getState(), featureId, provideHeaders(context));
5251

5352
assertStagedModificationResult(underTest, THING_V2, command,
5453
FeatureDesiredPropertiesDeleted.class,
@@ -59,7 +58,7 @@ public void successfullyDeleteFeatureDesiredPropertiesFromFeature() {
5958
public void deleteFeatureDesiredPropertiesFromThingWithoutFeatures() {
6059
final CommandStrategy.Context<ThingId> context = getDefaultContext();
6160
final DeleteFeatureDesiredProperties command =
62-
DeleteFeatureDesiredProperties.of(context.getState(), FLUX_CAPACITOR_ID, DittoHeaders.empty());
61+
DeleteFeatureDesiredProperties.of(context.getState(), FLUX_CAPACITOR_ID, provideHeaders(context));
6362
final DittoRuntimeException expectedException =
6463
ExceptionFactory.featureNotFound(context.getState(), command.getFeatureId(),
6564
command.getDittoHeaders());
@@ -72,7 +71,7 @@ public void deleteFeatureDesiredPropertiesFromThingWithoutThatFeature() {
7271
final String featureId = FLUX_CAPACITOR_ID;
7372
final CommandStrategy.Context<ThingId> context = getDefaultContext();
7473
final DeleteFeatureDesiredProperties command =
75-
DeleteFeatureDesiredProperties.of(context.getState(), featureId, DittoHeaders.empty());
74+
DeleteFeatureDesiredProperties.of(context.getState(), featureId, provideHeaders(context));
7675
final DittoRuntimeException expectedException =
7776
ExceptionFactory.featureNotFound(context.getState(), command.getFeatureId(),
7877
command.getDittoHeaders());
@@ -85,7 +84,7 @@ public void deleteFeatureDesiredPropertiesFromFeatureWithoutDesiredProperties()
8584
final Feature feature = FLUX_CAPACITOR.removeDesiredProperties();
8685
final CommandStrategy.Context<ThingId> context = getDefaultContext();
8786
final DeleteFeatureDesiredProperties command =
88-
DeleteFeatureDesiredProperties.of(context.getState(), feature.getId(), DittoHeaders.empty());
87+
DeleteFeatureDesiredProperties.of(context.getState(), feature.getId(), provideHeaders(context));
8988
final DittoRuntimeException expectedException =
9089
ExceptionFactory.featureDesiredPropertiesNotFound(context.getState(), command.getFeatureId(),
9190
command.getDittoHeaders());

0 commit comments

Comments
 (0)