-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create module packages for akka/webapi (#398)
Pulls the setup logic in standalone into modules that we can just include in other projects. We don't use the standalone jar internally it is just for simple testing. This change allows us to further reduce deviation from oss and internal.
- Loading branch information
1 parent
59024bb
commit 857888c
Showing
11 changed files
with
182 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
atlas-module-akka/src/main/resources/META-INF/services/com.google.inject.Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.netflix.atlas.akka.AkkaModule |
46 changes: 46 additions & 0 deletions
46
atlas-module-akka/src/main/scala/com/netflix/atlas/akka/AkkaModule.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2014-2016 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.netflix.atlas.akka | ||
|
||
import javax.inject.Singleton | ||
|
||
import akka.actor.ActorSystem | ||
import com.google.inject.AbstractModule | ||
import com.google.inject.Provides | ||
import com.google.inject.multibindings.Multibinder | ||
import com.netflix.iep.guice.LifecycleModule | ||
import com.netflix.iep.service.Service | ||
import com.typesafe.config.Config | ||
|
||
/** | ||
* Configures the actor system and web server. This module expects that bindings | ||
* are available for [[com.typesafe.config.Config]] and [[com.netflix.spectator.api.Registry]]. | ||
*/ | ||
class AkkaModule extends AbstractModule { | ||
override def configure(): Unit = { | ||
install(new LifecycleModule) | ||
val serviceBinder = Multibinder.newSetBinder(binder, classOf[Service]) | ||
serviceBinder.addBinding().to(classOf[ActorService]) | ||
serviceBinder.addBinding().to(classOf[WebServer]) | ||
} | ||
|
||
@Provides @Singleton | ||
private def providesActorSystem(config: Config): ActorSystem = { | ||
val name = config.getString("atlas.akka.name") | ||
ActorSystem(name, config) | ||
} | ||
} | ||
|
50 changes: 50 additions & 0 deletions
50
atlas-module-akka/src/test/scala/com/netflix/atlas/akka/AkkaModuleSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2014-2016 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.netflix.atlas.akka | ||
|
||
import akka.actor.ActorSystem | ||
import com.google.inject.AbstractModule | ||
import com.google.inject.Guice | ||
import com.netflix.iep.guice.PreDestroyList | ||
import com.netflix.iep.service.ServiceManager | ||
import com.netflix.spectator.api.NoopRegistry | ||
import com.netflix.spectator.api.Registry | ||
import com.typesafe.config.Config | ||
import com.typesafe.config.ConfigFactory | ||
import org.scalatest.FunSuite | ||
|
||
class AkkaModuleSuite extends FunSuite { | ||
|
||
private val testCfg = ConfigFactory.parseString( | ||
""" | ||
|atlas.akka.name = test | ||
|atlas.akka.port = 0 | ||
|atlas.akka.actors = [] | ||
""".stripMargin) | ||
|
||
test("load module") { | ||
val deps = new AbstractModule { | ||
override def configure(): Unit = { | ||
bind(classOf[Config]).toInstance(testCfg.withFallback(ConfigFactory.load())) | ||
bind(classOf[Registry]).toInstance(new NoopRegistry) | ||
} | ||
} | ||
val injector = Guice.createInjector(deps, new AkkaModule) | ||
assert(injector.getInstance(classOf[ActorSystem]) != null) | ||
assert(injector.getInstance(classOf[ServiceManager]).services().size === 2) | ||
injector.getInstance(classOf[PreDestroyList]).invokeAll() | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
atlas-module-webapi/src/main/resources/META-INF/services/com.google.inject.Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
com.netflix.atlas.guice.WebApiModule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
atlas-module-webapi/src/test/scala/com/netflix/atlas/guice/WebApiModuleSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2014-2016 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.netflix.atlas.guice | ||
|
||
import com.google.inject.AbstractModule | ||
import com.google.inject.Guice | ||
import com.netflix.atlas.core.db.Database | ||
import com.netflix.iep.guice.PreDestroyList | ||
import com.typesafe.config.Config | ||
import com.typesafe.config.ConfigFactory | ||
import org.scalatest.FunSuite | ||
|
||
class WebApiModuleSuite extends FunSuite { | ||
|
||
test("load module") { | ||
val deps = new AbstractModule { | ||
override def configure(): Unit = { | ||
bind(classOf[Config]).toInstance(ConfigFactory.load()) | ||
} | ||
} | ||
val injector = Guice.createInjector(deps, new WebApiModule) | ||
assert(injector.getInstance(classOf[Database]) != null) | ||
injector.getInstance(classOf[PreDestroyList]).invokeAll() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters