* change package name to akka.cluster.sbr * reference.conf has same config paths * akka.cluster.sbr.SplitBrainResolverProvider instead of com.lightbend.akka.sbr.SplitBrainResolverProvider * dependency from akka-cluster to akka-coordination, for lease strategy * move TestLease to akka-coordination and use that in SBR tests * remove keep-referee strategy * use keep-majority by default * review and adjust reference documentation Co-authored-by: Johan Andrén <johan@markatta.com> Co-authored-by: Johannes Rudolph <johannes.rudolph@gmail.com> Co-authored-by: Christopher Batey <christopher.batey@gmail.com> Co-authored-by: Arnout Engelen <github@bzzt.net>
This commit is contained in:
parent
e0586e546c
commit
c45e6ef39b
37 changed files with 5612 additions and 67 deletions
105
akka-docs/src/test/java/jdocs/coordination/LeaseDocTest.java
Normal file
105
akka-docs/src/test/java/jdocs/coordination/LeaseDocTest.java
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright (C) 2019-2020 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package jdocs.coordination;
|
||||
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.coordination.lease.LeaseSettings;
|
||||
import akka.coordination.lease.javadsl.Lease;
|
||||
import akka.coordination.lease.javadsl.LeaseProvider;
|
||||
import akka.testkit.javadsl.TestKit;
|
||||
import docs.coordination.LeaseDocSpec;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.scalatestplus.junit.JUnitSuite;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class LeaseDocTest extends JUnitSuite {
|
||||
// #lease-example
|
||||
static class SampleLease extends Lease {
|
||||
|
||||
private LeaseSettings settings;
|
||||
|
||||
public SampleLease(LeaseSettings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LeaseSettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<Boolean> acquire() {
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<Boolean> acquire(Consumer<Optional<Throwable>> leaseLostCallback) {
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionStage<Boolean> release() {
|
||||
return CompletableFuture.completedFuture(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkLease() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// #lease-example
|
||||
|
||||
private static ActorSystem system;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
system = ActorSystem.create("LeaseDocTest", LeaseDocSpec.config());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void teardown() {
|
||||
TestKit.shutdownActorSystem(system);
|
||||
system = null;
|
||||
}
|
||||
|
||||
private void doSomethingImportant(Optional<Throwable> leaseLostReason) {}
|
||||
|
||||
@Test
|
||||
public void javaLeaseBeLoadableFromJava() {
|
||||
// #lease-usage
|
||||
Lease lease =
|
||||
LeaseProvider.get(system).getLease("<name of the lease>", "jdocs-lease", "<owner name>");
|
||||
CompletionStage<Boolean> acquired = lease.acquire();
|
||||
boolean stillAcquired = lease.checkLease();
|
||||
CompletionStage<Boolean> released = lease.release();
|
||||
// #lease-usage
|
||||
|
||||
// #lost-callback
|
||||
lease.acquire(this::doSomethingImportant);
|
||||
// #lost-callback
|
||||
|
||||
// #cluster-owner
|
||||
// String owner = Cluster.get(system).selfAddress().hostPort();
|
||||
// #cluster-owner
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalaLeaseBeLoadableFromJava() {
|
||||
Lease lease =
|
||||
LeaseProvider.get(system).getLease("<name of the lease>", "docs-lease", "<owner name>");
|
||||
CompletionStage<Boolean> acquired = lease.acquire();
|
||||
boolean stillAcquired = lease.checkLease();
|
||||
CompletionStage<Boolean> released = lease.release();
|
||||
lease.acquire(this::doSomethingImportant);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue