Skip to content

Commit e1f1efc

Browse files
Merge pull request TechEmpower#1911 from sagenschneider/officefloor_techempire
OfficeFloor
2 parents 07879f7 + d10f374 commit e1f1efc

34 files changed

+1664
-0
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ env:
8282
- "TESTDIR=Java/jooby"
8383
- "TESTDIR=Java/netty"
8484
- "TESTDIR=Java/ninja-standalone"
85+
- "TESTDIR=Java/officefloor"
8586
- "TESTDIR=Java/play1"
8687
- "TESTDIR=Java/play1siena"
8788
- "TESTDIR=Java/play2-java"
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/production/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"framework": "officefloor",
3+
"tests": [{
4+
"default": {
5+
"setup_file": "setup",
6+
"json_url": "/json-service.woof",
7+
"db_url": "/singleQuery-service.woof",
8+
"query_url": "/multipleQueries-service.woof?queries=",
9+
"fortune_url": "/fortune.woof",
10+
"update_url": "/databaseUpdate-service.woof?queries=",
11+
"plaintext_url": "/plaintext.woof",
12+
"port": 7878,
13+
"approach": "Realistic",
14+
"classification": "Fullstack",
15+
"database": "MySQL",
16+
"framework": "officefloor",
17+
"language": "Java",
18+
"orm": "Full",
19+
"platform": "OfficeFloor",
20+
"webserver": "WoOF (Web on OfficeFloor)",
21+
"os": "Linux",
22+
"database_os": "Linux",
23+
"display_name": "officefloor",
24+
"notes": "",
25+
"versus": ""
26+
}
27+
}]
28+
}

frameworks/Java/officefloor/pom.xml

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>net.officefloor.performance</groupId>
5+
<artifactId>TechEmpowerPerformance</artifactId>
6+
<version>0.0.1</version>
7+
<packaging>war</packaging>
8+
<name>TechEmpowerPerformance</name>
9+
<properties>
10+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11+
<officefloor-version>2.16.0</officefloor-version>
12+
<compiler-version>3.1</compiler-version>
13+
<datanucleus-version>4.0.0-release</datanucleus-version>
14+
<mysql-version>5.1.36</mysql-version>
15+
<junit-version>4.11</junit-version>
16+
</properties>
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.apache.maven.plugins</groupId>
21+
<artifactId>maven-war-plugin</artifactId>
22+
<version>2.4</version>
23+
</plugin>
24+
<plugin>
25+
<!-- Standard JVM for compilation -->
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-compiler-plugin</artifactId>
28+
<version>${compiler-version}</version>
29+
<configuration>
30+
<source>1.8</source>
31+
<target>1.8</target>
32+
</configuration>
33+
</plugin>
34+
<plugin>
35+
<groupId>org.datanucleus</groupId>
36+
<artifactId>datanucleus-maven-plugin</artifactId>
37+
<version>${datanucleus-version}</version>
38+
<configuration>
39+
<api>JPA</api>
40+
<verbose>true</verbose>
41+
</configuration>
42+
<executions>
43+
<execution>
44+
<phase>process-classes</phase>
45+
<goals>
46+
<goal>enhance</goal>
47+
</goals>
48+
</execution>
49+
</executions>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
<dependencies>
54+
<dependency>
55+
<groupId>net.officefloor.plugin</groupId>
56+
<artifactId>officeplugin_woof</artifactId>
57+
<version>${officefloor-version}</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>net.officefloor.plugin</groupId>
61+
<artifactId>officeplugin_json</artifactId>
62+
<version>${officefloor-version}</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>net.officefloor.plugin</groupId>
66+
<artifactId>officeplugin_jpa</artifactId>
67+
<version>${officefloor-version}</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>log4j</groupId>
71+
<artifactId>log4j</artifactId>
72+
<version>1.2.17</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.eclipse.persistence</groupId>
76+
<artifactId>javax.persistence</artifactId>
77+
<version>2.1.0</version>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.datanucleus</groupId>
81+
<artifactId>datanucleus-accessplatform-jpa-rdbms</artifactId>
82+
<type>pom</type>
83+
<version>${datanucleus-version}</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>mysql</groupId>
87+
<artifactId>mysql-connector-java</artifactId>
88+
<version>${mysql-version}</version>
89+
</dependency>
90+
<dependency>
91+
<groupId>com.mchange</groupId>
92+
<artifactId>c3p0</artifactId>
93+
<version>0.9.5.1</version>
94+
</dependency>
95+
<dependency>
96+
<groupId>org.projectlombok</groupId>
97+
<artifactId>lombok</artifactId>
98+
<version>1.12.4</version>
99+
</dependency>
100+
<dependency>
101+
<!-- Should be scope test, but available to run stand alone for manual testing -->
102+
<groupId>com.h2database</groupId>
103+
<artifactId>h2</artifactId>
104+
<version>1.4.187</version>
105+
</dependency>
106+
<dependency>
107+
<groupId>org.apache.httpcomponents</groupId>
108+
<artifactId>httpclient</artifactId>
109+
<version>4.3.2</version>
110+
<scope>test</scope>
111+
</dependency>
112+
<dependency>
113+
<groupId>junit</groupId>
114+
<artifactId>junit</artifactId>
115+
<version>${junit-version}</version>
116+
<scope>test</scope>
117+
</dependency>
118+
</dependencies>
119+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
datanucleus.ConnectionDriverName = com.mysql.jdbc.Driver
2+
datanucleus.ConnectionURL = jdbc:mysql://DATABASE_HOST:3306/hello_world?jdbcCompliantTruncation=false&elideSetAutoCommits=true&useLocalSessionState=true&cachePrepStmts=true&cacheCallableStmts=true&alwaysSendSetIsolation=false&prepStmtCacheSize=4096&cacheServerConfiguration=true&prepStmtCacheSqlLimit=2048&zeroDateTimeBehavior=convertToNull&traceProtocol=false&useUnbufferedInput=false&useReadAheadInput=false&maintainTimeStats=false&useServerPrepStmts&cacheRSMetadata=true
3+
datanucleus.ConnectionUserName = benchmarkdbuser
4+
datanucleus.ConnectionPassword = benchmarkdbpass
5+
datanucleus.connectionPoolingType = C3P0

frameworks/Java/officefloor/setup.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Propagate any failure
4+
set -e
5+
6+
# Setup java and maven
7+
fw_depends java maven
8+
9+
# Setup configuration file (normally properties files contains environment specific information but create copy to avoid SCM issues)
10+
echo "Creating configuration for OfficeFloor environment ..."
11+
mkdir -p ./production
12+
cp ./raw/datasource.properties ./production
13+
sed -i 's|DATABASE_HOST|'"${DBHOST}"'|g' ./production/datasource.properties
14+
echo "Configuration created"
15+
16+
# Compile application
17+
echo "Building OfficeFloor test application ..."
18+
mvn -DskipTests clean package
19+
echo "OfficeFloor test application built"
20+
21+
# Run application
22+
echo "Starting OfficeFloor application"
23+
mvn -DincludeGWT=false -DenvDir=production net.officefloor.maven:woof-maven-plugin:run
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
./officefloor/src/main/java/net/officefloor/performance/entities/Fortune.java
2+
./officefloor/src/main/java/net/officefloor/performance/entities/World.java
3+
./officefloor/src/main/java/net/officefloor/performance/logic/DatabaseUpdateLogic.java
4+
./officefloor/src/main/java/net/officefloor/performance/logic/FortunesLogic.java
5+
./officefloor/src/main/java/net/officefloor/performance/logic/JsonSerialisationLogic.java
6+
./officefloor/src/main/java/net/officefloor/performance/logic/LogicUtil.java
7+
./officefloor/src/main/java/net/officefloor/performance/logic/MultipleDatabaseQueriesLogic.java
8+
./officefloor/src/main/java/net/officefloor/performance/logic/SingleDatabaseQueryLogic.java
9+
./officefloor/src/main/webapp/fortune.woof.html
10+
./officefloor/src/main/webapp/plaintext.woof.html
11+
./officefloor/src/main/webapp/service.woof.html
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package net.officefloor.performance.entities;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.Id;
5+
import javax.persistence.NamedQueries;
6+
import javax.persistence.NamedQuery;
7+
8+
import net.officefloor.plugin.web.http.template.UnescapedHtml;
9+
import lombok.Data;
10+
import lombok.NonNull;
11+
12+
/**
13+
* Fortune entity.
14+
*
15+
* @author Daniel Sagenschneider
16+
*/
17+
@Data
18+
@Entity
19+
@NamedQueries({ @NamedQuery(name = "Fortune.getAll", query = "SELECT e FROM Fortune e") })
20+
public class Fortune {
21+
public static final String NAMED_QUERY_ALL = "Fortune.getAll";
22+
23+
@Id
24+
private int id;
25+
26+
@NonNull
27+
private String message;
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package net.officefloor.performance.entities;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.Id;
5+
6+
import lombok.Data;
7+
8+
/**
9+
* World entity.
10+
*
11+
* @author Daniel Sagenschneider
12+
*/
13+
@Data
14+
@Entity
15+
public class World {
16+
@Id
17+
private int id;
18+
private int randomNumber;
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package net.officefloor.performance.logic;
2+
3+
import java.io.IOException;
4+
import java.io.Serializable;
5+
import java.util.Arrays;
6+
7+
import javax.persistence.EntityManager;
8+
9+
import lombok.Data;
10+
import net.officefloor.performance.entities.World;
11+
import net.officefloor.plugin.json.JsonResponseWriter;
12+
import net.officefloor.plugin.web.http.application.HttpParameters;
13+
14+
/**
15+
* Logic for Database Update query.
16+
*
17+
* @author Daniel Sagenschneider
18+
*/
19+
public class DatabaseUpdateLogic {
20+
21+
@Data
22+
@HttpParameters
23+
public static class Parameters implements Serializable {
24+
private String queries;
25+
}
26+
27+
public void service(Parameters parameters, EntityManager entityManager,
28+
JsonResponseWriter response) throws IOException {
29+
30+
// Obtain the number of queries
31+
int queryCount = LogicUtil.getQueryCount(parameters.queries);
32+
33+
// Create the listing of random identifiers
34+
int[] identifiers = new int[queryCount];
35+
for (int i = 0; i < identifiers.length; i++) {
36+
identifiers[i] = LogicUtil.generateRandomNumber(1, 10000);
37+
}
38+
39+
// Sort identifiers to avoid dead locks
40+
Arrays.sort(identifiers);
41+
42+
// Obtain the world objects (changing their random values)
43+
World[] list = new World[queryCount];
44+
for (int i = 0; i < list.length; i++) {
45+
46+
// Obtain the object
47+
int identifier = identifiers[i];
48+
World world = entityManager.find(World.class, identifier);
49+
list[i] = world;
50+
51+
// Change the random value
52+
world.setRandomNumber(LogicUtil.generateRandomNumber(1, 10000));
53+
}
54+
55+
// Send the response
56+
response.writeResponse(list);
57+
}
58+
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package net.officefloor.performance.logic;
2+
3+
import java.util.Arrays;
4+
import java.util.Comparator;
5+
import java.util.List;
6+
7+
import javax.persistence.EntityManager;
8+
9+
import lombok.Data;
10+
import net.officefloor.performance.entities.Fortune;
11+
12+
/**
13+
* Logic for Database Update query.
14+
*
15+
* @author Daniel Sagenschneider
16+
*/
17+
public class FortunesLogic {
18+
19+
@Data
20+
public static class TemplateData {
21+
private final Fortune[] fortunes;
22+
}
23+
24+
public TemplateData getTemplate(EntityManager entityManager) {
25+
26+
// Obtain all the fortunes
27+
List<Fortune> list = entityManager.createNamedQuery(
28+
Fortune.NAMED_QUERY_ALL, Fortune.class).getResultList();
29+
30+
// Obtain the fortunes as array
31+
Fortune[] fortunes = list.toArray(new Fortune[list.size() + 1]);
32+
int index = 0;
33+
for (Fortune fortune : list) {
34+
fortunes[index++] = fortune;
35+
}
36+
37+
// Add the necessary Fortune
38+
fortunes[fortunes.length - 1] = new Fortune(
39+
"Additional fortune added at request time.");
40+
41+
// Sort the fortunes
42+
Arrays.sort(fortunes, new Comparator<Fortune>() {
43+
@Override
44+
public int compare(Fortune a, Fortune b) {
45+
return String.CASE_INSENSITIVE_ORDER.compare(a.getMessage(),
46+
b.getMessage());
47+
}
48+
});
49+
50+
// Return the data for the template
51+
return new TemplateData(fortunes);
52+
}
53+
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.officefloor.performance.logic;
2+
3+
import java.io.IOException;
4+
5+
import lombok.Data;
6+
import net.officefloor.plugin.json.JsonResponseWriter;
7+
8+
/**
9+
* Logic for JSON Serialisation.
10+
*
11+
* @author Daniel Sagenschneider
12+
*/
13+
public class JsonSerialisationLogic {
14+
15+
@Data
16+
public static class Message {
17+
private final String message;
18+
}
19+
20+
public void service(JsonResponseWriter writer) throws IOException {
21+
writer.writeResponse(new Message("Hello, World!"));
22+
}
23+
24+
}

0 commit comments

Comments
 (0)