Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

hazelcast clustering test

  • Loading branch information...
commit 2202534616846c56bdd0cb3c5c8a90667034147e 1 parent 87d510f
@alextkachman alextkachman authored
View
6 gretty-hazelcast/src/org/mbte/gretty/hazelcast/GrettyHazelcastSessionManager.groovy
@@ -19,10 +19,8 @@ package org.mbte.gretty.hazelcast
import org.mbte.gretty.httpserver.session.GrettySessionManager
import org.mbte.gretty.httpserver.session.GrettySession
import groovypp.concurrent.BindLater
-import com.hazelcast.config.MapConfig
import com.hazelcast.core.IMap
import java.util.concurrent.TimeUnit
-import com.sun.corba.se.spi.activation.Server
@Typed class GrettyHazelcastSessionManager extends GrettySessionManager {
final static String GRETTY_SESSION_MAP = "gretty:sessions"
@@ -43,13 +41,13 @@ Use org.mbte.gretty.hazelcast.GrettyHazelcastManager to configure.
}
GrettySession getSession(String id) {
- map.get(id)
+ map.get(id)[server: server]
}
BindLater<GrettySession> getSessionAsync(String id, GrettySessionManager.SessionCallback callback = null) {
def later = callback ?: new BindLater()
server.execute {
- later.set(map.get(id))
+ later.set(map.get(id)[server: server])
}
later
}
View
81 gretty-hazelcast/tests/org/mbte/gretty/hazelcast/ClusterTest.groovy
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2009-2011 MBTE Sweden AB.
+ *
+ * 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 org.mbte.gretty.hazelcast
+
+import com.hazelcast.config.MapConfig
+import org.jboss.netty.handler.codec.http.HttpMethod
+import org.mbte.gretty.httpserver.GrettyHttpRequest
+import org.mbte.gretty.httpserver.GrettyHttpResponse
+import org.mbte.gretty.test.GrettyServerTestCase
+import org.mbte.gretty.httpserver.GrettyServer
+import org.jboss.netty.channel.local.LocalAddress
+import org.mbte.gretty.httpclient.HttpRequestHelper
+
+@Typed class ClusterTest extends GroovyTestCase implements HttpRequestHelper {
+ List<GrettyServer> servers = []
+ protected void setUp() {
+ for (i in 0..<3) {
+ GrettyHazelcastManager hazelcast = []
+ MapConfig mc = []
+ mc.setName(GrettyHazelcastSessionManager.GRETTY_SESSION_MAP)
+ hazelcast.config.addMapConfig(mc)
+
+ GrettyServer server = [
+ localAddress: new LocalAddress("test_server_$i"),
+
+ sessionManager: new GrettyHazelcastSessionManager(hazelcast),
+
+ default: {
+ Integer obj = session.counter
+ println "$i: $obj"
+ if(obj == null) {
+ session.counter = obj = 1
+ }
+ else {
+ obj = obj + 1
+ session.counter = obj
+ }
+ response.text = obj
+ },
+ ]
+ servers << server
+ }
+ servers*.start()
+ super.setUp()
+ }
+
+ protected void tearDown() {
+ servers.reverse()*.stop()
+ super.tearDown()
+ }
+
+ void testMe () {
+ Reference sessionId = []
+ for (i in 0..<100) {
+ GrettyHttpRequest req = [method:HttpMethod.GET, uri:"/"]
+ if(sessionId.get())
+ req.addCookie("JSESSIONID", sessionId.get().toString())
+
+ doTest(req, "test_server_${i%3}") { GrettyHttpResponse response ->
+ def session = response.getCookie("JSESSIONID")?.value
+ sessionId.set(session)
+ println "$i ${response.contentText} $session"
+ assert response.contentText == "${i+1}"
+ }
+ }
+ }
+}
View
27 gretty-redis/build.gradle
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2009-2011 MBTE Sweden AB.
+ *
+ * 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.
+ */
+
+dependsOn ':gretty'
+
+dependencies {
+ groovy group: 'org.codehaus.groovy', name: 'groovy', version: "1.8.0"
+
+ compile project(':gretty')
+
+ compile 'redis.clients:jedis:2.0.0'
+
+ testCompile(group: 'junit', name: 'junit', version: '4.8.1')
+}
View
122 gretty-redis/gretty-redis.iml
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module relativePaths="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
+ <output url="file://$MODULE_DIR$/build/classes/main" />
+ <output-test url="file://$MODULE_DIR$/build/classes/test" />
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/groovy" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/groovy" isTestSource="true" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/.gradle" />
+ <excludeFolder url="file://$MODULE_DIR$/build" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="module-library" exported="">
+ <library>
+ <CLASSES>
+ <root url="jar://$USER_HOME$/.gradle/cache/redis.clients/jedis/jars/jedis-2.0.0.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES>
+ <root url="jar://$USER_HOME$/.gradle/cache/redis.clients/jedis/sources/jedis-2.0.0-sources.jar!/" />
+ </SOURCES>
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" exported="">
+ <library>
+ <CLASSES>
+ <root url="jar://$USER_HOME$/.gradle/cache/commons-pool/commons-pool/jars/commons-pool-1.5.5.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES>
+ <root url="jar://$USER_HOME$/.gradle/cache/commons-pool/commons-pool/sources/commons-pool-1.5.5-sources.jar!/" />
+ </SOURCES>
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" exported="">
+ <library>
+ <CLASSES>
+ <root url="jar://$USER_HOME$/.gradle/cache/org.codehaus.groovy/groovy/jars/groovy-1.8.0.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES>
+ <root url="jar://$USER_HOME$/.gradle/cache/org.codehaus.groovy/groovy/sources/groovy-1.8.0-sources.jar!/" />
+ </SOURCES>
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" exported="">
+ <library>
+ <CLASSES>
+ <root url="jar://$USER_HOME$/.gradle/cache/antlr/antlr/jars/antlr-2.7.7.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" exported="">
+ <library>
+ <CLASSES>
+ <root url="jar://$USER_HOME$/.gradle/cache/asm/asm/jars/asm-3.2.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" exported="">
+ <library>
+ <CLASSES>
+ <root url="jar://$USER_HOME$/.gradle/cache/asm/asm-commons/jars/asm-commons-3.2.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" exported="">
+ <library>
+ <CLASSES>
+ <root url="jar://$USER_HOME$/.gradle/cache/asm/asm-tree/jars/asm-tree-3.2.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" exported="">
+ <library>
+ <CLASSES>
+ <root url="jar://$USER_HOME$/.gradle/cache/asm/asm-util/jars/asm-util-3.2.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" exported="">
+ <library>
+ <CLASSES>
+ <root url="jar://$USER_HOME$/.gradle/cache/asm/asm-analysis/jars/asm-analysis-3.2.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module" module-name="gretty" exported="" />
+ <orderEntry type="module-library" scope="TEST">
+ <library>
+ <CLASSES>
+ <root url="jar://$USER_HOME$/.gradle/cache/junit/junit/jars/junit-4.8.1.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES>
+ <root url="jar://$USER_HOME$/.gradle/cache/junit/junit/sources/junit-4.8.1-sources.jar!/" />
+ </SOURCES>
+ </library>
+ </orderEntry>
+ </component>
+</module>
+
View
34 gretty/gretty.iml
@@ -16,6 +16,7 @@
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
+ <content url="file://$MODULE_DIR$/../redis" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" exported="">
@@ -174,6 +175,17 @@
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
+ <root url="jar://$USER_HOME$/.gradle/cache/junit/junit/jars/junit-4.8.1.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES>
+ <root url="jar://$USER_HOME$/.gradle/cache/junit/junit/sources/junit-4.8.1-sources.jar!/" />
+ </SOURCES>
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library" exported="">
+ <library>
+ <CLASSES>
<root url="jar://$USER_HOME$/.gradle/cache/org.codehaus.groovy/groovy/jars/groovy-1.8.0.jar!/" />
</CLASSES>
<JAVADOC />
@@ -239,17 +251,6 @@
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
- <root url="jar://$USER_HOME$/.gradle/cache/junit/junit/jars/junit-4.8.1.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root url="jar://$USER_HOME$/.gradle/cache/junit/junit/sources/junit-4.8.1-sources.jar!/" />
- </SOURCES>
- </library>
- </orderEntry>
- <orderEntry type="module-library" exported="">
- <library>
- <CLASSES>
<root url="jar://$USER_HOME$/.gradle/cache/org.jboss.netty/netty/bundles/netty-3.2.4.Final.jar!/" />
</CLASSES>
<JAVADOC />
@@ -291,17 +292,6 @@
</SOURCES>
</library>
</orderEntry>
- <orderEntry type="module-library" scope="TEST">
- <library>
- <CLASSES>
- <root url="jar://$USER_HOME$/.gradle/cache/junit/junit/jars/junit-4.8.1.jar!/" />
- </CLASSES>
- <JAVADOC />
- <SOURCES>
- <root url="jar://$USER_HOME$/.gradle/cache/junit/junit/sources/junit-4.8.1-sources.jar!/" />
- </SOURCES>
- </library>
- </orderEntry>
</component>
</module>
View
20 gretty/src/org/mbte/gretty/httpclient/HttpRequestHelper.groovy
@@ -26,13 +26,21 @@ import org.mbte.gretty.httpserver.GrettyHttpResponse
@Trait abstract class HttpRequestHelper {
void doTest (String request, Function1<GrettyHttpResponse,Void> action) {
- doTest([uri:request], action)
+ doTest([uri:request], "test_server", action)
+ }
+
+ void doTest (String request, String address, Function1<GrettyHttpResponse,Void> action) {
+ doTest([uri:request], address, action)
}
void doTest (GrettyHttpRequest request, Function1<GrettyHttpResponse,Void> action) {
+ doTest(request, "test_server", action)
+ }
+
+ void doTest (GrettyHttpRequest request, String address, Function1<GrettyHttpResponse,Void> action) {
BindLater cdl = []
- GrettyClient client = [new LocalAddress("test_server")]
+ GrettyClient client = [new LocalAddress(address)]
client.connect{ future ->
client.request(request) { bound ->
try {
@@ -49,11 +57,11 @@ import org.mbte.gretty.httpserver.GrettyHttpResponse
client.disconnect ()
}
- void doTest (String request, Closure action) {
- doTest(request, { req -> action(req) } )
+ void doTest (String request, String address = "test_server", Closure action) {
+ doTest(request, address, { req -> action(req) } )
}
- void doTest (GrettyHttpRequest request, Closure action) {
- doTest(request, { req -> action(req) } )
+ void doTest (GrettyHttpRequest request, String address = "test_server", Closure action) {
+ doTest(request, address, { req -> action(req) } )
}
}
View
4 gretty/src/org/mbte/gretty/httpserver/session/GrettyInMemorySessionManager.groovy
@@ -23,12 +23,12 @@ import groovypp.concurrent.BindLater
private final ConcurrentHashMap<String,GrettySession> sessions = [:]
GrettySession getSession(String id) {
- sessions[id]
+ sessions[id][server: server]
}
BindLater<GrettySession> getSessionAsync(String id, SessionCallback callback = null) {
def later = callback ?: new BindLater()
- later.set(sessions[id])
+ later.set(sessions[id][server: server])
later
}
View
2  settings.gradle
@@ -1 +1 @@
-include 'gretty', 'gretty-hazelcast'
+include 'gretty', 'gretty-hazelcast', 'gretty-redis'
Please sign in to comment.
Something went wrong with that request. Please try again.