Skip to content

Commit

Permalink
Migrate to latest Play version - addresses #92
Browse files Browse the repository at this point in the history
- fixes load generator
- fixes issues occurring while generating load
- author is happy about load test error rate :)
  • Loading branch information
resamsel committed Oct 3, 2020
1 parent c5c81a5 commit 64a139b
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 21 deletions.
28 changes: 28 additions & 0 deletions .idea/runConfigurations/Start_Server_Load_Test.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions app/criterias/AbstractGetCriteria.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

import play.mvc.Http;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static java.util.Objects.requireNonNull;

public abstract class AbstractGetCriteria<T extends AbstractGetCriteria<T, U>, U>
extends AbstractContextCriteria<T> implements GetCriteria<U> {

Expand All @@ -18,7 +13,7 @@ public abstract class AbstractGetCriteria<T extends AbstractGetCriteria<T, U>, U

protected AbstractGetCriteria(U id, Http.Request request) {
this.id = id;
this.request = requireNonNull(request);
this.request = request;
}

@Nonnull
Expand All @@ -27,6 +22,7 @@ public U getId() {
return id;
}

@CheckForNull
@Override
public Http.Request getRequest() {
return request;
Expand Down
2 changes: 2 additions & 0 deletions app/criterias/GetCriteria.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import play.mvc.Http;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

public interface GetCriteria<U> extends ContextCriteria {
@Nonnull
U getId();

@CheckForNull
Http.Request getRequest();

static <T extends DefaultGetCriteria<T, U>, U> DefaultGetCriteria<T, U> from(U id, Http.Request request, String... fetches) {
Expand Down
9 changes: 9 additions & 0 deletions app/services/api/impl/UserApiServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package services.api.impl;

import auth.ClientName;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Sets;
import criterias.GetCriteria;
import criterias.LogEntryCriteria;
import criterias.UserCriteria;
Expand Down Expand Up @@ -29,6 +31,7 @@
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;

Expand All @@ -40,6 +43,8 @@
public class UserApiServiceImpl extends
AbstractApiService<User, UUID, UserCriteria, UserService, dto.User>
implements UserApiService {
private static final Set<String> EXCLUDED_CLIENTS = Sets.newHashSet(
ClientName.ANONYMOUS, ClientName.PARAMETER, ClientName.HEADER);

private final AuthProvider authProvider;
private final LogEntryService logEntryService;
Expand Down Expand Up @@ -72,6 +77,10 @@ public dto.User create(Http.Request request) {
User user = toModel(toDto(request.body().asJson()), request);

authProvider.loggedInProfile(request).ifPresent(profile -> {
if (EXCLUDED_CLIENTS.contains(profile.getClientName())) {
return;
}

LinkedAccount linkedAccount = new LinkedAccount().withUser(user);
linkedAccount.providerKey = profile.getClientName();
linkedAccount.providerUserId = profile.getId();
Expand Down
8 changes: 4 additions & 4 deletions app/services/impl/AccessTokenServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ protected void postCreate(AccessToken t, Http.Request request) {
protected void preUpdate(AccessToken t, Http.Request request) {
super.preUpdate(t, request);

if (StringUtils.isBlank(t.key)) {
t.key = generateKey(AccessToken.KEY_LENGTH);
}

activityActor.tell(
new ActivityProtocol.Activity<>(
ActionType.Update,
Expand All @@ -142,6 +138,10 @@ protected void preUpdate(AccessToken t, Http.Request request) {
protected void preSave(AccessToken t, Http.Request request) {
super.preSave(t, request);

if (StringUtils.isBlank(t.key)) {
t.key = generateKey(AccessToken.KEY_LENGTH);
}

User loggedInUser = authProvider.loggedInUser(request);
if (t.user == null || t.user.id == null
|| (loggedInUser != null && t.user.id != loggedInUser.id && loggedInUser.role != UserRole.Admin)) {
Expand Down
45 changes: 45 additions & 0 deletions conf/logback-prod.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->
<configuration>

<conversionRule
conversionWord="coloredLevel"
converterClass="play.api.libs.logback.ColoredLevel" />

<appender
name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{10}</pattern>
</encoder>
</appender>

<appender
name="ASYNCSTDOUT"
class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="STDOUT" />
</appender>

<logger
name="play"
level="WARN" />

<!-- Off these ones as they are annoying, and anyway we manage configuration
ourselves -->
<logger
name="io.ebean.config.PropertyMapLoader"
level="OFF" />
<logger
name="io.ebeaninternal.server.core.XmlConfigLoader"
level="OFF" />
<logger
name="io.ebeaninternal.server.lib.BackgroundThread"
level="OFF" />
<logger
name="com.gargoylesoftware.htmlunit.javascript"
level="OFF" />

<root level="WARN">
<appender-ref ref="ASYNCSTDOUT" />
</root>

</configuration>
28 changes: 28 additions & 0 deletions load.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
include classpath("application.conf")

db.default {
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost/translatr?reWriteBatchedInserts=true"
username = translatr
password = translatr
logSql = false
}

redis.host = localhost

play.modules {
enabled += modules.NoCacheModule
}

translatr {
baseUrl = "http://localhost:9000"
}

pac4j {
cache.timeout = 0s

clients.keycloak {
host = "sso.repanzar.com"
host = ${?KEYCLOAK_HOST}
}
}
2 changes: 1 addition & 1 deletion ui/apps/cli-generate/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": []
"types": ["node"]
},
"files": [
"src/main.ts"
Expand Down
7 changes: 4 additions & 3 deletions ui/libs/generator/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const providers: StaticProvider[] = [
},
{ provide: XhrFactory, useValue: new BrowserXhr() },
{ provide: ErrorHandler, useValue: new ErrorHandler() },
{ provide: LanguageProvider, useValue: new LanguageProvider() },
{
provide: UserService,
useFactory: (
Expand All @@ -88,7 +89,7 @@ const providers: StaticProvider[] = [
errorHandler: ErrorHandler,
languageProvider: LanguageProvider
) => new LocaleService(client, errorHandler, languageProvider),
deps: [HttpClient, ErrorHandler]
deps: [HttpClient, ErrorHandler, LanguageProvider]
},
{
provide: KeyService,
Expand All @@ -97,7 +98,7 @@ const providers: StaticProvider[] = [
errorHandler: ErrorHandler,
languageProvider: LanguageProvider
) => new KeyService(client, errorHandler, languageProvider),
deps: [HttpClient, ErrorHandler]
deps: [HttpClient, ErrorHandler, LanguageProvider]
},
{
provide: MessageService,
Expand All @@ -106,7 +107,7 @@ const providers: StaticProvider[] = [
errorHandler: ErrorHandler,
languageProvider: LanguageProvider
) => new MessageService(client, errorHandler, languageProvider),
deps: [HttpClient, ErrorHandler]
deps: [HttpClient, ErrorHandler, LanguageProvider]
},
{
provide: AccessTokenService,
Expand Down
2 changes: 1 addition & 1 deletion ui/libs/generator/src/lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const createRandomUser = (userService: UserService): Observable<Partial<S
const lastName = randomName.last();
const name = `${firstName} ${lastName}`;
const username = name.replace(' ', '').toLowerCase();
const email = `${firstName}.${lastName}@resamsel.com`;
const email = `${firstName}.${lastName}@repanzar.com`;
return userService
.create({
name,
Expand Down
13 changes: 12 additions & 1 deletion ui/libs/translatr-sdk/src/lib/services/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ export interface RestRequest {
path: string;
}

const errorTemplate = (error: HttpErrorResponse, request?: RestRequest): string => `
Error Report
============
Source: Translatr SDK
Date: ${new Date()}
Request: ${JSON.stringify(request, null, 2)}
Error: ${JSON.stringify(error, null, 2)}
------------
`;

export class ErrorHandler {
handleError(error: HttpErrorResponse, request?: RestRequest): Observable<never> {
console.warn('Handling error for %s:\n%s', JSON.stringify(request), JSON.stringify(error));
console.warn(errorTemplate(error, request));
return throwError(error);
}
}
6 changes: 3 additions & 3 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"@types/jasminewd2": "^2.0.8",
"@types/jest": "^23.3.14",
"@types/jquery": "3.3.6",
"@types/node": "^12.11.1",
"@types/node": "12.12.62",
"@types/sanitize-html": "1.23.0",
"@types/underscore": "1.10.0",
"codelyzer": "^5.1.2",
Expand Down

0 comments on commit 64a139b

Please sign in to comment.