Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish docs #34

Merged
merged 21 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1aadc92
docs: workflow execution details in console (#8)
aludwiko Nov 20, 2024
6bfa5e4
chore: adapt secret name (#11)
octonato Nov 20, 2024
3968512
docs: less detail in Hello World (#12)
octonato Nov 20, 2024
e45ab13
chore: wrapping passphrase (#13)
octonato Nov 20, 2024
76fd9f5
chore: wrapping passphrase (take2) (#15)
octonato Nov 20, 2024
0f1e735
docs: Release notes projection 1.6.2 (#14)
patriknw Nov 20, 2024
b3221ba
chore: escaping with CDATA (#16)
octonato Nov 20, 2024
e346b53
docs: missing patch version redirect for insights docs (#17)
sebastian-alfers Nov 21, 2024
f4fba08
feat: Improved custom tracing span API (#10)
octonato Nov 21, 2024
0a24ac9
docs: workflows sample with a basic deduplication (#9)
aludwiko Nov 21, 2024
34cbd24
feat: Http endpoint base class with request context access (#18)
johanandren Nov 21, 2024
1f4524e
fix: entityId should be propagated to command context in ES testkit (…
aludwiko Nov 21, 2024
ae6d00b
docs: Fix wrong links to edge
patriknw Nov 22, 2024
e4785bc
Merge pull request #22 from akka/wip-edge-link-patriknw
johanandren Nov 22, 2024
fca5e97
chore: sed syntax in CLI version workflow (#24)
ennru Nov 22, 2024
b9ac488
chore: syntax in CLI version workflow (#26)
ennru Nov 22, 2024
16a9e46
chore: syntax in CLI version workflow (#28)
ennru Nov 22, 2024
89b84a2
chore: syntax in CLI version workflow (#30)
ennru Nov 22, 2024
0d1dd38
chore: syntax in CLI version workflow (#31)
ennru Nov 22, 2024
736510e
docs: akka CLI docs (#32)
github-actions[bot] Nov 22, 2024
9d3d41b
chore: remove static methods from the quickstart domain model (#25)
aludwiko Nov 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/publish-maven.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ cat <<EOF >~/.m2/settings.xml
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.passphrase>${PGP_PASSPHRASE}</gpg.passphrase>
<gpg.passphrase><![CDATA[${PGP_PASSPHRASE}]]></gpg.passphrase>
</properties>
</profile>
</profiles>
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/docs-cli-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ jobs:
with:
ruby-version: '3.1'

- name: Install Akka CLI
- name: Install Akka CLI and create the CLI docs
id: install-cli
run: |
export CLI_INSTALL_PATH=$HOME/.akka/bin
export PATH=${PATH}:${CLI_INSTALL_PATH}
mkdir -p ${CLI_INSTALL_PATH}
curl -sL https://docs.akka.io/install-cli.sh | bash -s -- -y -P ${CLI_INSTALL_PATH}
echo ${CLI_INSTALL_PATH} >> ${GITHUB_PATH}
echo "CLI_VERSION=$(${CLI_INSTALL_PATH}/akka version)" >> ${GITHUB_OUTPUT}
- name: Script
run: |
sed -i '' "s/\(echo \":akka-cli-version: \)[^\"]*/\1${CLI_VERSION}/" Makefile
chmod +x docs/src-static/install-cli.sh
docs/src-static/install-cli.sh --force --prefix=${CLI_INSTALL_PATH}
CLI_VERSION=$(akka version)
echo "setting CLI version to ${CLI_VERSION}"
sed -i.bak "s/\(echo \":akka-cli-version: \)[^\"]*/\1${CLI_VERSION}/" Makefile
rm Makefile.bak
gem install kramdown-asciidoc
./docs/bin/generate_cli_docs.sh gen-index
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ jobs:
SDK_VERSION="$(cat ~/akka-javasdk-version.txt)"
echo "SDK version: '${SDK_VERSION}'"
- name: sbt publishSigned
- name: sbt publishSigned (Cloudsmith)
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
PUBLISH_USER: ${{ secrets.CLOUDSMITH_MACHINE_USER }}
PUBLISH_PASSWORD: ${{ secrets.CLOUDSMITH_MACHINE_PASSWORD }}
PUBLISH_USER: ${{ secrets.PUBLISH_USER }}
PUBLISH_PASSWORD: ${{ secrets.PUBLISH_PASSWORD }}
run: sbt publishSigned

- name: sbt publishM2
run: sbt publishM2

- name: mvn deploy
- name: mvn deploy (Sonatype)
run: |-
export SDK_VERSION="$(cat ~/akka-javasdk-version.txt)"
./.github/publish-maven.sh
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_USERNAME: ${{ secrets.TEST_SONATYPE_AKKA_IO_USER }}
SONATYPE_PASSWORD: ${{ secrets.TEST_SONATYPE_AKKA_IO_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_AKKA_IO_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_AKKA_IO_PASSWORD }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ attributes: prepare
> "${managed_partials}/attributes.adoc"
docs/bin/version.sh | xargs -0 printf ":akka-javasdk-version: %s" \
> "${managed_partials}/attributes.adoc"
echo ":akka-cli-version: 3.0.5" >> "${managed_partials}/attributes.adoc"
echo ":akka-cli-version: 3.0.6" >> "${managed_partials}/attributes.adoc"
echo ":akka-cli-min-version: 3.0.4" >> "${managed_partials}/attributes.adoc"
# see https://adoptium.net/marketplace/
echo ":java-version: 21" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public class EventSourcedTestKit<S, E, ES extends EventSourcedEntity<S, E>>
extends EventSourcedEntityEffectsRunner<S, E> {

private final ES entity;
private final String entityId;

private final JsonMessageCodec messageCodec;

private EventSourcedTestKit(ES entity) {
private EventSourcedTestKit(ES entity, String entityId) {
super(entity);
this.entity = entity;
this.entityId = entityId;
this.messageCodec = new JsonMessageCodec();
}

Expand Down Expand Up @@ -72,7 +74,7 @@ public static <S, E, ES extends EventSourcedEntity<S, E>> EventSourcedTestKit<S,
public static <S, E, ES extends EventSourcedEntity<S, E>> EventSourcedTestKit<S, E, ES> of(
String entityId, Function<EventSourcedEntityContext, ES> entityFactory) {
EventSourcedEntityContext context = new TestKitEventSourcedEntityContext(entityId);
return new EventSourcedTestKit<>(entityFactory.apply(context));
return new EventSourcedTestKit<>(entityFactory.apply(context), entityId);
}

/**
Expand All @@ -99,7 +101,7 @@ public <R> EventSourcedResult<R> call(Function<ES, EventSourcedEntity.Effect<R>>
* @return a EventSourcedResult
*/
public <R> EventSourcedResult<R> call(Function<ES, EventSourcedEntity.Effect<R>> func, Metadata metadata) {
return interpretEffects(() -> func.apply(entity), metadata);
return interpretEffects(() -> func.apply(entity), entityId, metadata);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public List<E> getAllEvents() {
*/
@SuppressWarnings("unchecked") // event type in loop
protected <R> EventSourcedResult<R> interpretEffects(
Supplier<EventSourcedEntity.Effect<R>> effect, Metadata metadata) {
var commandContext = new TestKitEventSourcedEntityCommandContext(metadata);
Supplier<EventSourcedEntity.Effect<R>> effect, String entityId, Metadata metadata) {
var commandContext = new TestKitEventSourcedEntityCommandContext(entityId, metadata);
EventSourcedEntity.Effect<R> effectExecuted;
try {
entity._internalSetCommandContext(Optional.of(commandContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
package akka.javasdk.testkit.impl

import akka.javasdk.Metadata
import akka.javasdk.Tracing
import akka.javasdk.impl.InternalContext
import akka.javasdk.testkit.MockRegistry
import akka.javasdk.timedaction.CommandContext
import io.opentelemetry.api.OpenTelemetry
import io.opentelemetry.api.trace.Tracer

/**
* INTERNAL API Used by the generated testkit
* INTERNAL API Used by the testkit
*/
final class TestKitCommandContextTimed(metadata: Metadata, mockRegistry: MockRegistry = MockRegistry.EMPTY)
extends AbstractTestKitContext(mockRegistry)
Expand All @@ -29,5 +28,5 @@ final class TestKitCommandContextTimed(metadata: Metadata, mockRegistry: MockReg

override def metadata() = metadata

override def getTracer: Tracer = OpenTelemetry.noop().getTracer("noop")
override def tracing(): Tracing = TestKitTracing
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package akka.javasdk.testkit.impl

import akka.javasdk.Metadata
import akka.javasdk.Tracing
import akka.javasdk.eventsourcedentity.CommandContext
import akka.javasdk.impl.InternalContext

Expand All @@ -18,10 +19,12 @@ final class TestKitEventSourcedEntityCommandContext(
extends CommandContext
with InternalContext {

def this(metadata: Metadata) = {
this(metadata = metadata, commandName = "stubCommandName")
def this(entityId: String, metadata: Metadata) = {
this(metadata = metadata, commandName = "stubCommandName", entityId = entityId)
}

override def tracing(): Tracing = TestKitTracing

}

object TestKitEventSourcedEntityCommandContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import akka.javasdk.eventsourcedentity.EventSourcedEntityContext
import akka.javasdk.testkit.MockRegistry

/**
* INTERNAL API Used by the generated testkit
* INTERNAL API Used by the testkit
*/
final class TestKitEventSourcedEntityContext(
override val entityId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package akka.javasdk.testkit.impl
import akka.javasdk.eventsourcedentity.EventContext

/**
* INTERNAL API Used by the generated testkit
* INTERNAL API Used by the testkit
*/
final class TestKitEventSourcedEntityEventContext extends EventContext {
override def entityId = "testkit-entity-id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
package akka.javasdk.testkit.impl

import akka.javasdk.Metadata
import akka.javasdk.Tracing
import akka.javasdk.keyvalueentity.CommandContext
import akka.javasdk.keyvalueentity.KeyValueEntityContext
import akka.javasdk.testkit.MockRegistry

/**
* INTERNAL API Used by the generated testkit
* INTERNAL API Used by the testkit
*/
final class TestKitKeyValueEntityCommandContext(
override val entityId: String,
Expand All @@ -26,4 +27,6 @@ final class TestKitKeyValueEntityCommandContext(
this(entityId = entityId, metadata = metadata, commandName = "stubCommandName")
}

override def tracing(): Tracing = TestKitTracing

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import akka.javasdk.keyvalueentity.KeyValueEntityContext
import akka.javasdk.testkit.MockRegistry

/**
* INTERNAL API Used by the generated testkit
* INTERNAL API Used by the testkit
*/
final class TestKitKeyValueEntityContext(override val entityId: String, mockRegistry: MockRegistry = MockRegistry.EMPTY)
extends AbstractTestKitContext(mockRegistry)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (C) 2021-2024 Lightbend Inc. <https://www.lightbend.com>
*/

package akka.javasdk.testkit.impl

import akka.javasdk.Tracing
import io.opentelemetry.api.trace.Span

import java.util.Optional

/**
* INTERNAL API
*/
object TestKitTracing extends Tracing {

override def startSpan(name: String): Optional[Span] = Optional.empty()

override def parentSpan(): Optional[Span] = Optional.empty()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ public class CounterEventSourcedEntity extends EventSourcedEntity<Integer, Incre

public Effect<String> increaseBy(Integer value) {
if (value <= 0) return effects().error("Can't increase with a negative value");
else return effects().persist(new Increased(value)).thenReply(__ -> "Ok");
else return effects().persist(new Increased(commandContext().entityId(), value)).thenReply(__ -> "Ok");
}

public Effect<String> increaseFromMeta() {
return effects().persist(new Increased(Integer.parseInt(commandContext().metadata().get("value").get()))).thenReply(__ -> "Ok");
return effects().persist(new Increased(commandContext().entityId(), Integer.parseInt(commandContext().metadata().get("value").get()))).thenReply(__ -> "Ok");
}

public Effect<String> doubleIncreaseBy(Integer value) {
if (value < 0) return effects().error("Can't increase with a negative value");
else {
Increased event = new Increased(value);
Increased event = new Increased(commandContext().entityId(), value);
return effects().persist(event, event).thenReply(__ -> "Ok");
}
}

@Override
public Integer applyEvent(Increased increased) {
if (currentState() == null) return increased.value;
else return currentState() + increased.value;
if (currentState() == null) return increased.value();
else return currentState() + increased.value();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import akka.javasdk.testkit.EventSourcedResult;
import akka.javasdk.testkit.EventSourcedTestKit;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -19,20 +20,22 @@ public void testIncrease() {
EventSourcedTestKit.of(ctx -> new CounterEventSourcedEntity());
EventSourcedResult<String> result = testKit.call(entity -> entity.increaseBy(10));
assertTrue(result.isReply());
assertEquals(result.getReply(), "Ok");
assertEquals(testKit.getState(), 10);
assertEquals(testKit.getAllEvents().size(), 1);
assertEquals("Ok", result.getReply());
assertEquals(10, testKit.getState());
assertEquals(1, testKit.getAllEvents().size());
}

@Test
public void testIncreaseWithMetadata() {
String counterId = "123";
EventSourcedTestKit<Integer, Increased, CounterEventSourcedEntity> testKit =
EventSourcedTestKit.of(ctx -> new CounterEventSourcedEntity());
EventSourcedTestKit.of(counterId, ctx -> new CounterEventSourcedEntity());
EventSourcedResult<String> result = testKit.call(entity -> entity.increaseFromMeta(), Metadata.EMPTY.add("value", "10"));
assertTrue(result.isReply());
assertEquals(result.getReply(), "Ok");
assertEquals(testKit.getState(), 10);
assertEquals(testKit.getAllEvents().size(), 1);
assertEquals(new Increased(counterId, 10), result.getNextEventOfType(Increased.class));
assertEquals("Ok", result.getReply());
assertEquals(10, testKit.getState());
assertEquals(1, testKit.getAllEvents().size());
}

@Test
Expand All @@ -41,9 +44,9 @@ public void testDoubleIncrease() {
EventSourcedTestKit.of(ctx -> new CounterEventSourcedEntity());
EventSourcedResult<String> result = testKit.call(entity -> entity.doubleIncreaseBy(10));
assertTrue(result.isReply());
assertEquals(result.getReply(), "Ok");
assertEquals(testKit.getState(), 20);
assertEquals(testKit.getAllEvents().size(), 2);
assertEquals("Ok", result.getReply());
assertEquals(20, testKit.getState());
assertEquals(2, testKit.getAllEvents().size());
}

@Test
Expand All @@ -52,6 +55,6 @@ public void testIncreaseWithNegativeValue() {
EventSourcedTestKit.of(ctx -> new CounterEventSourcedEntity());
EventSourcedResult<String> result = testKit.call(entity -> entity.increaseBy(-10));
assertTrue(result.isError());
assertEquals(result.getError(), "Can't increase with a negative value");
assertEquals("Can't increase with a negative value", result.getError());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,5 @@

package akka.javasdk.testkit.eventsourced;

public class Increased {

public final Integer value;

public Increased(Integer value) {
this.value = value;
}
public record Increased(String counterId, Integer value) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import akka.javasdk.annotations.JWT;
import akka.javasdk.annotations.http.HttpEndpoint;
import akka.javasdk.annotations.http.Get;
import akka.javasdk.http.RequestContext;
import akka.javasdk.http.AbstractHttpEndpoint;

import java.util.concurrent.CompletionStage;
import static java.util.concurrent.CompletableFuture.completedStage;
Expand All @@ -19,17 +19,12 @@
// tag::bearer-token[]
@HttpEndpoint("/hello")
@JWT(validate = JWT.JwtMethodMode.BEARER_TOKEN, bearerTokenIssuers = "my-issuer-123", staticClaims = { @JWT.StaticClaim(claim = "sub", pattern = "my-subject-123")})
public class HelloJwtEndpoint {
public class HelloJwtEndpoint extends AbstractHttpEndpoint {
// end::bearer-token[]

RequestContext context;
public HelloJwtEndpoint(RequestContext context){
this.context = context;
}

@Get("/")
public CompletionStage<String> helloWorld() {
var claims = context.getJwtClaims();
var claims = requestContext().getJwtClaims();
var issuer = claims.issuer().get();
var sub = claims.subject().get();
return completedStage("issuer: " + issuer + ", subject: " + sub);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
@HttpEndpoint("/missingjwt")
public class MissingJwtEndpoint {

// Note: leaving this with injected request context rather than extend AbstractHttpEndpoint to keep
// some test coverage
RequestContext context;
public MissingJwtEndpoint(RequestContext context){
this.context = context;
Expand Down
Loading
Loading