-
Notifications
You must be signed in to change notification settings - Fork 214
/
ThingPersistenceOperationsActorIT.java
166 lines (140 loc) · 6.35 KB
/
ThingPersistenceOperationsActorIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* Copyright (c) 2021 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.things.service.persistence.actors;
import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.internal.utils.persistence.mongo.ops.eventsource.MongoEventSourceITAssertions;
import org.eclipse.ditto.internal.utils.persistence.mongo.streaming.MongoReadJournal;
import org.eclipse.ditto.internal.utils.pubsub.DistributedPub;
import org.eclipse.ditto.internal.utils.pubsub.extractors.AckExtractor;
import org.eclipse.ditto.internal.utils.pubsubthings.LiveSignalPub;
import org.eclipse.ditto.internal.utils.tracing.DittoTracingInitResource;
import org.eclipse.ditto.policies.enforcement.PolicyEnforcerProvider;
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.ThingCommand;
import org.eclipse.ditto.things.model.signals.commands.exceptions.ThingNotAccessibleException;
import org.eclipse.ditto.things.model.signals.commands.modify.CreateThing;
import org.eclipse.ditto.things.model.signals.commands.modify.CreateThingResponse;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThing;
import org.eclipse.ditto.things.model.signals.commands.query.RetrieveThingResponse;
import org.eclipse.ditto.things.model.signals.events.ThingEvent;
import org.eclipse.ditto.things.service.enforcement.TestSetup;
import org.eclipse.ditto.utils.jsr305.annotations.AllValuesAreNonnullByDefault;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.mockito.Mockito;
import com.typesafe.config.Config;
import org.apache.pekko.actor.ActorRef;
import org.apache.pekko.actor.ActorSystem;
import org.apache.pekko.actor.Props;
/**
* Tests {@link ThingPersistenceOperationsActor} against a local MongoDB.
*/
@AllValuesAreNonnullByDefault
public final class ThingPersistenceOperationsActorIT extends MongoEventSourceITAssertions<ThingId> {
@ClassRule
public static final DittoTracingInitResource DITTO_TRACING_INIT_RESOURCE =
DittoTracingInitResource.disableDittoTracing();
private PolicyEnforcerProvider policyEnforcerProvider;
@Before
public void setup() {
policyEnforcerProvider = Mockito.mock(PolicyEnforcerProvider.class);
}
@Test
public void purgeNamespace() {
assertPurgeNamespace();
}
@Override
protected String getServiceName() {
// this loads the things.conf from module "ditto-internal-things-config" as ActorSystem conf
return "things";
}
@Override
protected String getResourceType() {
return ThingCommand.RESOURCE_TYPE;
}
@Override
protected ThingId toEntityId(final CharSequence entityId) {
return ThingId.of(entityId);
}
@Override
protected Object getCreateEntityCommand(final ThingId id) {
return CreateThing.of(Thing.newBuilder()
.setId(id)
.setPolicyId(PolicyId.of(id))
.build(), null, DittoHeaders.newBuilder()
.putHeader(DittoHeaderDefinition.DITTO_SUDO.getKey(),
"true") // required for a stable test - which does not try to load policies from the policiesShardRegion for enforcement
.build());
}
@Override
protected Class<?> getCreateEntityResponseClass() {
return CreateThingResponse.class;
}
@Override
protected Object getRetrieveEntityCommand(final ThingId id) {
return RetrieveThing.of(id, DittoHeaders.newBuilder()
.putHeader(DittoHeaderDefinition.DITTO_SUDO.getKey(),
"true") // required for a stable test - which does not try to load policies from the policiesShardRegion for enforcement
.build());
}
@Override
protected Class<?> getRetrieveEntityResponseClass() {
return RetrieveThingResponse.class;
}
@Override
protected Class<?> getEntityNotAccessibleClass() {
return ThingNotAccessibleException.class;
}
@Override
protected ActorRef startActorUnderTest(final ActorSystem actorSystem, final ActorRef pubSubMediator,
final Config config) {
final Props opsActorProps = ThingPersistenceOperationsActor.props(pubSubMediator, mongoDbConfig, config,
persistenceOperationsConfig);
return actorSystem.actorOf(opsActorProps, ThingPersistenceOperationsActor.ACTOR_NAME);
}
@Override
protected ActorRef startEntityActor(final ActorSystem system, final ActorRef pubSubMediator, final ThingId id) {
final LiveSignalPub liveSignalPub = new TestSetup.DummyLiveSignalPub(pubSubMediator);
final Props props = ThingSupervisorActor.props(pubSubMediator,
new DistributedPub<>() {
@Override
public ActorRef getPublisher() {
return pubSubMediator;
}
@Override
public Object wrapForPublication(final ThingEvent<?> message, final CharSequence groupIndexKey) {
return message;
}
@Override
public <S extends ThingEvent<?>> Object wrapForPublicationWithAcks(final S message,
final CharSequence groupIndexKey, final AckExtractor<S> ackExtractor) {
return wrapForPublication(message, groupIndexKey);
}
},
liveSignalPub,
(thingId, mongoReadJournal, distributedPub, searchShardRegionProxy) -> ThingPersistenceActor.props(
thingId,
mongoReadJournal,
distributedPub,
null
),
null,
policyEnforcerProvider,
Mockito.mock(MongoReadJournal.class));
return system.actorOf(props, id.toString());
}
}