Skip to content

Instantly share code, notes, and snippets.

View rowanl's full-sized avatar

Rowan rowanl

View GitHub Profile
@rowanl
rowanl / CharityControllerTest.java
Created January 17, 2018 19:59
playframework-kubernetes - Mocking time dependency in tests using Guice
public class CharityControllerTest extends WithServer {
private Clock clock;
@Override
protected Application provideApplication() {
return new GuiceApplicationBuilder()
.overrides(bindClockToMockInstance())
.build();
}
@rowanl
rowanl / routes
Created January 17, 2018 19:56
playframework-kubernetes - Route for index page
GET / controllers.CharityController.index()
@rowanl
rowanl / CharityController.java
Created January 17, 2018 19:41
playframework-kubernetes - Serving an HTML page
public class CharityController {
private final CharityRepository charityRepository;
private final HttpExecutionContext ec;
private final LocalDateTime endDateTime;
private final Clock clock;
@Inject
public CharityController(CharityRepository charityRepository,
HttpExecutionContext ec,
@rowanl
rowanl / DatabaseExecutionContext.java
Created January 17, 2018 19:32
playframework-kubernetes - Execution context for database calls
public class DatabaseExecutionContext extends CustomExecutionContext {
@Inject
public DatabaseExecutionContext(ActorSystem actorSystem) {
super(actorSystem, "database.dispatcher");
}
}
@rowanl
rowanl / CharityRepository.java
Last active January 17, 2018 20:05
playframework-kubernetes - Asynchronously find all models using Ebean in a non-blocking fashion
private <T> CompletionStage<T> wrapContext(Supplier<T> toRun) {
return supplyAsync(toRun, executionContext);
}
public CompletionStage<List<Charity>> findList() {
return wrapContext(() -> ebeanServer.find(Charity.class).findList());
}
@rowanl
rowanl / Charity.java
Created January 17, 2018 19:28
playframework-kubernetes - Charity model
@Entity
@Table(name="charity")
public class Charity extends Model {
@Id
public Integer id;
@Column(name="name")
public String name;