Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ object ModelBuilder {
else fqn.name + "Action"

val className =
if (fqn.name.endsWith("Action")) fqn.name + "Impl"
if (fqn.name.contains("Action")) fqn.name + "Impl"
else fqn.name + "Action"
val interfaceName = "Abstract" + baseClassName
val handlerName = baseClassName + "Handler"
Expand All @@ -195,15 +195,18 @@ object ModelBuilder {
transformedUpdates: Iterable[Command])
extends Service(fqn, commands) {

val viewClassName =
private val baseClassName =
if (fqn.name.endsWith("View")) fqn.name
else fqn.name + "View"

val abstractViewName = "Abstract" + viewClassName
val handlerName = viewClassName + "Handler"
val providerName = viewClassName + "Provider"
val className =
if (fqn.name.contains("View")) fqn.name + "Impl"
else fqn.name + "View"
val abstractViewName = "Abstract" + baseClassName
val handlerName = baseClassName + "Handler"
val providerName = baseClassName + "Provider"

val classNameQualified = s"${fqn.parent.javaPackage}.$viewClassName"
val classNameQualified = s"${fqn.parent.javaPackage}.$className"
val providerNameQualified = s"${fqn.parent.javaPackage}.$providerName"

val state = State(updates.head.outputType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,7 @@ object FullyQualifiedName {
Some(s"${descriptor.getName}Proto"),
javaMultipleFiles = true)
} else PackageNaming.from(fileDescriptor)
FullyQualifiedName(
descriptor.getName,
serviceType match {
// View and Actions services clashes with akka-grpc service generation
// therefore we need to append [View,Action] to it (or Impl).
// FIXME: should we find a better solution for that?
case ServiceType.SERVICE_TYPE_VIEW =>
if (descriptor.getName.endsWith("View")) descriptor.getName + "Impl"
else descriptor.getName + "View"
case _ => descriptor.getName
},
packageNaming)
FullyQualifiedName(descriptor.getName, descriptor.getName, packageNaming)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ class ModelBuilderSuite extends munit.FunSuite {
assertEquals(
model.services,
Map(
"shopping.cart.view.ShoppingCartViewServiceView" ->
"shopping.cart.view.ShoppingCartViewService" ->
ModelBuilder.ViewService(
FullyQualifiedName("ShoppingCartViewService", "ShoppingCartViewServiceView", shoppingCartProto),
FullyQualifiedName("ShoppingCartViewService", "ShoppingCartViewService", shoppingCartProto),
transformedUpdates ++ queries,
"ShoppingCartViewService",
transformedUpdates,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ object SourceGenerator {
}

case service: ModelBuilder.ViewService =>
List(s".register(${service.providerName}.of(create${service.viewClassName}))")
List(s".register(${service.providerName}.of(create${service.className}))")

case service: ModelBuilder.ActionService =>
List(s".register(${service.providerName}.of(create${service.className}))")
Expand Down Expand Up @@ -280,7 +280,7 @@ object SourceGenerator {
case service: ModelBuilder.ActionService =>
s"Function<ActionCreationContext, ${service.className}> create${service.className}"
case view: ModelBuilder.ViewService =>
s"Function<ViewCreationContext, ${view.viewClassName}> create${view.viewClassName}"
s"Function<ViewCreationContext, ${view.className}> create${view.className}"
}.toList

val creatorParameters = entityCreators ::: serviceCreators
Expand Down Expand Up @@ -334,7 +334,7 @@ object SourceGenerator {

val serviceRegistrationParameters = services.values.collect {
case service: ModelBuilder.ActionService => s"${service.className}::new"
case view: ModelBuilder.ViewService => s"${view.viewClassName}::new"
case view: ModelBuilder.ViewService => s"${view.className}::new"
}.toList

val registrationParameters = entityRegistrationParameters ::: serviceRegistrationParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object ViewServiceSourceGenerator {
val packagePath = packageAsPath(packageName)

val implSourcePath =
sourceDirectory.resolve(packagePath.resolve(service.viewClassName + ".java"))
sourceDirectory.resolve(packagePath.resolve(service.className + ".java"))

val abstractViewPath =
generatedSourceDirectory.resolve(packagePath.resolve(service.abstractViewName + ".java"))
Expand Down Expand Up @@ -102,9 +102,9 @@ object ViewServiceSourceGenerator {
|$imports
|
|/** A view handler */
|public class ${view.handlerName} extends ViewHandler<${qualifiedType(view.state.fqn)}, ${view.viewClassName}> {
|public class ${view.handlerName} extends ViewHandler<${qualifiedType(view.state.fqn)}, ${view.className}> {
|
| public ${view.handlerName}(${view.viewClassName} view) {
| public ${view.handlerName}(${view.className} view) {
| super(view);
| }
|
Expand Down Expand Up @@ -147,19 +147,19 @@ object ViewServiceSourceGenerator {
|
|$imports
|
|public class ${view.providerName} implements ViewProvider<${qualifiedType(view.state.fqn)}, ${view.viewClassName}> {
|public class ${view.providerName} implements ViewProvider<${qualifiedType(view.state.fqn)}, ${view.className}> {
|
| private final Function<ViewCreationContext, ${view.viewClassName}> viewFactory;
| private final Function<ViewCreationContext, ${view.className}> viewFactory;
| private final String viewId;
|
| /** Factory method of ${view.viewClassName} */
| /** Factory method of ${view.className} */
| public static ${view.providerName} of(
| Function<ViewCreationContext, ${view.viewClassName}> viewFactory) {
| Function<ViewCreationContext, ${view.className}> viewFactory) {
| return new ${view.providerName}(viewFactory, "${view.viewId}");
| }
|
| private ${view.providerName}(
| Function<ViewCreationContext, ${view.viewClassName}> viewFactory,
| Function<ViewCreationContext, ${view.className}> viewFactory,
| String viewId) {
| this.viewFactory = viewFactory;
| this.viewId = viewId;
Expand Down Expand Up @@ -225,9 +225,9 @@ object ViewServiceSourceGenerator {
|
|$imports
|
|public class ${view.viewClassName} extends ${view.abstractViewName} {
|public class ${view.className} extends ${view.abstractViewName} {
|
| public ${view.viewClassName}(ViewContext context) {}
| public ${view.className}(ViewContext context) {}
|$emptyState
| ${Syntax.indent(handlers, 2)}
|}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class SourceGeneratorSuite extends munit.FunSuite {
testSourceDirectory.resolve("com/example/service/domain/MyEntity3Test.java"),
generatedTestSourceDirectory.resolve("com/example/service/domain/MyEntity3TestKit.java"),
generatedSourceDirectory.resolve("com/example/service/domain/MyEntity3Provider.java"),
sourceDirectory.resolve("com/example/service/MyService4View.java"),
sourceDirectory.resolve("com/example/service/MyService4ViewImpl.java"),
generatedSourceDirectory.resolve("com/example/service/AbstractMyService4View.java"),
generatedSourceDirectory.resolve("com/example/service/MyService4ViewHandler.java"),
generatedSourceDirectory.resolve("com/example/service/MyService4ViewProvider.java"),
Expand Down Expand Up @@ -226,7 +226,7 @@ class SourceGeneratorSuite extends munit.FunSuite {
|import com.example.service.domain.MyValueEntity2;
|import com.example.service.domain.MyValueEntity2Provider;
|import com.example.service.something.ServiceOuterClass3;
|import com.example.service.view.MyService4View;
|import com.example.service.view.MyService4ViewImpl;
|import com.example.service.view.MyService4ViewProvider;
|import com.example.service.view.ServiceOuterClass4;
|import com.external.ExternalDomain;
Expand All @@ -239,14 +239,14 @@ class SourceGeneratorSuite extends munit.FunSuite {
| Function<ValueEntityContext, MyValueEntity2> createMyValueEntity2,
| Function<EventSourcedEntityContext, MyEntity3> createMyEntity3,
| Function<ReplicatedEntityContext, MyReplicatedEntity6> createMyReplicatedEntity6,
| Function<ViewCreationContext, MyService4View> createMyService4View,
| Function<ViewCreationContext, MyService4ViewImpl> createMyService4ViewImpl,
| Function<ActionCreationContext, MyService5Action> createMyService5Action) {
| AkkaServerless akkaServerless = new AkkaServerless();
| return akkaServerless
| .register(MyEntity1Provider.of(createMyEntity1))
| .register(MyEntity3Provider.of(createMyEntity3))
| .register(MyReplicatedEntity6Provider.of(createMyReplicatedEntity6))
| .register(MyService4ViewProvider.of(createMyService4View))
| .register(MyService4ViewProvider.of(createMyService4ViewImpl))
| .register(MyService5ActionProvider.of(createMyService5Action))
| .register(MyValueEntity2Provider.of(createMyValueEntity2));
| }
Expand Down Expand Up @@ -278,18 +278,18 @@ class SourceGeneratorSuite extends munit.FunSuite {
|import com.akkaserverless.javasdk.AkkaServerless;
|import com.akkaserverless.javasdk.view.ViewCreationContext;
|import com.example.service.domain.EntityOuterClass;
|import com.example.service.view.MyServiceView;
|import com.example.service.view.MyServiceViewImpl;
|import com.example.service.view.MyServiceViewProvider;
|import com.example.service.view.ServiceOuterClass;
|import java.util.function.Function;
|
|public final class AkkaServerlessFactory {
|
| public static AkkaServerless withComponents(
| Function<ViewCreationContext, MyServiceView> createMyServiceView) {
| Function<ViewCreationContext, MyServiceViewImpl> createMyServiceViewImpl) {
| AkkaServerless akkaServerless = new AkkaServerless();
| return akkaServerless
| .register(MyServiceViewProvider.of(createMyServiceView));
| .register(MyServiceViewProvider.of(createMyServiceViewImpl));
| }
|}
|""".stripMargin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite {
|import com.akkaserverless.javasdk.view.ViewContext;
|import com.example.service.domain.EntityOuterClass;
|
|public class MyServiceView extends AbstractMyServiceView {
|public class MyServiceViewImpl extends AbstractMyServiceView {
|
| public MyServiceView(ViewContext context) {}
| public MyServiceViewImpl(ViewContext context) {}
|
| @Override
| public ServiceOuterClass.ViewState emptyState() {
Expand Down Expand Up @@ -76,9 +76,9 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite {
|import com.akkaserverless.javasdk.view.ViewContext;
|import com.example.service.domain.EntityOuterClass;
|
|public class MyServiceView extends AbstractMyServiceView {
|public class MyServiceViewImpl extends AbstractMyServiceView {
|
| public MyServiceView(ViewContext context) {}
| public MyServiceViewImpl(ViewContext context) {}
|
|
|}
Expand Down Expand Up @@ -162,9 +162,9 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite {
|import com.example.service.domain.EntityOuterClass;
|
|/** A view handler */
|public class MyServiceViewHandler extends ViewHandler<ServiceOuterClass.ViewState, MyServiceView> {
|public class MyServiceViewHandler extends ViewHandler<ServiceOuterClass.ViewState, MyServiceViewImpl> {
|
| public MyServiceViewHandler(MyServiceView view) {
| public MyServiceViewHandler(MyServiceViewImpl view) {
| super(view);
| }
|
Expand Down Expand Up @@ -214,24 +214,24 @@ class ViewServiceSourceGeneratorSuite extends munit.FunSuite {
|import com.akkaserverless.javasdk.view.View;
|import com.akkaserverless.javasdk.view.ViewCreationContext;
|import com.akkaserverless.javasdk.view.ViewProvider;
|import com.example.service.MyServiceView;
|import com.example.service.MyServiceViewImpl;
|import com.google.protobuf.Descriptors;
|import com.google.protobuf.EmptyProto;
|import java.util.function.Function;
|
|public class MyServiceViewProvider implements ViewProvider<ServiceOuterClass.ViewState, MyServiceView> {
|public class MyServiceViewProvider implements ViewProvider<ServiceOuterClass.ViewState, MyServiceViewImpl> {
|
| private final Function<ViewCreationContext, MyServiceView> viewFactory;
| private final Function<ViewCreationContext, MyServiceViewImpl> viewFactory;
| private final String viewId;
|
| /** Factory method of MyServiceView */
| /** Factory method of MyServiceViewImpl */
| public static MyServiceViewProvider of(
| Function<ViewCreationContext, MyServiceView> viewFactory) {
| Function<ViewCreationContext, MyServiceViewImpl> viewFactory) {
| return new MyServiceViewProvider(viewFactory, "MyService");
| }
|
| private MyServiceViewProvider(
| Function<ViewCreationContext, MyServiceView> viewFactory,
| Function<ViewCreationContext, MyServiceViewImpl> viewFactory,
| String viewId) {
| this.viewFactory = viewFactory;
| this.viewId = viewId;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* This code was generated by Akka Serverless tooling.
* As long as this file exists it will not be re-generated.
* You are free to make changes to this file.
*/
package customer.domain;

import com.akkaserverless.javasdk.eventsourcedentity.EventSourcedEntity;
import com.akkaserverless.javasdk.eventsourcedentity.EventSourcedEntityContext;
import com.akkaserverless.javasdk.testkit.EventSourcedResult;
import com.google.protobuf.Empty;
import customer.api.CustomerApi;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import org.junit.Test;
import scala.jdk.javaapi.CollectionConverters;

import static org.junit.Assert.*;

public class CustomerEntityTest {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I compiled all project locally and found some files that were not checked in


@Test
public void exampleTest() {
CustomerEntityTestKit testKit = CustomerEntityTestKit.of(CustomerEntity::new);
// use the testkit to execute a command
// of events emitted, or a final updated state:
// EventSourcedResult<SomeResponse> result = testKit.someOperation(SomeRequest);
// verify the emitted events
// ExpectedEvent actualEvent = result.getNextEventOfType(ExpectedEvent.class);
// assertEquals(expectedEvent, actualEvent)
// verify the final state after applying the events
// assertEquals(expectedState, testKit.getState());
// verify the response
// SomeResponse actualResponse = result.getReply();
// assertEquals(expectedResponse, actualResponse);
}

@Test
public void createTest() {
CustomerEntityTestKit testKit = CustomerEntityTestKit.of(CustomerEntity::new);
// EventSourcedResult<Empty> result = testKit.create(Customer.newBuilder()...build());
}


@Test
public void changeNameTest() {
CustomerEntityTestKit testKit = CustomerEntityTestKit.of(CustomerEntity::new);
// EventSourcedResult<Empty> result = testKit.changeName(ChangeNameRequest.newBuilder()...build());
}


@Test
public void changeAddressTest() {
CustomerEntityTestKit testKit = CustomerEntityTestKit.of(CustomerEntity::new);
// EventSourcedResult<Empty> result = testKit.changeAddress(ChangeAddressRequest.newBuilder()...build());
}


@Test
public void getCustomerTest() {
CustomerEntityTestKit testKit = CustomerEntityTestKit.of(CustomerEntity::new);
// EventSourcedResult<Customer> result = testKit.getCustomer(GetCustomerRequest.newBuilder()...build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ public static AkkaServerless createAkkaServerless() {
CustomerValueEntity::new,
// end::register[]
CustomerSummaryByNameView::new,
CustomerByEmailView::new,
CustomersResponseByNameView::new,
CustomerByEmailView::new,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, here the names didn't change, but the ordering changed. Note that the CustomerS and Customers (plural).

In any case, the ordering doesn't seen to be deterministic.

CustomerByEmailView
CustomerActionImpl
CustomerByNameView

Alphabetical? Per component type? File system ordering?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created issue #407 for this.

CustomerActionImpl::new,
// tag::register[]
CustomerByNameView::new
);
CustomerByNameView::new);
}
// end::register[]

Expand Down
Loading