2023-01-08 17:13:31 +08:00
|
|
|
/*
|
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* license agreements; and to You under the Apache License, version 2.0:
|
|
|
|
|
*
|
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the Apache Pekko project, derived from Akka.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2022-02-04 12:36:44 +01:00
|
|
|
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
|
2014-02-15 23:44:00 -05:00
|
|
|
*/
|
|
|
|
|
|
2017-03-16 09:30:00 +01:00
|
|
|
package jdocs.persistence;
|
2014-02-15 23:44:00 -05:00
|
|
|
|
2019-01-12 04:00:53 +08:00
|
|
|
// #plugin-imports
|
2022-11-12 10:21:24 +01:00
|
|
|
import org.apache.pekko.dispatch.Futures;
|
|
|
|
|
import org.apache.pekko.persistence.*;
|
|
|
|
|
import org.apache.pekko.persistence.journal.japi.*;
|
|
|
|
|
import org.apache.pekko.persistence.snapshot.japi.*;
|
2019-01-12 04:00:53 +08:00
|
|
|
// #plugin-imports
|
2014-12-08 11:02:14 +01:00
|
|
|
|
2022-11-12 10:21:24 +01:00
|
|
|
import org.apache.pekko.actor.*;
|
|
|
|
|
import org.apache.pekko.persistence.journal.leveldb.SharedLeveldbJournal;
|
|
|
|
|
import org.apache.pekko.persistence.journal.leveldb.SharedLeveldbStore;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
|
|
|
|
import com.typesafe.config.Config;
|
|
|
|
|
import com.typesafe.config.ConfigFactory;
|
|
|
|
|
import java.io.File;
|
2015-06-25 19:58:47 +02:00
|
|
|
import java.util.ArrayList;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
import java.util.List;
|
2019-04-30 13:17:46 +01:00
|
|
|
|
|
|
|
|
import org.junit.runner.RunWith;
|
2020-01-11 15:14:21 +03:00
|
|
|
import org.scalatestplus.junit.JUnitRunner;
|
2014-12-08 11:02:14 +01:00
|
|
|
import scala.concurrent.Future;
|
2015-06-23 21:01:36 +02:00
|
|
|
import java.util.function.Consumer;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
import org.iq80.leveldb.util.FileUtils;
|
2015-06-17 01:23:18 +02:00
|
|
|
import java.util.Optional;
|
2014-12-08 11:02:14 +01:00
|
|
|
|
2022-11-12 10:21:24 +01:00
|
|
|
import org.apache.pekko.persistence.japi.journal.JavaJournalSpec;
|
|
|
|
|
import org.apache.pekko.persistence.japi.snapshot.JavaSnapshotStoreSpec;
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
2014-02-15 23:44:00 -05:00
|
|
|
public class LambdaPersistencePluginDocTest {
|
|
|
|
|
|
2019-01-12 04:00:53 +08:00
|
|
|
static Object o1 =
|
|
|
|
|
new Object() {
|
|
|
|
|
final ActorSystem system = null;
|
|
|
|
|
// #shared-store-creation
|
|
|
|
|
final ActorRef store = system.actorOf(Props.create(SharedLeveldbStore.class), "store");
|
|
|
|
|
// #shared-store-creation
|
|
|
|
|
|
|
|
|
|
// #shared-store-usage
|
|
|
|
|
class SharedStorageUsage extends AbstractActor {
|
|
|
|
|
@Override
|
|
|
|
|
public void preStart() throws Exception {
|
2019-05-15 18:01:34 +02:00
|
|
|
String path = "akka://example@127.0.0.1:2552/user/store";
|
2019-01-12 04:00:53 +08:00
|
|
|
ActorSelection selection = getContext().actorSelection(path);
|
|
|
|
|
selection.tell(new Identify(1), getSelf());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Receive createReceive() {
|
|
|
|
|
return receiveBuilder()
|
|
|
|
|
.match(
|
|
|
|
|
ActorIdentity.class,
|
|
|
|
|
ai -> {
|
|
|
|
|
if (ai.correlationId().equals(1)) {
|
|
|
|
|
Optional<ActorRef> store = ai.getActorRef();
|
|
|
|
|
if (store.isPresent()) {
|
|
|
|
|
SharedLeveldbJournal.setStore(store.get(), getContext().getSystem());
|
|
|
|
|
} else {
|
|
|
|
|
throw new RuntimeException("Couldn't identify store");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// #shared-store-usage
|
|
|
|
|
};
|
2014-02-15 23:44:00 -05:00
|
|
|
|
|
|
|
|
class MySnapshotStore extends SnapshotStore {
|
|
|
|
|
@Override
|
2019-01-12 04:00:53 +08:00
|
|
|
public Future<Optional<SelectedSnapshot>> doLoadAsync(
|
|
|
|
|
String persistenceId, SnapshotSelectionCriteria criteria) {
|
2014-02-15 23:44:00 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Future<Void> doSaveAsync(SnapshotMetadata metadata, Object snapshot) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-06-17 01:23:18 +02:00
|
|
|
public Future<Void> doDeleteAsync(SnapshotMetadata metadata) {
|
2015-06-03 15:56:00 +02:00
|
|
|
return Futures.successful(null);
|
2014-02-15 23:44:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-06-17 01:23:18 +02:00
|
|
|
public Future<Void> doDeleteAsync(String persistenceId, SnapshotSelectionCriteria criteria) {
|
2015-06-03 15:56:00 +02:00
|
|
|
return Futures.successful(null);
|
2014-02-15 23:44:00 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyAsyncJournal extends AsyncWriteJournal {
|
2019-01-12 04:00:53 +08:00
|
|
|
// #sync-journal-plugin-api
|
2014-02-15 23:44:00 -05:00
|
|
|
@Override
|
2015-06-25 19:58:47 +02:00
|
|
|
public Future<Iterable<Optional<Exception>>> doAsyncWriteMessages(
|
|
|
|
|
Iterable<AtomicWrite> messages) {
|
|
|
|
|
try {
|
|
|
|
|
Iterable<Optional<Exception>> result = new ArrayList<Optional<Exception>>();
|
|
|
|
|
// blocking call here...
|
|
|
|
|
// result.add(..)
|
|
|
|
|
return Futures.successful(result);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return Futures.failed(e);
|
|
|
|
|
}
|
2014-02-15 23:44:00 -05:00
|
|
|
}
|
2019-01-12 04:00:53 +08:00
|
|
|
// #sync-journal-plugin-api
|
2014-02-15 23:44:00 -05:00
|
|
|
|
|
|
|
|
@Override
|
2015-06-25 07:44:52 +02:00
|
|
|
public Future<Void> doAsyncDeleteMessagesTo(String persistenceId, long toSequenceNr) {
|
2014-02-15 23:44:00 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2019-01-12 04:00:53 +08:00
|
|
|
public Future<Void> doAsyncReplayMessages(
|
|
|
|
|
String persistenceId,
|
|
|
|
|
long fromSequenceNr,
|
|
|
|
|
long toSequenceNr,
|
|
|
|
|
long max,
|
|
|
|
|
Consumer<PersistentRepr> replayCallback) {
|
2014-02-15 23:44:00 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-06-23 14:33:35 +02:00
|
|
|
public Future<Long> doAsyncReadHighestSequenceNr(String persistenceId, long fromSequenceNr) {
|
2014-02-15 23:44:00 -05:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
|
2019-01-12 04:00:53 +08:00
|
|
|
static Object o2 =
|
|
|
|
|
new Object() {
|
|
|
|
|
// #journal-tck-java
|
2019-04-30 13:17:46 +01:00
|
|
|
@RunWith(JUnitRunner.class)
|
2019-01-12 04:00:53 +08:00
|
|
|
class MyJournalSpecTest extends JavaJournalSpec {
|
|
|
|
|
|
|
|
|
|
public MyJournalSpecTest() {
|
|
|
|
|
super(
|
|
|
|
|
ConfigFactory.parseString(
|
2022-12-02 04:53:48 -08:00
|
|
|
"pekko.persistence.journal.plugin = "
|
|
|
|
|
+ "\"pekko.persistence.journal.leveldb-shared\""));
|
2019-01-12 04:00:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CapabilityFlag supportsRejectingNonSerializableObjects() {
|
|
|
|
|
return CapabilityFlag.off();
|
|
|
|
|
}
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
}
|
2019-01-12 04:00:53 +08:00
|
|
|
// #journal-tck-java
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static Object o3 =
|
|
|
|
|
new Object() {
|
|
|
|
|
// #snapshot-store-tck-java
|
2019-04-30 13:17:46 +01:00
|
|
|
@RunWith(JUnitRunner.class)
|
2019-01-12 04:00:53 +08:00
|
|
|
class MySnapshotStoreTest extends JavaSnapshotStoreSpec {
|
|
|
|
|
|
|
|
|
|
public MySnapshotStoreTest() {
|
|
|
|
|
super(
|
|
|
|
|
ConfigFactory.parseString(
|
2022-12-02 04:53:48 -08:00
|
|
|
"pekko.persistence.snapshot-store.plugin = "
|
|
|
|
|
+ "\"pekko.persistence.snapshot-store.local\""));
|
2019-01-12 04:00:53 +08:00
|
|
|
}
|
improve AbstractActor, #21717
* Receive class that wraps PartialFunction, to avoid
scary scala types
* move AbstractActorContext to AbstractActor.ActorContext
* converting docs, many, many UntypedActor
* removing UntypedActor docs
* add unit test for ReceiveBuilder
* MiMa filters
* consistent use of getContext(), self(), sender()
* rename cross references
* migration guide
* skip samples for now
* improve match type safetyi, add matchUnchecked
* the `? extends P` caused code like this to compile:
`match(String.class, (Integer i) -> {})`
* added matchUnchecked, since it can still be useful (um, convenient)
to be able to do:
`matchUnchecked(List.class, (List<String> list) -> {})`
* eleminate some scala.Option
* preRestart
* findChild
* ActorIdentity.getActorRef
2016-12-13 10:59:29 +01:00
|
|
|
}
|
2019-01-12 04:00:53 +08:00
|
|
|
// #snapshot-store-tck-java
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static Object o4 =
|
|
|
|
|
new Object() {
|
2019-05-24 08:11:50 +02:00
|
|
|
// https://github.com/akka/akka/issues/26826
|
2019-01-12 04:00:53 +08:00
|
|
|
// #journal-tck-before-after-java
|
2019-04-30 13:17:46 +01:00
|
|
|
@RunWith(JUnitRunner.class)
|
2019-01-12 04:00:53 +08:00
|
|
|
class MyJournalSpecTest extends JavaJournalSpec {
|
|
|
|
|
|
|
|
|
|
List<File> storageLocations = new ArrayList<File>();
|
|
|
|
|
|
|
|
|
|
public MyJournalSpecTest() {
|
|
|
|
|
super(
|
|
|
|
|
ConfigFactory.parseString(
|
|
|
|
|
"persistence.journal.plugin = "
|
2022-12-02 04:53:48 -08:00
|
|
|
+ "\"pekko.persistence.journal.leveldb-shared\""));
|
2019-01-12 04:00:53 +08:00
|
|
|
|
|
|
|
|
Config config = system().settings().config();
|
|
|
|
|
storageLocations.add(
|
2022-12-02 04:53:48 -08:00
|
|
|
new File(config.getString("pekko.persistence.journal.leveldb.dir")));
|
2019-01-12 04:00:53 +08:00
|
|
|
storageLocations.add(
|
2022-12-02 04:53:48 -08:00
|
|
|
new File(config.getString("pekko.persistence.snapshot-store.local.dir")));
|
2019-01-12 04:00:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CapabilityFlag supportsRejectingNonSerializableObjects() {
|
|
|
|
|
return CapabilityFlag.on();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeAll() {
|
|
|
|
|
for (File storageLocation : storageLocations) {
|
|
|
|
|
FileUtils.deleteRecursively(storageLocation);
|
|
|
|
|
}
|
|
|
|
|
super.beforeAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterAll() {
|
|
|
|
|
super.afterAll();
|
|
|
|
|
for (File storageLocation : storageLocations) {
|
|
|
|
|
FileUtils.deleteRecursively(storageLocation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// #journal-tck-before-after-java
|
|
|
|
|
};
|
2014-02-15 23:44:00 -05:00
|
|
|
}
|