initial commit
This commit is contained in:
1
test/.gitignore
vendored
Normal file
1
test/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
5
test/Dockerfile
Normal file
5
test/Dockerfile
Normal file
@ -0,0 +1,5 @@
|
||||
FROM openjdk:11
|
||||
|
||||
ARG version
|
||||
ADD target/test-test-${version}.jar /test-test.jar
|
||||
ENTRYPOINT ["java", "-jar", "/test-test.jar"]
|
66
test/pom.xml
Normal file
66
test/pom.xml
Normal file
@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>test</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>${revision}${sha1}${changelist}</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>test-test</artifactId>
|
||||
|
||||
<properties>
|
||||
<main.class>test.TestApp</main.class>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>test</groupId>
|
||||
<artifactId>test-model</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.bootique.cayenne</groupId>
|
||||
<artifactId>bootique-cayenne</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.bootique.agrest</groupId>
|
||||
<artifactId>bootique-agrest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.agrest</groupId>
|
||||
<artifactId>agrest-engine</artifactId>
|
||||
<version>4.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.bootique.jdbc</groupId>
|
||||
<artifactId>bootique-jdbc-hikaricp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.bootique.logback</groupId>
|
||||
<artifactId>bootique-logback</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
33
test/src/main/java/test/FailCommand.java
Normal file
33
test/src/main/java/test/FailCommand.java
Normal file
@ -0,0 +1,33 @@
|
||||
package test;
|
||||
|
||||
import io.bootique.cli.Cli;
|
||||
import io.bootique.command.CommandOutcome;
|
||||
import io.bootique.command.CommandWithMetadata;
|
||||
import io.bootique.meta.application.CommandMetadata;
|
||||
import org.apache.cayenne.ObjectContext;
|
||||
import org.apache.cayenne.configuration.server.ServerRuntime;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
|
||||
public class FailCommand extends CommandWithMetadata {
|
||||
|
||||
@Inject
|
||||
private Provider<ServerRuntime> cayenneRuntimeProvider;
|
||||
|
||||
@Inject
|
||||
public FailCommand(CommandMetadata.Builder metadataBuilder) {
|
||||
super(metadataBuilder
|
||||
.name("fail")
|
||||
.description("Demo of a possible issue with Cayenne.")
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandOutcome run(Cli cli) {
|
||||
ObjectContext context = cayenneRuntimeProvider.get().newContext();
|
||||
TestCase.runTest(context, true);
|
||||
return CommandOutcome.succeeded();
|
||||
}
|
||||
}
|
32
test/src/main/java/test/HappyCommand.java
Normal file
32
test/src/main/java/test/HappyCommand.java
Normal file
@ -0,0 +1,32 @@
|
||||
package test;
|
||||
|
||||
import io.bootique.cli.Cli;
|
||||
import io.bootique.command.CommandOutcome;
|
||||
import io.bootique.command.CommandWithMetadata;
|
||||
import io.bootique.meta.application.CommandMetadata;
|
||||
import org.apache.cayenne.ObjectContext;
|
||||
import org.apache.cayenne.configuration.server.ServerRuntime;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
|
||||
public class HappyCommand extends CommandWithMetadata {
|
||||
@Inject
|
||||
private Provider<ServerRuntime> cayenneRuntimeProvider;
|
||||
|
||||
@Inject
|
||||
public HappyCommand(CommandMetadata.Builder metadataBuilder) {
|
||||
super(metadataBuilder
|
||||
.name("happy")
|
||||
.description("Demo of a possible issue with Cayenne. This command shows a workaround.")
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandOutcome run(Cli cli) {
|
||||
ObjectContext context = cayenneRuntimeProvider.get().newContext();
|
||||
TestCase.runTest(context, false);
|
||||
return CommandOutcome.succeeded();
|
||||
}
|
||||
}
|
31
test/src/main/java/test/TestApp.java
Normal file
31
test/src/main/java/test/TestApp.java
Normal file
@ -0,0 +1,31 @@
|
||||
package test;
|
||||
|
||||
import io.bootique.BQCoreModule;
|
||||
import io.bootique.BaseModule;
|
||||
import io.bootique.Bootique;
|
||||
import io.bootique.di.Binder;
|
||||
import io.bootique.meta.application.OptionMetadata;
|
||||
|
||||
public class TestApp extends BaseModule {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Bootique.app(args)
|
||||
.autoLoadModules()
|
||||
.exec()
|
||||
.exit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(Binder binder) {
|
||||
BQCoreModule.extend(binder)
|
||||
.addConfig("classpath:test/default.yaml")
|
||||
.addCommand(FailCommand.class)
|
||||
.addCommand(HappyCommand.class)
|
||||
|
||||
// --local
|
||||
.addOption(OptionMetadata.builder("local", "Load configuration for local environment.").build())
|
||||
.mapConfigResource("local", "classpath:test/local.yaml")
|
||||
|
||||
;
|
||||
}
|
||||
}
|
13
test/src/main/java/test/TestAppProvider.java
Normal file
13
test/src/main/java/test/TestAppProvider.java
Normal file
@ -0,0 +1,13 @@
|
||||
package test;
|
||||
|
||||
import io.bootique.BQModuleProvider;
|
||||
|
||||
public class TestAppProvider implements BQModuleProvider {
|
||||
|
||||
public TestAppProvider() {}
|
||||
|
||||
@Override
|
||||
public TestApp module() {
|
||||
return new TestApp();
|
||||
}
|
||||
}
|
30
test/src/main/java/test/TestCase.java
Normal file
30
test/src/main/java/test/TestCase.java
Normal file
@ -0,0 +1,30 @@
|
||||
package test;
|
||||
|
||||
import org.apache.cayenne.ObjectContext;
|
||||
import test.cayenne.E1;
|
||||
import test.cayenne.E2;
|
||||
|
||||
public class TestCase {
|
||||
|
||||
public static void runTest (ObjectContext context, boolean doFail) {
|
||||
for (int i=100; i<110; ++i) {
|
||||
E1 e1 = context.newObject(E1.class);
|
||||
E2 e2 = context.newObject(E2.class);
|
||||
|
||||
e1.setText("e1 #" + i);
|
||||
e2.setText("e2 #" + i);
|
||||
|
||||
// executing this commit seems to
|
||||
// mitigate the issue
|
||||
|
||||
if (!doFail) {
|
||||
context.commitChanges();
|
||||
}
|
||||
|
||||
e1.setE2(e2);
|
||||
e2.setE1(e1);
|
||||
|
||||
context.commitChanges();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
test.TestAppProvider
|
22
test/src/main/resources/test/default.yaml
Normal file
22
test/src/main/resources/test/default.yaml
Normal file
@ -0,0 +1,22 @@
|
||||
# JDBC config
|
||||
jdbc:
|
||||
test:
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
jdbcUrl: "jdbc:mysql://db:3306/test?connectTimeout=0&autoReconnect=true&useUnicode=true&characterEncoding=UTF-8"
|
||||
username: root
|
||||
password: test
|
||||
minimumIdle: 1
|
||||
maximumPoolSize: 20
|
||||
connectionTestQuery: "select 1"
|
||||
autoCommit: false
|
||||
|
||||
cayenne:
|
||||
configs:
|
||||
- test/cayenne-test.xml
|
||||
datasource: test
|
||||
|
||||
log:
|
||||
level: debug
|
||||
appenders:
|
||||
- type: console
|
||||
logFormat: '[%d{"dd/MMM/yyyy:HH:mm:ss,SSS"}] %t %X %-5p %c{1}: %m%n%ex'
|
3
test/src/main/resources/test/local.yaml
Normal file
3
test/src/main/resources/test/local.yaml
Normal file
@ -0,0 +1,3 @@
|
||||
jdbc:
|
||||
test:
|
||||
jdbcUrl: "jdbc:mysql://localhost:33006/test?connectTimeout=0&autoReconnect=true&useUnicode=true&characterEncoding=UTF-8"
|
Reference in New Issue
Block a user