Skip to content

Commit

Permalink
Merge pull request #34 from akka/main
Browse files Browse the repository at this point in the history
Publish docs
  • Loading branch information
ennru authored Nov 25, 2024
2 parents e34409a + 9d3d41b commit ec8c855
Show file tree
Hide file tree
Showing 215 changed files with 1,112 additions and 730 deletions.
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

0 comments on commit ec8c855

Please sign in to comment.