Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Apr 18, 2013
2 parents 660015c + 159ecde commit 1985290
Show file tree
Hide file tree
Showing 139 changed files with 8,008 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ mods/
/.settings
/.buildpath
/.project
*.iml
.idea/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ The benchmark_config file is used by our run script to identify the available te
* query_url (optional): The relative URL path to the variable query test. The URL must be set up so that an integer can be applied to the end of the url to specify the number of queries to run, i.e. /db?queries= or /db/
* port: The port the server is listneing on
* sort: The sort order. This is important for our own blog post which relies on consistent ordering of the frameworks. You can get the next available sort order by running:
./run-test.py --next-sort
./run-tests.py --next-sort

## Setup Files

Expand Down
3 changes: 2 additions & 1 deletion config/php.ini
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ default_socket_timeout = 60
; Be sure to appropriately set the extension_dir directive.
;
extension=apc.so
extension=phalcon.so
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_fileinfo.dll
Expand Down Expand Up @@ -1862,4 +1863,4 @@ ldap.max_links = -1
; tab-width: 4
; End:
[apc]
apc.stat = 0
apc.stat = 0
Empty file added dropwizard/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions dropwizard/benchmark_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"framework": "dropwizard",
"tests": [{
"default": {
"setup_file": "setup",
"json_url": "/json",
"db_url": "/db",
"query_url": "/db?queries=",
"port": 9000,
"sort": 69
}
}]
}
58 changes: 58 additions & 0 deletions dropwizard/hello-world.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
http:
port: 9000

requestLog:

# Settings for logging to stdout.
console:
# If true, log requests to stdout.
enabled: false

database:
# the name of your JDBC driver
driverClass: com.mysql.jdbc.Driver

# the username
user: benchmarkdbuser

# the password
password: benchmarkdbpass

# the JDBC URL
url: jdbc:mysql://localhost: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

# any properties specific to your JDBC driver:
properties:
charSet: UTF-8

# the maximum amount of time to wait on an empty pool before throwing an exception
maxWaitForConnection: 1s

# the SQL query to run when validating a connection's liveness
validationQuery: "/* MyService Health Check */ SELECT 1"

# the minimum number of connections to keep open
minSize: 8

# the maximum number of connections to keep open
maxSize: 256

# whether or not idle connections should be validated
checkConnectionWhileIdle: false

# how long a connection must be held before it can be validated
checkConnectionHealthWhenIdleFor: 10s

# the maximum lifetime of an idle connection
closeConnectionIfIdleFor: 1 minute

logging:

# The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
level: OFF

console:

# If true, write log statements to stdout.
enabled: false

88 changes: 88 additions & 0 deletions dropwizard/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?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>

<groupId>com.xekm</groupId>
<artifactId>hello-world</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.yammer.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>com.yammer.dropwizard</groupId>
<artifactId>dropwizard-hibernate</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.helloworld.HelloWorldService</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
25 changes: 25 additions & 0 deletions dropwizard/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import subprocess
import sys
import setup_util
from os.path import expanduser
import os

home = expanduser("~")

def start(args):
setup_util.replace_text("dropwizard/hello-world.yml", "url: jdbc:mysql://.*/hello_world", "url: jdbc:mysql://" + args.database_host + ":3306/hello_world")

try:
subprocess.check_call("mvn clean package;", shell=True, cwd="dropwizard")
subprocess.Popen("java -jar target/hello-world-0.0.1-SNAPSHOT.jar server hello-world.yml", shell=True, cwd="dropwizard")
return 0
except subprocess.CalledProcessError:
return 1
def stop():
p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.splitlines():
if 'hello-world' in line:
pid = int(line.split(None, 2)[1])
os.kill(pid, 9)
return 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

package com.example.helloworld;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotEmpty;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.yammer.dropwizard.config.Configuration;
import com.yammer.dropwizard.db.DatabaseConfiguration;

public class HelloWorldConfiguration
extends Configuration
{
@Valid
@NotNull
@JsonProperty
private DatabaseConfiguration database = new DatabaseConfiguration();

public DatabaseConfiguration getDatabaseConfiguration()
{
return database;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

package com.example.helloworld;

import com.example.helloworld.core.World;
import com.example.helloworld.db.WorldDAO;
import com.example.helloworld.resources.JsonResource;
import com.example.helloworld.resources.WorldResource;
import com.yammer.dropwizard.Service;
import com.yammer.dropwizard.config.Bootstrap;
import com.yammer.dropwizard.config.Environment;
import com.yammer.dropwizard.db.DatabaseConfiguration;
import com.yammer.dropwizard.hibernate.HibernateBundle;

public class HelloWorldService
extends Service<HelloWorldConfiguration>
{
private final HibernateBundle<HelloWorldConfiguration> hibernate = new HibernateBundle<HelloWorldConfiguration>(
World.class)
{
@Override
public DatabaseConfiguration getDatabaseConfiguration(
HelloWorldConfiguration configuration)
{
return configuration.getDatabaseConfiguration();
}
};

public static void main(String[] args) throws Exception
{
new HelloWorldService().run(args);
}

@Override
public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap)
{
bootstrap.setName("hello-world");
bootstrap.addBundle(hibernate);
}

@Override
public void run(HelloWorldConfiguration config, Environment environment)
{
final WorldDAO dao = new WorldDAO(hibernate.getSessionFactory());
environment.addResource(new WorldResource(dao));
environment.addResource(new JsonResource());
}

}
36 changes: 36 additions & 0 deletions dropwizard/src/main/java/com/example/helloworld/core/World.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

package com.example.helloworld.core;

import javax.persistence.*;

@Entity
@Table(name = "World")
public class World
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;

@Column(name = "randomNumber", nullable = false)
private long randomNumber;

public long getId()
{
return id;
}

public void setId(long id)
{
this.id = id;
}

public long getRandomNumber()
{
return this.randomNumber;
}

public void setRandomNumber(long randomNumber)
{
this.randomNumber = randomNumber;
}
}
22 changes: 22 additions & 0 deletions dropwizard/src/main/java/com/example/helloworld/db/WorldDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

package com.example.helloworld.db;

import org.hibernate.SessionFactory;

import com.example.helloworld.core.World;
import com.google.common.base.Optional;
import com.yammer.dropwizard.hibernate.AbstractDAO;

public class WorldDAO
extends AbstractDAO<World>
{
public WorldDAO(SessionFactory factory)
{
super(factory);
}

public Optional<World> findById(Long id)
{
return Optional.fromNullable(get(id));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

package com.example.helloworld.resources;

import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/json")
@Produces(MediaType.APPLICATION_JSON)
public class JsonResource
{
private final Map<String, String> MESSAGE = new HashMap<String, String>();

public JsonResource()
{
MESSAGE.put("message", "Hello, world!");
}

@GET
public Map<String, String> sayHello()
{
return MESSAGE;
}
}
Loading

0 comments on commit 1985290

Please sign in to comment.