Skip to content

Commit eb031fc

Browse files
docs: check if license key is valid (#32671)
* docs: check if license key is valid * example actual tests * comments from pr * more comments from pr * proper testing the key expiry * move closing doc comment
1 parent 14e83e1 commit eb031fc

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

akka-docs/src/main/paradox/general/configuration.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ If the license key has expired when the `ActorSystem` is started the system will
6464
The expiry date is exposed by @apidoc[akka.actor.typed.ActorSystem] {scala="#licenseKeyExpiry" java="#getLicenseKeyExpiry"}
6565
so that you can write a test to remind yourself that it is time for renewal before it has expired.
6666

67+
To verify that your license key is still valid (for example during CI/CD integration), you can use the following test
68+
that will start to fail one month before the license key will expire:
69+
70+
Scala
71+
: @@snip [ConfigDocSpec.scala](/akka-docs/src/test/scala/docs/config/ConfigDocSpec.scala) { #check-is-key-valid }
72+
73+
Java
74+
: @@snip [ConfigDocTest.java](/akka-docs/src/test/java/jdocs/config/ConfigDocTest.java) { #check-is-key-valid }
75+
6776
## When using JarJar, OneJar, Assembly or any jar-bundler
6877

6978
@@@ warning

akka-docs/src/test/java/jdocs/config/ConfigDocTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
// #imports
1515
import akka.actor.testkit.typed.javadsl.ActorTestKit;
1616

17+
//#check-is-key-valid
18+
import java.time.LocalDate;
19+
import java.util.Optional;
20+
21+
//#check-is-key-valid
22+
23+
import static org.junit.Assert.*;
24+
1725
public class ConfigDocTest {
1826

1927
private Behavior<Void> rootBehavior = Behaviors.empty();
@@ -67,4 +75,18 @@ public ActorSystem createConfiguredSystem() {
6775
// #custom-config-2
6876
return system;
6977
}
78+
79+
public void compileOnlyIsLicenseKeyValid() {
80+
//#check-is-key-valid
81+
ActorSystem<Void> system = ActorSystem.create(rootBehavior, "name");
82+
Optional<LocalDate> licenseKey = system.getLicenseKeyExpiry();
83+
84+
assertFalse(licenseKey.isEmpty());
85+
86+
LocalDate nextMonth = LocalDate.now().plusMonths(1);
87+
assertTrue(licenseKey.get().isAfter(nextMonth));
88+
89+
system.terminate();
90+
//#check-is-key-valid
91+
}
7092
}

akka-docs/src/test/scala/docs/config/ConfigDocSpec.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,18 @@ class ConfigDocSpec extends AnyWordSpec with Matchers {
109109
val system = ActorSystem(rootBehavior, "MySystem", conf)
110110
ActorTestKit.shutdown(system)
111111
}
112+
113+
def compileOnlyIsLicenseKeyValid(): Unit = {
114+
//#check-is-key-valid
115+
val system = ActorSystem(rootBehavior, "name")
116+
val licenseKey = system.licenseKeyExpiry
117+
licenseKey.isEmpty shouldBe false
118+
119+
import java.time.LocalDate
120+
val nextMonth = LocalDate.now().plusMonths(1)
121+
licenseKey.get.isAfter(nextMonth) shouldBe true
122+
123+
system.terminate()
124+
//#check-is-key-valid
125+
}
112126
}

0 commit comments

Comments
 (0)