Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit aad3d48e7449ce4cd0356adeac809880c09aae8b 0 parents
@codahale codahale authored
7 .gitignore
@@ -0,0 +1,7 @@
+.idea
+lib_managed
+src_managed
+project/boot
+target
+project/plugins/project/build.properties
+*.iml
1  example.conf
102 example.conf.template
@@ -0,0 +1,102 @@
+{
+ "example": {
+ "template": "Oh, hey there %s!",
+ "default_name": "Stranger"
+ },
+
+ "http": {
+ // The type of connector to use. Other valid values are "select_channel" or
+ // "socket".
+ "connector": "blocking_channel",
+
+ // The TCP/IP port Jetty will host your server on.
+ "port": 8080,
+
+ // Maximum number of concurrent connections.
+ "max_connections": 50,
+
+ // Number of milliseconds to wait for connections to complete while
+ // gracefully shutting down.
+ "shutdown_milliseconds": 2000,
+
+ // The hostname of the interface on which to listen. If not set, it will
+ // listen on all available interfaces.
+ // "hostname": "localhost",
+
+ // Whether or not the server is downstream from a proxy which appends
+ // X-Forwarded-For headers.
+ "forwarded": false
+ },
+
+ "metrics": {
+ // The TCP/IP port Jetty will expose your metrics on.
+ "port": 8081
+ },
+
+ "logging": {
+ // The default logger level.
+ "level": "info",
+
+ // A set of specific logger levels.
+ "loggers": {
+ "com.yammer.notifications": "info"
+ },
+
+ "console": {
+ // Whether or not to output log statements to STDOUT.
+ "enabled": true,
+
+ // The log level threshold for console logging.
+ "threshold": "all"
+ },
+ "file": {
+ // Whether or not to output log statement to a log file.
+ "enabled": false,
+
+ // The filename pattern for the log file.
+ "filename": "./logs/notifications.log",
+
+ // Let logs get to 50MB in size.
+ "max_log_size_kilobytes": 51200,
+
+ // Retain the last five log files.
+ "retain_files": 5,
+
+ // The log level threshold for file logging.
+ "threshold": "all"
+ }
+ },
+
+ "request_log": {
+ // Whether or not to log all requests to an NSCA-formatted log.
+ "enabled": false,
+
+ // Whether to append to existing log files or overwrite them.
+ "append": true,
+
+ // The filename of the log file, where "yyyy_mm_dd" will be replaced with the
+ // current date.
+ "filename": "./logs/yyyy_mm_dd.log",
+
+ // Whether to log referrer, user-agent, and x-forwarded-for values.
+ "extended": false,
+
+ // URIs which will not be logged.
+ "ignore_paths": ["/health"],
+
+ // Whether to log cookie values.
+ "include_cookies": false,
+
+ // Whether to log the number of milliseconds a response took.
+ "include_latency": true,
+
+ // Whether to log the Host header of requests.
+ "include_server": false,
+
+ // The timezone that timestamps should be in.
+ "timezone": "UTC",
+
+ // The maximum number of logfiles to retain.
+ "retain_days": 90
+ }
+}
8 project/build.properties
@@ -0,0 +1,8 @@
+#Project properties
+#Thu Nov 04 15:26:43 PDT 2010
+project.organization=com.yammer
+project.name=dropwizard-example
+sbt.version=0.7.5.RC0
+project.version=1.0-SNAPSHOT
+build.scala.versions=2.8.1
+project.initialize=false
54 project/build/DropWizardExampleProject.scala
@@ -0,0 +1,54 @@
+import sbt._
+import assembly._
+import maven._
+import de.element34.sbteclipsify._
+
+class DropWizardExampleProject(info: ProjectInfo) extends DefaultProject(info)
+ with MavenDependencies
+ with IdeaProject
+ with AssemblyBuilder
+ with Eclipsify {
+ /**
+ * Always check for new versions of snapshot dependencies.
+ */
+ override def snapshotUpdatePolicy = SnapshotUpdatePolicy.Always
+
+ /**
+ * Repositories
+ */
+ val codasRepo = "Coda's Repo" at "http://repo.codahale.com"
+ val googleMaven = "Google Maven" at "http://google-maven-repository.googlecode.com/svn/repository/"
+ val sunRepo = "Sun Repo" at "http://download.java.net/maven/2/"
+ val yammerRepo = "Yammer's Internal Repo" at "http://repo.yammer.com/maven/"
+
+ /**
+ * Service Dependencies
+ */
+ val dropWizard = "com.yammer" %% "dropwizard" % "0.0.2-SNAPSHOT"
+
+ /**
+ * Test Dependencies
+ */
+ val simplespec = "com.codahale" %% "simplespec" % "0.2.0" % "test"
+ val mockito = "org.mockito" % "mockito-all" % "1.8.4" % "test"
+
+ override def fork = forkRun(List(
+ "-server", // make sure we're using the 64-bit server VM
+ "-d64",
+ "-XX:+UseParNewGC", // use parallel GC for the new generation
+ "-XX:+UseConcMarkSweepGC", // use concurrent mark-and-sweep for the old generation
+ "-XX:+CMSParallelRemarkEnabled", // use multiple threads for the remark phase
+ "-XX:+AggressiveOpts", // use the latest and greatest in JVM tech
+ "-XX:+UseFastAccessorMethods", // be sure to inline simple accessor methods
+ "-XX:+UseBiasedLocking", // speed up uncontended locks
+ "-Xss128k", // reduce the thread stack size, freeing up space for the heap
+ "-Xmx500M", // same with the max heap size
+ // "-XX:+PrintGCDetails", // log GC details to stdout
+ // "-XX:+PrintGCTimeStamps",
+ "-XX:+HeapDumpOnOutOfMemoryError" // dump the heap if we run out of memory
+ ))
+
+ lazy val server = runTask(
+ getMainClass(true), runClasspath, List("server", "example.conf")
+ ) dependsOn(compile) describedAs("Runs Example Service with example.conf")
+}
10 project/plugins/Plugins.scala
@@ -0,0 +1,10 @@
+class Plugins(info: sbt.ProjectInfo) extends sbt.PluginDefinition(info) {
+ val codaRepo = "Coda Hale's Repository" at "http://repo.codahale.com/"
+ val assemblySBT = "com.codahale" % "assembly-sbt" % "0.1.1"
+ val mavenSBT = "com.codahale" % "maven-sbt" % "0.1.1"
+
+ val sbtIdeaRepo = "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"
+ val sbtIdea = "com.github.mpeltonen" % "sbt-idea-plugin" % "0.3.0"
+
+ val eclipse = "de.element34" % "sbt-eclipsify" % "0.7.0"
+}
0  src/main/resources/.git-turd
No changes.
19 src/main/scala/com/yammer/example/Example.scala
@@ -0,0 +1,19 @@
+package com.yammer.example
+
+import com.yammer.dropwizard.Service
+import com.yammer.dropwizard.service.Jersey
+import config.TemplateModule
+
+object Example extends Service with Jersey {
+ require(new TemplateModule)
+
+ def name = "example-service"
+
+ override def banner = Some("""
+HERP A DERP DERP HERIPTY DERP DERP HERP A DING DERP DOP TEEDLY TUM HERP DOOP BOH
+HERP A DERP DERP HERIPTY DERP DERP HERP A DING DERP DOP TEEDLY TUM HERP DOOP BOH
+HERP A DERP DERP Example Service! HERP DOOP BOH
+HERP A DERP DERP HERIPTY DERP DERP HERP A DING DERP DOP TEEDLY TUM HERP DOOP BOH
+HERP A DERP DERP HERIPTY DERP DERP HERP A DING DERP DOP TEEDLY TUM HERP DOOP BOH
+""")
+}
17 src/main/scala/com/yammer/example/config/TemplateModule.scala
@@ -0,0 +1,17 @@
+package com.yammer.example.config
+
+import com.codahale.fig.Configuration
+import com.google.inject.{Provides, Singleton}
+import com.yammer.example.data.Template
+import com.yammer.dropwizard.modules.ProviderModule
+
+class TemplateModule extends ProviderModule {
+ @Provides
+ @Singleton
+ def provideTemplate(config: Configuration): Template = {
+ Template(
+ config("example.template").asRequired[String],
+ config("example.default_name").or("Stranger")
+ )
+ }
+}
3  src/main/scala/com/yammer/example/data/Saying.scala
@@ -0,0 +1,3 @@
+package com.yammer.example.data
+
+case class Saying(id: Long, content: String)
5 src/main/scala/com/yammer/example/data/Template.scala
@@ -0,0 +1,5 @@
+package com.yammer.example.data
+
+case class Template(template: String, defaultName: String) {
+ def apply(name: Option[String]) = template.format(name.getOrElse(defaultName))
+}
18 src/main/scala/com/yammer/example/resources/HelloWorldResource.scala
@@ -0,0 +1,18 @@
+package com.yammer.example.resources
+
+import javax.ws.rs.core.MediaType
+import com.google.inject.{Inject, Singleton}
+import javax.ws.rs.{QueryParam, GET, Produces, Path}
+import com.yammer.example.data.{Saying, Template}
+import java.util.concurrent.atomic.AtomicLong
+
+@Path("/hello-world")
+@Produces(Array(MediaType.APPLICATION_JSON))
+@Singleton
+class HelloWorldResource @Inject()(template: Template) {
+ private val counter = new AtomicLong(0)
+
+ @GET
+ def sayHello(@QueryParam("name") name: Option[String]) =
+ Saying(counter.incrementAndGet, template(name))
+}
0  src/test/resources/.git-turd
No changes.
0  src/test/scala/.git-turd
No changes.
61 src/test/scala/com/example/config/tests/TemplateModuleSpec.scala
@@ -0,0 +1,61 @@
+package com.example.config.tests
+
+import com.codahale.simplespec.Spec
+import io.Source
+import com.yammer.example.config.TemplateModule
+import com.yammer.example.data.Template
+import com.codahale.fig.{ConfigurationException, Configuration}
+
+object TemplateModuleSpec extends Spec {
+ class `A config file with a template and a default name` {
+ val config = new Configuration(Source.fromString("""
+ {
+ "example": {
+ "template": "Hello there %s.",
+ "default_name": "dude"
+ }
+ }
+ """))
+
+ val module = new TemplateModule
+
+ def `should produce a template with a default name` {
+ module.provideTemplate(config) must beEqualTo(Template("Hello there %s.", "dude"))
+ }
+ }
+
+ class `A config file with a template and no default name` {
+ val config = new Configuration(Source.fromString("""
+ {
+ "example": {
+ "template": "Hello there %s."
+ }
+ }
+ """
+ )
+ )
+
+ val module = new TemplateModule
+
+ def `should produce a template with a default name` {
+ module.provideTemplate(config) must beEqualTo(Template("Hello there %s.", "Stranger"))
+ }
+ }
+
+ class `A config file with no template` {
+ val config = new Configuration(Source.fromString("""
+ {
+ "example": {
+ }
+ }
+ """
+ )
+ )
+
+ val module = new TemplateModule
+
+ def `should throw an exception` {
+ module.provideTemplate(config) must throwA[ConfigurationException]
+ }
+ }
+}
18 src/test/scala/com/example/data/tests/SayingSpec.scala
@@ -0,0 +1,18 @@
+package com.example.data.tests
+
+import com.codahale.simplespec.Spec
+import com.yammer.example.data.Saying
+
+object SayingSpec extends Spec {
+ class `A saying` {
+ val saying = Saying(1, "yay")
+
+ def `should have an ID` {
+ saying.id must beEqualTo(1)
+ }
+
+ def `should have content` {
+ saying.content must beEqualTo("yay")
+ }
+ }
+}
26 src/test/scala/com/example/data/tests/TemplateSpec.scala
@@ -0,0 +1,26 @@
+package com.example.data.tests
+
+import com.codahale.simplespec.Spec
+import com.yammer.example.data.Template
+
+object TemplateSpec extends Spec {
+ class `A template` {
+ val template = Template("Hello there %s.", "stranger")
+
+ def `should have a template` {
+ template.template must beEqualTo("Hello there %s.")
+ }
+
+ def `should have a default name` {
+ template.defaultName must beEqualTo("stranger")
+ }
+
+ def `should render the template` {
+ template(Some("Frank")) must beEqualTo("Hello there Frank.")
+ }
+
+ def `should render the template using the default name` {
+ template(None) must beEqualTo("Hello there stranger.")
+ }
+ }
+}
20 src/test/scala/com/example/resources/test/HelloWorldResourceSpec.scala
@@ -0,0 +1,20 @@
+package com.example.resources.test
+
+import com.codahale.simplespec.Spec
+import com.yammer.example.resources.HelloWorldResource
+import com.yammer.example.data.{Saying, Template}
+
+object HelloWorldResourceSpec extends Spec {
+ class `Saying hello to the world` {
+ val resource = new HelloWorldResource(Template("Hello there %s.", "stranger"))
+
+ def `should return a saying with a unique ID` {
+ resource.sayHello(None) must beEqualTo(Saying(1, "Hello there stranger."))
+ resource.sayHello(None) must beEqualTo(Saying(2, "Hello there stranger."))
+ }
+
+ def `should use a specific name if one is given` {
+ resource.sayHello(Some("Frank")) must beEqualTo(Saying(1, "Hello there Frank."))
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.