Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update to use platform manager in 2.0 snapshot

  • Loading branch information...
commit 45b476dd01d04efe226d70a5d83709ffed751509 1 parent 038f001
@pidster pidster authored
Showing with 2,040 additions and 160 deletions.
  1. +6 −5 build.gradle
  2. +2 −2 gradle.properties
  3. +4 −3 src/main/java/org/vertx/java/test/{VerticleManagerAware.java → ContainerAware.java}
  4. +29 −0 src/main/java/org/vertx/java/test/PlatformManagerAware.java
  5. +2 −0  src/main/java/org/vertx/java/test/TestVerticle.java
  6. +7 −7 src/main/java/org/vertx/java/test/VertxTestBase.java
  7. +4 −4 src/main/java/org/vertx/java/test/junit/JUnitDeploymentUtils.java
  8. +6 −7 src/main/java/org/vertx/java/test/junit/VertxExternalResource.java
  9. +36 −31 src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java
  10. +17 −13 src/main/java/org/vertx/java/test/utils/DeploymentUtils.java
  11. +8 −8 src/main/java/org/vertx/java/test/utils/InjectionUtils.java
  12. +1 −1  src/test/java/org/vertx/java/test/junit/JsonConfigVerticleTest.java
  13. +7 −14 src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java
  14. +18 −17 src/test/java/org/vertx/java/test/junit/SimpleModuleTest.java
  15. +1 −1  src/test/java/org/vertx/java/test/junit/SimpleTestBusModTest.java
  16. +11 −11 src/test/java/org/vertx/java/test/junit/SimpleVerticleTest.java
  17. +4 −6 src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java
  18. +2 −2 src/test/java/org/vertx/java/test/junit/VertxConfigurationTest.java
  19. +16 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/coffee-script.js
  20. +20 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/buffer.js
  21. +84 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/deploy.js
  22. +27 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/env.js
  23. +174 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/event_bus.js
  24. +426 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/filesystem.js
  25. +679 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/http.js
  26. +35 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/logger.js
  27. +27 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/net.js
  28. +27 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/parse_tools.js
  29. +39 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/shared_data.js
  30. +66 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/sockjs.js
  31. +53 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/streams.js
  32. +36 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/timers.js
  33. +23 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/utils.js
  34. BIN  src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/lib/rhino-1.7R4.jar
  35. +4 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/mod.json
  36. BIN  src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/org/vertx/java/platform/impl/CoffeeScriptCompiler.class
  37. BIN  src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/org/vertx/java/platform/impl/RhinoContextFactory.class
  38. BIN  ...est/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/org/vertx/java/platform/impl/RhinoVerticleFactory$1.class
  39. BIN  ...est/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/org/vertx/java/platform/impl/RhinoVerticleFactory$2.class
  40. BIN  ...en:io.vertx:lang-rhino:1.0.0-SNAPSHOT/org/vertx/java/platform/impl/RhinoVerticleFactory$RhinoVerticle.class
  41. BIN  src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/org/vertx/java/platform/impl/RhinoVerticleFactory.class
  42. +69 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/test_utils.js
  43. +33 −0 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/vertx.js
  44. +32 −28 src/test/resources/langs.properties
  45. +5 −0 src/test/resources/repos.txt
View
11 build.gradle
@@ -24,18 +24,19 @@ sourceCompatibility = '1.7'
targetCompatibility = '1.7'
repositories {
+ mavenLocal()
+ maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
mavenCentral()
}
dependencies {
compile "junit:junit-dep:$junitVersion"
- compile "org.vert-x:vertx-core:$vertxVersion"
- compile "org.vert-x:vertx-platform:$vertxVersion"
+ compile "io.vertx:vertx-core:$vertxVersion"
+ compile "io.vertx:vertx-platform:$vertxVersion"
- testCompile "org.vert-x:vertx-lang-java:$vertxVersion"
- testCompile "org.vert-x:vertx-lang-rhino:$vertxVersion"
+// testCompile "io.vertx:lang-java:$vertxVersion"
+ testCompile "io.vertx:lang-rhino:1.0.0-SNAPSHOT"
testCompile "org.mozilla:rhino:$rhinoVersion"
-
}
test {
View
4 gradle.properties
@@ -13,12 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-version=1.3.3-SNAPSHOT
+version=2.0.0-SNAPSHOT
group=org.vert-x
modulename=vertx-junit-annotations
gradleVersion=1.4
-vertxVersion=1.3.1.final
+vertxVersion=2.0.0-SNAPSHOT
rhinoVersion=1.7R4
junitVersion=4.11
View
7 ...vertx/java/test/VerticleManagerAware.java → ...a/org/vertx/java/test/ContainerAware.java
@@ -15,14 +15,15 @@
*/
package org.vertx.java.test;
-import org.vertx.java.deploy.impl.VerticleManager;
+import org.vertx.java.platform.Container;
+
/**
* @author swilliams
*
*/
-public interface VerticleManagerAware {
+public interface ContainerAware {
- void setVerticleManager(VerticleManager verticleManager);
+ void setContainer(Container container);
}
View
29 src/main/java/org/vertx/java/test/PlatformManagerAware.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2012 the original author or authors.
+ *
+ * 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.vertx.java.test;
+
+import org.vertx.java.platform.PlatformManager;
+
+
+/**
+ * @author swilliams
+ *
+ */
+public interface PlatformManagerAware {
+
+ void setPlatformManager(PlatformManager platformManager);
+
+}
View
2  src/main/java/org/vertx/java/test/TestVerticle.java
@@ -35,6 +35,8 @@
boolean worker() default false;
+ boolean multiThreaded() default false;
+
String main();
int instances() default 1;
View
14 src/main/java/org/vertx/java/test/VertxTestBase.java
@@ -28,7 +28,7 @@
import org.vertx.java.core.Vertx;
import org.vertx.java.core.eventbus.EventBus;
import org.vertx.java.core.eventbus.Message;
-import org.vertx.java.deploy.impl.VerticleManager;
+import org.vertx.java.platform.Container;
import org.vertx.java.test.utils.QueueReplyHandler;
import org.vertx.java.test.utils.SimpleLatchAsyncResultHandler;
@@ -37,11 +37,11 @@
* @author swilliams
*
*/
-public abstract class VertxTestBase implements VertxAware, VerticleManagerAware {
+public abstract class VertxTestBase implements VertxAware, ContainerAware {
private Vertx vertx;
- private VerticleManager manager;
+ private Container container;
@SuppressWarnings("rawtypes")
private Map<String, VertxHandlerMapping> mappings = new HashMap<>();
@@ -58,8 +58,8 @@ public void setVertx(Vertx vertx) {
}
@Override
- public void setVerticleManager(VerticleManager manager) {
- this.manager = manager;
+ public void setContainer(Container container) {
+ this.container = container;
}
protected Vertx getVertx() {
@@ -70,8 +70,8 @@ protected EventBus getEventBus() {
return vertx.eventBus();
}
- protected VerticleManager getManager() {
- return manager;
+ protected Container getContainer() {
+ return container;
}
protected static final void setAwaitTimeout(long awaitTimeout) {
View
8 src/main/java/org/vertx/java/test/junit/JUnitDeploymentUtils.java
@@ -23,7 +23,7 @@
import java.util.Set;
import org.junit.runner.Description;
-import org.vertx.java.deploy.impl.VerticleManager;
+import org.vertx.java.platform.PlatformManager;
import org.vertx.java.test.TestModule;
import org.vertx.java.test.TestModules;
import org.vertx.java.test.TestVerticle;
@@ -41,7 +41,7 @@
* @param description
* @return map
*/
- public static Map<Annotation, String> deploy(VerticleManager manager, File modDir, Description description, long timeout) {
+ public static Map<Annotation, String> deploy(PlatformManager platformManager, File modDir, Description description, long timeout) {
Map<Annotation, String> deployments = new HashMap<>();
@@ -60,7 +60,7 @@
}
}
- Map<Annotation, String> verticleDeployments = DeploymentUtils.deployVerticles(manager, modDir, verticles, timeout);
+ Map<Annotation, String> verticleDeployments = DeploymentUtils.deployVerticles(platformManager, modDir, verticles, timeout);
deployments.putAll(verticleDeployments);
// ------------------------------------------------------------------------------
@@ -78,7 +78,7 @@
}
}
- Map<Annotation, String> modulesDeployments = DeploymentUtils.deployModules(manager, modDir, modules, timeout);
+ Map<Annotation, String> modulesDeployments = DeploymentUtils.deployModules(platformManager, modDir, modules, timeout);
deployments.putAll(modulesDeployments);
// ------------------------------------------------------------------------------
View
13 src/main/java/org/vertx/java/test/junit/VertxExternalResource.java
@@ -22,9 +22,8 @@
import org.junit.rules.ExternalResource;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
-import org.vertx.java.deploy.impl.VerticleManager;
+import org.vertx.java.platform.PlatformManager;
import org.vertx.java.test.utils.DeploymentRegistry;
-import org.vertx.java.test.utils.DeploymentUtils;
/**
* @author swilliams
@@ -34,14 +33,14 @@
private File modDir;
- private VerticleManager manager;
+ private PlatformManager platformManager;
private Description description;
private Map<Annotation, String> methodDeployments;
- public VertxExternalResource(VerticleManager manager) {
- this.manager = manager;
+ public VertxExternalResource(PlatformManager platformManager) {
+ this.platformManager = platformManager;
}
@Override
@@ -59,7 +58,7 @@ public Statement apply(Statement base, Description description) {
@Override
protected void before() throws Throwable {
long timeout = Long.getLong("vertx.test.timeout", 15000L);
- this.methodDeployments = JUnitDeploymentUtils.deploy(manager, modDir, description, timeout);
+ this.methodDeployments = JUnitDeploymentUtils.deploy(platformManager, modDir, description, timeout);
DeploymentRegistry.register(methodDeployments);
super.before();
}
@@ -67,7 +66,7 @@ protected void before() throws Throwable {
@Override
protected void after() {
if (methodDeployments.size() > 0) {
- DeploymentUtils.undeploy(manager, methodDeployments);
+ // DeploymentUtils.undeploy(container, methodDeployments);
}
super.after();
DeploymentRegistry.clear();
View
67 src/main/java/org/vertx/java/test/junit/VertxJUnit4ClassRunner.java
@@ -24,10 +24,13 @@
import org.junit.runner.Description;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
-import org.vertx.java.core.impl.VertxInternal;
-import org.vertx.java.deploy.Container;
-import org.vertx.java.deploy.Verticle;
-import org.vertx.java.deploy.impl.VerticleManager;
+import org.vertx.java.platform.Container;
+import org.vertx.java.platform.PlatformManagerFactory;
+import org.vertx.java.platform.Verticle;
+import org.vertx.java.platform.PlatformManager;
+import org.vertx.java.platform.impl.DefaultPlatformManagerFactory;
+import org.vertx.java.platform.impl.PlatformManagerInternal;
+
import org.vertx.java.test.VertxConfiguration;
import org.vertx.java.test.utils.CountDownLatchDoneHandler;
import org.vertx.java.test.utils.DeploymentRegistry;
@@ -40,9 +43,9 @@
*/
public class VertxJUnit4ClassRunner extends JUnit4ClassRunnerAdapter {
- private VertxInternal vertx;
-
- private VerticleManager manager;
+// private VertxInternal vertx;
+//
+ private PlatformManager platformManager;
private VertxConfiguration configuration;
@@ -61,30 +64,32 @@ public VertxJUnit4ClassRunner(Class<?> klass) throws InitializationError {
@Override
protected void beforeAll() {
- VertxBuilder builder = new VertxBuilder();
-
String vertxMods = System.getProperty("vertx.mods", "build/tmp/mods-test");
this.configuration = getDescription().getAnnotation(VertxConfiguration.class);
- if (configuration != null) {
- if (!"".equalsIgnoreCase(configuration.hostname())) {
- builder.setAddress(configuration.hostname());
- }
- if (configuration.port() > 0) {
- builder.setPort(configuration.port());
- }
- if (!"".equalsIgnoreCase(configuration.modsDir())) {
- vertxMods = configuration.modsDir();
- System.setProperty("vertx.mods", vertxMods);
- }
+ if (configuration != null && !"".equalsIgnoreCase(configuration.modsDir())) {
+ vertxMods = configuration.modsDir();
+ System.setProperty("vertx.mods", vertxMods);
+ }
+
+ // sysprops must be set before this is called
+ PlatformManagerFactory factory = new DefaultPlatformManagerFactory();
+
+ if (configuration != null && configuration.port() > 0) {
+ int clusterPort = configuration.port();
+ String clusterHost = configuration.hostname();
+ this.platformManager = factory.createPlatformManager(clusterPort, clusterHost);
+ }
+ else {
+ this.platformManager = factory.createPlatformManager();
}
+
this.modDir = new File(vertxMods);
if (!modDir.exists()) {
modDir.mkdirs();
}
- this.vertx = builder.build();
- this.manager = new VerticleManager(vertx);
+ this.platformManager = factory.createPlatformManager();
}
@Override
@@ -97,8 +102,8 @@ protected void afterCreateTest(Object target) {
if (target instanceof Verticle) {
this.verticle = (Verticle) target;
- verticle.setVertx(vertx);
- verticle.setContainer(new Container(manager));
+ verticle.setVertx(platformManager.getVertx());
+ verticle.setContainer(new Container((PlatformManagerInternal) platformManager));
try {
System.out.println("Starting test verticle!");
verticle.start();
@@ -111,8 +116,8 @@ protected void afterCreateTest(Object target) {
@Override
protected void injectResources(Object target) {
if ((configuration != null && configuration.injectResources()) || configuration == null) {
- InjectionUtils.inject(vertx, target);
- InjectionUtils.inject(manager, target);
+ InjectionUtils.inject(platformManager.getVertx(), target);
+ InjectionUtils.inject(platformManager, target);
}
}
@@ -124,20 +129,20 @@ protected void injectMethodResources(FrameworkMethod method, Object target) {
@Override
protected void beforeClass() {
long timeout = Long.getLong("vertx.test.timeout", 15000L);
- this.classDeployments = JUnitDeploymentUtils.deploy(manager, modDir, getDescription(), timeout);
+ this.classDeployments = JUnitDeploymentUtils.deploy(platformManager, modDir, getDescription(), timeout);
}
@Override
protected void beforeTest(Description description, Object target) {
long timeout = Long.getLong("vertx.test.timeout", 15000L);
- this.methodDeployments = JUnitDeploymentUtils.deploy(manager, modDir, description, timeout);
+ this.methodDeployments = JUnitDeploymentUtils.deploy(platformManager, modDir, description, timeout);
DeploymentRegistry.register(methodDeployments);
}
@Override
protected void afterTest(Description description, Object target) {
if (methodDeployments.size() > 0) {
- DeploymentUtils.undeploy(manager, methodDeployments);
+ DeploymentUtils.undeploy(platformManager, methodDeployments);
}
// avoid leaks
@@ -160,7 +165,7 @@ protected void beforeAfterClass() {
@Override
protected void afterClass() {
if (classDeployments.size() > 0) {
- DeploymentUtils.undeploy(manager, classDeployments);
+ DeploymentUtils.undeploy(platformManager, classDeployments);
}
}
@@ -168,7 +173,7 @@ protected void afterClass() {
protected void afterAll() {
CountDownLatch latch = new CountDownLatch(1);
CountDownLatchDoneHandler<Void> h = new CountDownLatchDoneHandler<>(latch);
- manager.undeployAll(h);
+ platformManager.undeployAll(h);
long timeout = 5L;
if (configuration != null) {
timeout = configuration.shutdownTimeoutSeconds();
View
30 src/main/java/org/vertx/java/test/utils/DeploymentUtils.java
@@ -36,7 +36,7 @@
import org.vertx.java.core.Handler;
import org.vertx.java.core.json.JsonObject;
-import org.vertx.java.deploy.impl.VerticleManager;
+import org.vertx.java.platform.PlatformManager;
import org.vertx.java.test.TestModule;
import org.vertx.java.test.TestVerticle;
@@ -48,7 +48,7 @@
private static final Logger LOG = Logger.getLogger(DeploymentUtils.class.getName());
- public static Map<Annotation, String> deployVerticles(VerticleManager manager, File modDir, Set<TestVerticle> verticles, long timeout) {
+ public static Map<Annotation, String> deployVerticles(PlatformManager platformManager, File modDir, Set<TestVerticle> verticles, long timeout) {
Map<Annotation, String> deployments = new HashMap<>();
if (verticles.size() > 0) {
@@ -56,19 +56,23 @@
Map<TestVerticle, DeploymentHandler> handlers = new HashMap<>();
for (TestVerticle v : verticles) {
- DeploymentHandler handler = new DeploymentHandler(latch);
- handlers.put(v, handler);
+ DeploymentHandler doneHandler = new DeploymentHandler(latch);
JsonObject config = getJsonConfig(v.jsonConfig());
- URL[] urls = findVerticleURLs(v);
+ URL[] classpath = findVerticleURLs(v);
LOG.log(Level.FINE, "deployVerticle(%s)%n", v);
// we are having to set null here which is not that clever
String includes = ("".equals(v.includes())) ? null : v.includes();
try {
- manager.deployVerticle(v.worker(), v.main(), config, urls, v.instances(), modDir, includes, handler);
-// deployments.put(v, handler.getDeploymentID());
+ if (v.worker()) {
+ platformManager.deployWorkerVerticle(v.multiThreaded(), v.main(), config, classpath, v.instances(), includes, doneHandler);
+ }
+ else {
+ platformManager.deployVerticle(v.main(), config, classpath, v.instances(), includes, doneHandler);
+ }
+ handlers.put(v, doneHandler);
} catch (Throwable e) {
e.printStackTrace();
LOG.log(Level.WARNING, String.format("Problem deploying (%s) %n", v), e);
@@ -89,7 +93,7 @@
return deployments;
}
- public static Map<Annotation, String> deployModules(VerticleManager manager, File modDir, Set<TestModule> modules, long timeout) {
+ public static Map<Annotation, String> deployModules(PlatformManager platformManager, File modDir, Set<TestModule> modules, long timeout) {
Map<Annotation, String> deployments = new HashMap<>();
if (modules.size() > 0) {
@@ -104,7 +108,7 @@
LOG.log(Level.FINE, "deployModule(%s)%n", m);
try {
- manager.deployMod(m.name(), config, m.instances(), modDir, handler);
+ platformManager.deployModule(m.name(), config, m.instances(), handler);
} catch (Throwable e) {
e.printStackTrace();
LOG.log(Level.WARNING, String.format("Problem deploying (%s) %n", m), e);
@@ -126,17 +130,16 @@
return deployments;
}
- public static void undeploy(VerticleManager manager, Map<Annotation, String> deployments) {
+ public static void undeploy(PlatformManager container, Map<Annotation, String> deployments) {
final CountDownLatch latch = new CountDownLatch(deployments.size());
- Map<String, Integer> instances = manager.listInstances();
for (Annotation a : deployments.keySet()) {
final String id = deployments.get(a);
- if (id != null && instances.containsKey(id)) {
+ if (id != null) {
try {
- manager.undeploy(id, new Handler<Void>() {
+ container.undeploy(id, new Handler<Void>() {
@Override
public void handle(Void event) {
LOG.log(Level.FINE, String.format("DeploymentUtils undeployed (%s) %n", id));
@@ -159,6 +162,7 @@ public static JsonObject getJsonConfig(String jsonConfig) {
String filename = jsonConfig.replaceFirst("file:", "");
try {
+ // TCCL may be problematic
URL url = Thread.currentThread().getContextClassLoader().getResource(filename);
Path json = Paths.get(url.toURI());
Charset utf8 = Charset.forName("UTF-8");
View
16 src/main/java/org/vertx/java/test/utils/InjectionUtils.java
@@ -15,9 +15,9 @@
*/
package org.vertx.java.test.utils;
-import org.vertx.java.core.impl.VertxInternal;
-import org.vertx.java.deploy.impl.VerticleManager;
-import org.vertx.java.test.VerticleManagerAware;
+import org.vertx.java.core.Vertx;
+import org.vertx.java.platform.PlatformManager;
+import org.vertx.java.test.PlatformManagerAware;
import org.vertx.java.test.VertxAware;
/**
@@ -26,17 +26,17 @@
*/
public class InjectionUtils {
- public static void inject(VertxInternal vertx, Object target) {
+ public static void inject(Vertx vertx, Object target) {
if (target instanceof VertxAware) {
VertxAware aware = (VertxAware) target;
aware.setVertx(vertx);
}
}
- public static void inject(VerticleManager verticleManager, Object target) {
- if (target instanceof VerticleManagerAware) {
- VerticleManagerAware aware = (VerticleManagerAware) target;
- aware.setVerticleManager(verticleManager);
+ public static void inject(PlatformManager platformManager, Object target) {
+ if (target instanceof PlatformManagerAware) {
+ PlatformManagerAware aware = (PlatformManagerAware) target;
+ aware.setPlatformManager(platformManager);
}
}
View
2  src/test/java/org/vertx/java/test/junit/JsonConfigVerticleTest.java
@@ -15,7 +15,7 @@
*/
package org.vertx.java.test.junit;
-import junit.framework.Assert;
+import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
View
21 src/test/java/org/vertx/java/test/junit/ModuleMethodRuleTest.java
@@ -23,9 +23,8 @@
import org.junit.Rule;
import org.junit.Test;
-import org.vertx.java.core.Vertx;
-import org.vertx.java.core.impl.DefaultVertx;
-import org.vertx.java.deploy.impl.VerticleManager;
+import org.vertx.java.platform.PlatformManager;
+import org.vertx.java.platform.impl.DefaultPlatformManagerFactory;
import org.vertx.java.test.TestModule;
import org.vertx.java.test.TestModules;
import org.vertx.java.test.utils.QueueReplyHandler;
@@ -37,19 +36,13 @@
*/
public class ModuleMethodRuleTest {
- private final DefaultVertx vertx = new DefaultVertx();
-
- private final VerticleManager manager = new VerticleManager(vertx);
+ private final PlatformManager manager = new DefaultPlatformManagerFactory().createPlatformManager();
@Rule
public VertxExternalResource rule = new VertxExternalResource(manager);
private long timeout = 10L;
- public Vertx getVertx() {
- return vertx;
- }
-
@Before
public void setup() {
this.timeout = Long.parseLong(System.getProperty("vertx.test.timeout", "15L"));
@@ -67,8 +60,8 @@ public void testModuleEcho1() {
final LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<>();
- getVertx().eventBus().send("vertx.test.mods.echo1", QUESTION, new QueueReplyHandler<String>(queue, timeout));
-
+ manager.getVertx().eventBus().send("vertx.test.mods.echo1", QUESTION, new QueueReplyHandler<String>(queue, timeout));
+
try {
String answer = queue.poll(timeout, TimeUnit.SECONDS);
System.out.println("answer: " + answer);
@@ -89,8 +82,8 @@ public void testModulesEcho2() {
final LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<>();
- getVertx().eventBus().send("vertx.test.mods.echo2", QUESTION, new QueueReplyHandler<String>(queue, timeout));
-
+ manager.getVertx().eventBus().send("vertx.test.mods.echo2", QUESTION, new QueueReplyHandler<String>(queue, timeout));
+
try {
String answer = queue.poll(timeout, TimeUnit.SECONDS);
System.out.println("answer: " + answer);
View
35 src/test/java/org/vertx/java/test/junit/SimpleModuleTest.java
@@ -15,34 +15,35 @@
*/
package org.vertx.java.test.junit;
-import junit.framework.Assert;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.vertx.java.deploy.impl.VerticleManager;
+import org.vertx.java.platform.PlatformManager;
+import org.vertx.java.test.PlatformManagerAware;
import org.vertx.java.test.TestModule;
import org.vertx.java.test.TestModules;
-import org.vertx.java.test.VerticleManagerAware;
+
import org.vertx.java.test.VertxConfiguration;
@RunWith(VertxJUnit4ClassRunner.class)
@VertxConfiguration(modsDir="src/test/mods")
@TestModule(name="test.echo0-v1.0")
-public class SimpleModuleTest implements VerticleManagerAware {
+public class SimpleModuleTest implements PlatformManagerAware {
- private volatile VerticleManager verticleManager;
+ private volatile PlatformManager platformManager;
@Override
- public void setVerticleManager(VerticleManager verticleManager) {
- this.verticleManager = verticleManager;
+ public void setPlatformManager(PlatformManager platformManager) {
+ this.platformManager = platformManager;
}
@Before
@TestModule(name="test.echo0-v1.0")
public void before() {
- System.out.printf("test.before %s %n", verticleManager.listInstances());
+ System.out.printf("test.before %s %n", platformManager.listInstances());
}
@Test
@@ -52,37 +53,37 @@ public void before() {
@TestModule(name="test.echo2-v1.0")
})
public void test1() {
- int instances = verticleManager.listInstances().size();
- System.out.printf("test.test1 %s %n", verticleManager.listInstances());
+ int instances = platformManager.listInstances().size();
+ System.out.printf("test.test1 %s %n", platformManager.listInstances());
Assert.assertEquals(instances, 4);
}
@Test
@TestModule(name="test.echo1-v1.0", instances=3)
public void test2() {
- int instances = verticleManager.listInstances().size();
- System.out.printf("test.test2 %s %n", verticleManager.listInstances());
+ int instances = platformManager.listInstances().size();
+ System.out.printf("test.test2 %s %n", platformManager.listInstances());
Assert.assertEquals(instances, 2);
}
@Test
@TestModule(name="test.echo2-v1.0", jsonConfig="{\"port\":8091}")
public void test3() {
- int instances = verticleManager.listInstances().size();
- System.out.printf("test.test3 %s %n", verticleManager.listInstances());
+ int instances = platformManager.listInstances().size();
+ System.out.printf("test.test3 %s %n", platformManager.listInstances());
Assert.assertEquals(instances, 2);
}
@Test
@TestModule(name="test.echo0-v1.0")
public void test4() {
- int instances = verticleManager.listInstances().size();
- System.out.printf("test.test4 %s %n", verticleManager.listInstances());
+ int instances = platformManager.listInstances().size();
+ System.out.printf("test.test4 %s %n", platformManager.listInstances());
Assert.assertEquals(instances, 2);
}
@After
public void after() {
- System.out.printf("test.after %s %n", verticleManager.listInstances());
+ System.out.printf("test.after %s %n", platformManager.listInstances());
}
}
View
2  src/test/java/org/vertx/java/test/junit/SimpleTestBusModTest.java
@@ -20,7 +20,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.vertx.java.deploy.Verticle;
+import org.vertx.java.platform.Verticle;
import org.vertx.java.test.VertxConfiguration;
@RunWith(VertxJUnit4ClassRunner.class)
View
22 src/test/java/org/vertx/java/test/junit/SimpleVerticleTest.java
@@ -15,31 +15,31 @@
*/
package org.vertx.java.test.junit;
-import junit.framework.Assert;
+import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.vertx.java.deploy.impl.VerticleManager;
+import org.vertx.java.platform.PlatformManager;
+import org.vertx.java.test.PlatformManagerAware;
import org.vertx.java.test.TestVerticle;
import org.vertx.java.test.TestVerticles;
-import org.vertx.java.test.VerticleManagerAware;
import org.vertx.java.test.VertxConfiguration;
@RunWith(VertxJUnit4ClassRunner.class)
@VertxConfiguration
@TestVerticle(main="test_verticle0.js")
-public class SimpleVerticleTest implements VerticleManagerAware {
+public class SimpleVerticleTest implements PlatformManagerAware {
- private volatile VerticleManager verticleManager;
+ private volatile PlatformManager platformManager;
@Override
- public void setVerticleManager(VerticleManager verticleManager) {
- this.verticleManager = verticleManager;
+ public void setPlatformManager(PlatformManager platformManager) {
+ this.platformManager = platformManager;
}
@Test
public void test0() {
- int instances = verticleManager.listInstances().size();
+ int instances = platformManager.listInstances().size();
System.out.println("test.test0 " + instances);
Assert.assertEquals(instances, 1);
}
@@ -51,7 +51,7 @@ public void test0() {
@TestVerticle(main="test_verticle3.js")
})
public void test1() {
- int instances = verticleManager.listInstances().size();
+ int instances = platformManager.listInstances().size();
System.out.println("test.test1 " + instances);
Assert.assertEquals(instances, 4);
}
@@ -59,7 +59,7 @@ public void test1() {
@Test
@TestVerticle(main="test_verticle4.js")
public void test2() {
- int instances = verticleManager.listInstances().size();
+ int instances = platformManager.listInstances().size();
System.out.println("test.test2 " + instances);
Assert.assertEquals(instances, 2);
}
@@ -67,7 +67,7 @@ public void test2() {
@Test
@TestVerticle(main="test_verticle5.js", instances=3)
public void test3() {
- int instances = verticleManager.listInstances().size();
+ int instances = platformManager.listInstances().size();
System.out.println("test.test3 " + instances);
Assert.assertEquals(instances, 2);
}
View
10 src/test/java/org/vertx/java/test/junit/VerticleMethodRuleTest.java
@@ -24,8 +24,8 @@
import org.junit.Test;
import org.vertx.java.core.Vertx;
-import org.vertx.java.core.impl.DefaultVertx;
-import org.vertx.java.deploy.impl.VerticleManager;
+import org.vertx.java.platform.PlatformManager;
+import org.vertx.java.platform.impl.DefaultPlatformManagerFactory;
import org.vertx.java.test.TestVerticle;
import org.vertx.java.test.TestVerticles;
import org.vertx.java.test.utils.QueueReplyHandler;
@@ -36,9 +36,7 @@
*/
public class VerticleMethodRuleTest {
- private final DefaultVertx vertx = new DefaultVertx();
-
- private final VerticleManager manager = new VerticleManager(vertx);
+ private final PlatformManager manager = new DefaultPlatformManagerFactory().createPlatformManager();
@Rule
public VertxExternalResource rule = new VertxExternalResource(manager);
@@ -46,7 +44,7 @@
private long timeout = 10L;
public Vertx getVertx() {
- return vertx;
+ return manager.getVertx();
}
@Before
View
4 src/test/java/org/vertx/java/test/junit/VertxConfigurationTest.java
@@ -15,7 +15,7 @@
*/
package org.vertx.java.test.junit;
-import junit.framework.Assert;
+import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -29,7 +29,7 @@
@Test
public void testModsDirIsSet() {
- Assert.assertEquals("src/test/mods-foo", System.getProperty("vertx.mods"));
+ Assert.assertTrue(System.getProperty("vertx.mods").endsWith("src/test/mods-foo"));
}
}
View
16 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/coffee-script.js
16 additions, 0 deletions not shown
View
20 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/buffer.js
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2011-2012 the original author or authors.
+ *
+ * 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.
+ */
+
+var vertx = vertx || {};
+
+if (!vertx.Buffer)
+ vertx.Buffer = org.vertx.java.core.buffer.Buffer;
View
84 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/deploy.js
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2011-2012 the original author or authors.
+ *
+ * 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.
+ */
+
+var vertx = vertx || {};
+
+if (!vertx.deployVerticle) {
+ (function() {
+
+ var VERTICLE = 0;
+ var WORKER = 1;
+ var MODULE = 2;
+
+ function deploy(deployType, name, config, instances, doneHandler) {
+ if (!instances) instances = 1;
+ if (config) {
+ // Convert to Java Json Object
+ var str = JSON.stringify(config);
+ config = new org.vertx.java.core.json.JsonObject(str);
+ } else {
+ config = null;
+ }
+ if (!doneHandler) doneHandler = null;
+ switch (deployType) {
+ case VERTICLE: {
+ org.vertx.java.platform.impl.RhinoVerticleFactory.container.deployVerticle(name, config, instances, doneHandler);
+ break;
+ }
+ case WORKER: {
+ org.vertx.java.platform.impl.RhinoVerticleFactory.container.deployWorkerVerticle(name, config, instances, doneHandler);
+ break;
+ }
+ case MODULE: {
+ org.vertx.java.platform.impl.RhinoVerticleFactory.container.deployModule(name, config, instances, doneHandler);
+ break;
+ }
+ }
+ }
+
+ vertx.deployVerticle = function(main, config, instances, doneHandler) {
+ deploy(VERTICLE, main, config, instances, doneHandler);
+ }
+
+ vertx.deployWorkerVerticle = function(main, config, instances, doneHandler) {
+ deploy(WORKER, main, config, instances, doneHandler);
+ }
+
+ vertx.deployModule = function(moduleName, config, instances, doneHandler) {
+ deploy(MODULE, moduleName, config, instances, doneHandler);
+ }
+
+ vertx.undeployVerticle = function(name, doneHandler) {
+ if (!doneHandler) doneHandler = null;
+ org.vertx.java.platform.impl.RhinoVerticleFactory.container.undeployVerticle(name, doneHandler);
+ }
+
+ vertx.undeployModule = function(name, doneHandler) {
+ if (!doneHandler) doneHandler = null;
+ org.vertx.java.platform.impl.RhinoVerticleFactory.container.undeployModule(name, doneHandler);
+ }
+
+ vertx.exit = function() {
+ org.vertx.java.platform.impl.RhinoVerticleFactory.container.exit();
+ }
+
+ var j_conf = org.vertx.java.platform.impl.RhinoVerticleFactory.container.getConfig();
+ vertx.config = j_conf == null ? null : JSON.parse(j_conf.encode());
+
+ })();
+}
+
+
View
27 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/env.js
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2011-2012 the original author or authors.
+ *
+ * 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.
+ */
+
+var vertx = vertx || {};
+
+if (!vertx.env) {
+ vertx.env = {};
+ var j_map = org.vertx.java.platform.impl.RhinoVerticleFactory.container.getEnv();
+ var j_iter = j_map.entrySet().iterator();
+ while (j_iter.hasNext()) {
+ var entry = j_iter.next();
+ vertx.env[entry.getKey()] = entry.getValue();
+ }
+}
View
174 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/event_bus.js
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2011-2012 the original author or authors.
+ *
+ * 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.
+ */
+
+var vertx = vertx || {};
+
+if (!vertx.eventBus) {
+ vertx.eventBus = new (function() {
+ var that = this;
+
+ var handlerMap = {};
+
+ var jEventBus = org.vertx.java.platform.impl.RhinoVerticleFactory.vertx.eventBus();
+
+ function checkHandlerParams(address, handler) {
+ if (!address) {
+ throw "address must be specified";
+ }
+ if (!handler) {
+ throw "handler must be specified";
+ }
+ if (typeof address != "string") {
+ throw "address must be a string";
+ }
+ if (typeof handler != "function") {
+ throw "handler must be a function";
+ }
+ }
+
+ var jsonObjectClass = new org.vertx.java.core.json.JsonObject().getClass();
+ var jsonArrayClass = new org.vertx.java.core.json.JsonArray().getClass();
+
+ function wrappedHandler(handler) {
+ return new org.vertx.java.core.Handler({
+ handle: function(jMsg) {
+ var body = jMsg.body;
+
+ if (typeof body === 'object') {
+ var clazz = body.getClass();
+ if (clazz === jsonObjectClass || clazz === jsonArrayClass) {
+ // Convert to JS JSON
+ if (jMsg.body) {
+ body = JSON.parse(jMsg.body.encode());
+ } else {
+ body = undefined;
+ }
+ }
+ }
+
+ handler(body, function(reply, replyHandler) {
+ if (typeof reply === 'undefined') {
+ throw "Reply message must be specified";
+ }
+ reply = convertMessage(reply);
+ if (replyHandler) {
+ var wrapped = wrappedHandler(replyHandler);
+ jMsg.reply(reply, wrapped);
+ } else {
+ jMsg.reply(reply);
+ }
+ })
+ }
+ });
+ }
+
+ function registerHandler(address, handler, localOnly) {
+ checkHandlerParams(address, handler);
+
+ var wrapped = wrappedHandler(handler);
+
+ // This is a bit more complex than it should be because we have to wrap the handler - therefore we
+ // have to keep track of it :(
+ handlerMap[handler] = wrapped;
+
+ if (localOnly) {
+ return jEventBus.registerLocalHandler(address, wrapped);
+ } else {
+ return jEventBus.registerHandler(address, wrapped);
+ }
+ }
+
+ that.registerLocalHandler = function(address, handler) {
+ return registerHandler(address, handler, true);
+ };
+
+ that.registerHandler = function(address, handler) {
+ return registerHandler(address, handler, false);
+ };
+
+ that.unregisterHandler = function(address, handler) {
+ checkHandlerParams(address, handler);
+ var wrapped = handlerMap[handler];
+ if (wrapped) {
+ jEventBus.unregisterHandler(address, wrapped);
+ delete handlerMap[handler];
+ }
+ };
+
+
+ function convertMessage(message) {
+ var msgType = typeof message;
+ switch (msgType) {
+ case 'string':
+ case 'boolean':
+ case 'undefined':
+ break;
+ case 'number':
+ message = new java.lang.Double(message);
+ break;
+ case 'object':
+ // If null then we just wrap it as an empty JSON message
+ // We don't do this if it's a Java class (it has the getClass) method
+ // since it may be a Buffer which we want to let through
+ if (message == null || typeof message.getClass === "undefined") {
+ // Not a Java object - assume JSON message
+ message = new org.vertx.java.core.json.JsonObject(JSON.stringify(message));
+ }
+ break;
+ default:
+ throw 'Invalid type for message: ' + msgType;
+ }
+ return message;
+ }
+
+ /*
+ Message should be a JSON object
+ It should have a property "address"
+ */
+ that.send = function(address, message, replyHandler) {
+ sendOrPub(true, address, message, replyHandler);
+ };
+
+ that.publish = function(address, message) {
+ sendOrPub(false, address, message);
+ };
+
+ function sendOrPub(send, address, message, replyHandler) {
+ if (!address) {
+ throw "address must be specified";
+ }
+ if (typeof address != "string") {
+ throw "address must be a string";
+ }
+ if (replyHandler && typeof replyHandler != "function") {
+ throw "replyHandler must be a function";
+ }
+ message = convertMessage(message);
+ if (send) {
+ if (replyHandler) {
+ var wrapped = wrappedHandler(replyHandler);
+ jEventBus.send(address, message, wrapped);
+ } else {
+ jEventBus.send(address, message);
+ }
+ } else {
+ jEventBus.publish(address, message);
+ }
+ }
+
+ })();
+
+}
View
426 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/filesystem.js
@@ -0,0 +1,426 @@
+/*
+ * Copyright 2011-2012 the original author or authors.
+ *
+ * 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.
+ */
+
+var vertx = vertx || {};
+
+if (!vertx.fileSystem) {
+ vertx.fileSystem = {};
+
+ (function() {
+ var j_fs = org.vertx.java.platform.impl.RhinoVerticleFactory.vertx.fileSystem();
+
+ function wrapHandler(handler) {
+ return function(asyncResult) {
+ if (asyncResult.succeeded()) {
+ handler(null, asyncResult.result);
+ } else {
+ handler(asyncResult.exception, null);
+ }
+ }
+ }
+
+ function wrapPropsHandler(handler) {
+ return function(asyncResult) {
+ if (asyncResult.succeeded()) {
+ var jsProps = convertProps(asyncResult.result);
+ handler(null, jsProps);
+ } else {
+ handler(asyncResult.exception, null);
+ }
+ }
+ }
+
+ function convertProps(j_props) {
+ var jsProps = {
+ creationTime: j_props.creationTime.getTime(),
+ lastAccessTime: j_props.lastAccessTime.getTime(),
+ lastModifiedTime: j_props.lastModifiedTime.getTime(),
+ isDirectory: j_props.isDirectory,
+ isOther: j_props.isOther,
+ isRegularFile: j_props.isRegularFile,
+ isSymbolicLink: j_props.isSymbolicLink,
+ size: j_props.size
+ }
+ return jsProps;
+ }
+
+ vertx.fileSystem.copy = function(from, to, arg2, arg3) {
+ var handler;
+ var recursive;
+ if (arguments.length === 4) {
+ handler = arg3;
+ recursive = arg2;
+ } else {
+ handler = arg2;
+ recursive = false;
+ }
+ j_fs.copy(from, to, recursive, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.copySync = function(from, to, recursive) {
+ if (!recursive) recursive = false;
+ j_fs.copySync(from, to, recursive);
+ }
+
+ vertx.fileSystem.move = function(from, to, handler) {
+ j_fs.move(from, to, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.moveSync = function(from, to) {
+ j_fs.moveSync(from, to);
+ }
+
+ vertx.fileSystem.truncate = function(path, len, handler) {
+ j_fs.truncate(path, len, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.truncateSync = function(path, len) {
+ j_fs.truncateSync(path, len);
+ }
+
+ vertx.fileSystem.chmod = function(path, perms, arg2, arg3) {
+ var handler;
+ var dirPerms;
+ if (arguments.length === 4) {
+ handler = arg3;
+ dirPerms = arg2;
+ } else {
+ handler = arg2;
+ dirPerms = null;
+ }
+ j_fs.chmod(path, perms, dirPerms, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.chmodSync = function(path, perms, dirPerms) {
+ if (!dirPerms) dirPerms = null;
+ j_fs.chmodSync(path, perms, dirPerms);
+ }
+
+ vertx.fileSystem.props = function(path, handler) {
+ j_fs.props(path, wrapPropsHandler(handler));
+ }
+
+ vertx.fileSystem.propsSync = function(path) {
+ var j_props = j_fs.propsSync(path);
+ return convertProps(j_props);
+ }
+
+ vertx.fileSystem.lprops = function(path, handler) {
+ j_fs.lprops(path, wrapPropsHandler(handler));
+ }
+
+ vertx.fileSystem.lpropsSync = function(path) {
+ var j_props = j_fs.lpropsSync(path);
+ return convertProps(j_props);
+ }
+
+ vertx.fileSystem.link = function(link, existing, handler) {
+ j_fs.link(link, existing, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.linkSync = function(link, existing) {
+ j_fs.linkSync(link, existing);
+ }
+
+ vertx.fileSystem.symlink = function(link, existing, handler) {
+ j_fs.symlink(link, existing, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.symlinkSync = function(link, existing) {
+ j_fs.symlinkSync(link, existing);
+ }
+
+ vertx.fileSystem.unlink = function(link, handler) {
+ j_fs.unlink(link, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.unlinkSync = function(link) {
+ j_fs.unlinkSync(link);
+ }
+
+ vertx.fileSystem.readSymlink = function(link, handler) {
+ j_fs.readSymlink(link, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.readSymlinkSync = function(link, handler) {
+ return j_fs.readSymlinkSync(link);
+ }
+
+ vertx.fileSystem.delete = function(path, arg1, arg2) {
+ var handler;
+ var recursive;
+ if (arguments.length === 3) {
+ handler = arg2;
+ recursive = arg1;
+ } else {
+ handler = arg1;
+ recursive = false;
+ }
+ j_fs.delete(path, recursive, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.deleteSync = function(path, recursive) {
+ if (!recursive) recursive = false;
+ j_fs.deleteSync(path, recursive);
+ }
+
+ vertx.fileSystem.mkDir = function(path, arg1, arg2, arg3) {
+ var createParents;
+ var perms;
+ var handler;
+ switch (arguments.length) {
+ case 2:
+ createParents = false;
+ perms = null;
+ handler = arg1;
+ break;
+ case 3:
+ createParents = arg2;
+ perms = null;
+ handler = arg2;
+ break;
+ case 4:
+ createParents = arg1;
+ perms = arg2;
+ handler = arg3;
+ break;
+ default:
+ throw 'Invalid number of arguments';
+ }
+ j_fs.mkdir(path, perms, createParents, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.mkDirSync = function(path, arg1, arg2) {
+ var createParents;
+ var perms;
+ switch (arguments.length) {
+ case 2:
+ createParents = false;
+ perms = null;
+ break;
+ case 2:
+ createParents = arg1;
+ perms = null;
+ break;
+ case 3:
+ createParents = arg1;
+ perms = arg2;
+ break;
+ default:
+ throw 'Invalid number of arguments';
+ }
+ j_fs.mkdirSync(path, perms, createParents);
+ }
+
+ vertx.fileSystem.readDir = function(path, arg1, arg2) {
+ var filter;
+ var handler;
+ if (arguments.length === 3) {
+ handler = arg2;
+ filter = arg1;
+ } else {
+ handler = arg1;
+ filter = null;
+ }
+ j_fs.readDir(path, filter, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.readDirSync = function(path, filter) {
+ if (!filter) filter = false;
+ return j_fs.readDirSync(path, filter);
+ }
+
+ vertx.fileSystem.readFile = function(path, handler) {
+ j_fs.readFile(path, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.readFileSync = function(path) {
+ return j_fs.readFileSync(path);
+ }
+
+ vertx.fileSystem.writeFile = function(path, data, handler) {
+ if (typeof data === 'string') {
+ data = new org.vertx.java.core.buffer.Buffer(data);
+ }
+ j_fs.writeFile(path, data, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.writeFileSync = function(path, data) {
+ if (typeof data === 'string') {
+ data = new org.vertx.java.core.buffer.Buffer(data);
+ }
+ j_fs.writeFileSync(path, data);
+ }
+
+ vertx.fileSystem.OPEN_READ = 1;
+ vertx.fileSystem.OPEN_WRITE = 2;
+ vertx.fileSystem.CREATE_NEW = 4;
+
+ vertx.fileSystem.openSync = function(path, arg1, arg2, arg3) {
+
+ // TODO combine this code with the similar code in open
+ var openFlags;
+ var flush;
+ var perms;
+ var handler;
+ switch (arguments.length) {
+ case 1:
+ openFlags = vertx.fileSystem.OPEN_READ | vertx.fileSystem.OPEN_WRITE
+ | vertx.fileSystem.CREATE_NEW;
+ flush = false;
+ perms = null;
+ break;
+ case 2:
+ openFlags = arg1;
+ flush = false;
+ perms = null;
+ break;
+ case 3:
+ openFlags = arg1;
+ flush = arg2;
+ perms = null;
+ break;
+ case 4:
+ openFlags = arg1;
+ flush = arg2;
+ perms = arg3;
+ break;
+ default:
+ throw 'Invalid number of arguments';
+ }
+
+ var read = (openFlags & vertx.fileSystem.OPEN_READ) == vertx.fileSystem.OPEN_READ;
+ var write = (openFlags & vertx.fileSystem.OPEN_WRITE) == vertx.fileSystem.OPEN_WRITE;
+ var createNew = (openFlags & vertx.fileSystem.CREATE_NEW) == vertx.fileSystem.CREATE_NEW;
+
+ var asyncFile = j_fs.openSync(path, perms, read, write, createNew, flush);
+
+ return wrapAsyncFile(asyncFile);
+ }
+
+ vertx.fileSystem.open = function(path, arg1, arg2, arg3, arg4) {
+
+ var openFlags;
+ var flush;
+ var perms;
+ var handler;
+ switch (arguments.length) {
+ case 2:
+ openFlags = vertx.fileSystem.OPEN_READ | vertx.fileSystem.OPEN_WRITE
+ | vertx.fileSystem.CREATE_NEW;
+ flush = false;
+ perms = null;
+ handler = arg1;
+ break;
+ case 3:
+ openFlags = arg1;
+ flush = false;
+ perms = null;
+ handler = arg2;
+ break;
+ case 4:
+ openFlags = arg1;
+ flush = arg2;
+ perms = null;
+ handler = arg3;
+ break;
+ case 5:
+ openFlags = arg1;
+ flush = arg2;
+ perms = arg3;
+ handler = arg4;
+ break;
+ default:
+ throw 'Invalid number of arguments';
+ }
+
+ var read = (openFlags & vertx.fileSystem.OPEN_READ) == vertx.fileSystem.OPEN_READ;
+ var write = (openFlags & vertx.fileSystem.OPEN_WRITE) == vertx.fileSystem.OPEN_WRITE;
+ var createNew = (openFlags & vertx.fileSystem.CREATE_NEW) == vertx.fileSystem.CREATE_NEW;
+
+ j_fs.open(path, perms, read, write, createNew, flush, function(asyncResult) {
+ if (asyncResult.succeeded()) {
+ var j_af = asyncResult.result;
+ var wrapped = wrapAsyncFile(j_af);
+ handler(null, wrapped);
+ } else {
+ handler(asyncResult.exception, null);
+ }
+ });
+ }
+
+ function wrapAsyncFile(j_af) {
+ return {
+ close: function(handler) {
+ if (handler) {
+ j_af.close(wrapHandler(handler))
+ } else {
+ j_af.close();
+ }
+ },
+
+ write: function(buffer, position, handler) {
+ j_af.write(buffer, position, wrapHandler(handler));
+ },
+
+ read: function(buffer, offset, position, length, handler) {
+ j_af.read(buffer, offset, position, length, wrapHandler(handler));
+ },
+
+ getWriteStream: function() {
+ return j_af.getWriteStream();
+ },
+
+ getReadStream: function() {
+ return j_af.getReadStream();
+ },
+
+ flush: function(handler) {
+ if (handler) {
+ j_af.flush(wrapHandler(handler));
+ } else {
+ j_af.flush();
+ }
+ }
+ }
+ }
+
+ vertx.fileSystem.createFile = function(path, handler) {
+ j_fs.createFile(path, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.createFileSync = function(path) {
+ j_fs.createFileSync(path);
+ }
+
+ vertx.fileSystem.exists = function(path, handler) {
+ j_fs.exists(path, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.existsSync = function(path) {
+ return j_fs.existsSync(path);
+ }
+
+ vertx.fileSystem.fsProps = function(path, handler) {
+ j_fs.fsProps(path, wrapHandler(handler));
+ }
+
+ vertx.fileSystem.fsPropsSync = function(path) {
+ return j_fs.fsPropsSync(path);
+ }
+
+ })();
+}
View
679 src/test/mods/maven:io.vertx:lang-rhino:1.0.0-SNAPSHOT/core/http.js
@@ -0,0 +1,679 @@
+/*
+ * Copyright 2011-2012 the original author or authors.
+ *
+ * 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.
+ */
+
+var vertx = vertx || {};
+
+if (!vertx.createHttpServer) {
+
+ (function() {
+
+ function convertMap(j_map) {
+ var map = {};
+ var j_iter = j_map.entrySet().iterator();
+ while (j_iter.hasNext()) {
+ var entry = j_iter.next();
+ map[entry.getKey()] = entry.getValue();
+ }
+ return map;
+ }
+
+ function wrappedRequestHandler(handler) {
+ return function(j_req) {
+
+ //We need to add some functions to the request and the response
+
+ var reqHeaders = null;
+ var reqParams = null;
+
+ var req = {
+
+ headers: function() {
+ if (!reqHeaders) {
+ reqHeaders = convertMap(j_req.headers());
+ }
+ return reqHeaders;
+ },
+ params: function() {
+ if (!reqParams) {
+ reqParams = convertMap(j_req.params());
+ }
+ return reqParams;
+ }
+ };
+
+ var j_resp = j_req.response;
+
+ var respHeaders = null;
+ var headersWritten = false;
+
+ function writeHeaders() {
+ if (respHeaders && !headersWritten) {
+ var j_hdrs = j_resp.headers();
+ for (var k in respHeaders) {
+ j_hdrs.put(k, respHeaders[k])
+ }
+ headersWritten = true;
+ }
+ }
+
+ var respTrailers = null;
+ var trailersWritten = false;
+
+ function writeTrailers() {
+ if (respTrailers && !trailersWritten) {
+ var j_trailers = j_resp.trailers();
+ for (var k in respTrailers) {
+ j_trailers.put(k, respTrailers[k])
+ }
+ trailersWritten = true;
+ }
+ }
+
+ var resp = {
+ headers: function() {
+ if (!respHeaders) {
+ respHeaders = {};
+ }
+ return respHeaders;
+ },
+ putAllHeaders: function(other) {
+ var hdrs = resp.headers();
+ for (var k in other) {
+ hdrs[k] = other[k];
+ }
+ },
+ trailers: function() {
+ if (!respTrailers) {
+ respTrailers = {};
+ }
+ return respTrailers;
+ },
+ putAllTrailers: function(other) {
+ var trlrs = resp.trailers();
+ for (var k in other) {
+ trlrs[k] = other[k];
+ }
+ },
+ write: function(arg0, arg1, arg2) {
+ writeHeaders();
+ if (arg1) {
+ if (arg2) {
+ j_resp.write(arg0, arg1, arg2);
+ } else {
+ j_resp.write(arg0, arg1);
+ }
+ } else {
+ j_resp.write(arg0);
+ }
+ return resp;
+ },
+ writeBuffer: function(buffer) {
+ writeHeaders();
+ j_resp.writeBuffer(buffer);
+ },
+ continueHandler: function(handler) {
+ j_resp.continueHandler(handler);
+ },
+ sendHead: function() {
+ writeHeaders();
+ j_resp.sendHead();
+ return resp;
+ },
+ end: function(arg0, arg1) {
+ writeHeaders();
+ writeTrailers();
+ if (arg0) {
+ if (arg1) {
+ j_resp.end(arg0, arg1);
+ } else {
+ j_resp.end(arg0);
+ }
+ } else {
+ j_resp.end();
+ }
+ }
+ }
+
+ req.response = resp;
+ req.__proto__ = j_req;
+ resp.__proto__ = j_req.response;
+
+
+ handler(req);
+ }
+ }
+
+ vertx.createHttpServer = function() {
+
+ var j_server = org.vertx.java.platform.impl.RhinoVerticleFactory.vertx.createHttpServer();
+
+ var that = {};
+
+ that.requestHandler = function(handler) {
+
+ if (handler) {
+
+ if (typeof handler === 'function') {
+ handler = wrappedRequestHandler(handler);
+ } else {
+ // It's a route matcher
+ handler = handler._to_java_handler();
+ }
+
+ j_server.requestHandler(handler);
+ }
+ return that;
+ };
+
+ that.websocketHandler = function(handler) {
+ if (handler) {
+ j_server.websocketHandler(handler);
+ }
+ return that;
+ };
+
+ that.close = function(handler) {
+ if (handler) {
+ j_server.close(handler);
+ } else {
+ j_server.close();
+ }
+ };
+
+ that.listen = function(port, host) {
+ if (host) {
+ j_server.listen(port, host);
+ } else {
+ j_server.listen(port);
+ }
+ return that;
+ }
+
+ that.setSSL = function(ssl) {
+ j_server.setSSL(ssl);
+ return that;
+ }
+
+ that.setKeyStorePath = function(path) {
+ j_server.setKeyStorePath(path);
+ return that;
+ }
+
+ that.setKeyStorePassword = function(password) {
+ j_server.setKeyStorePassword(password);
+ return that;
+ }
+
+ that.setTrustStorePath = function(path) {
+ j_server.setTrustStorePath(path);
+ return that;
+ }
+
+ that.setTrustStorePassword = function(password) {
+ j_server.setTrustStorePassword(password);
+ return that;
+ }
+
+ that.setClientAuthRequired = function(required) {
+ j_server.setClientAuthRequired(required);
+ return that;
+ }
+
+ that.setTCPNoDelay = function(tcpNoDelay) {
+ j_server.setTCPNoDelay(tcpNoDelay);
+ return that;
+ }
+
+ that.setSendBufferSize = function(size) {
+ j_server.setSendBufferSize(size);
+ return that;
+ }
+
+ that.setReceiveBufferSize = function(size) {
+ j_server.setReceiveBufferSize(size);
+ return that;
+ }
+
+ that.setTCPKeepAlive = function(keepAlive) {
+ j_server.setTCPKeepAlive(keepAlive);
+ return that;
+ }
+
+ that.setReuseAddress = function(reuse) {
+ j_server.setReuseAddress(reuse);
+ return that;
+ }
+
+ that.setSoLinger = function(linger) {
+ j_server.setSoLinger(linger);
+ return that;
+ }
+
+ that.setTrafficClass = function(klazz) {
+ j_server.setTrafficClass(klazz);
+ return that;
+ }
+
+ that.setClientAuthRequired = function(required) {
+ j_server.setClientAuthRequired(required);
+ return that;
+ }
+
+ that.isTCPNoDelay = function() {
+ return j_server.isTCPNoDelay();
+ }
+
+ that.getSendBufferSize = function() {
+ return j_server.getSendBufferSize();
+ }
+
+ that.getReceiveBufferSize = function() {
+ return j_server.getReceiveBufferSize();
+ }
+
+ that.isSoLinger = function() {
+ return j_server.isSoLinger();
+ }
+
+ that.getTrafficClass = function() {
+ return j_server.getTrafficClass();
+ }
+
+ that.isSSL = function() {
+ return j_server.isSSL();
+ }
+
+ that._to_java_server = function() {
+ return j_server;
+ }
+
+ return that;
+ }
+
+ vertx.createHttpClient = function() {
+ var j_client = org.vertx.java.platform.impl.RhinoVerticleFactory.vertx.createHttpClient();
+
+ function wrapResponseHandler(handler) {
+ var wrapperHandler = function(j_resp) {
+
+ var respHeaders = null;
+ var respTrailers = null;
+
+ var resp = {
+
+ headers: function() {
+ if (!respHeaders) {
+ respHeaders = convertMap(j_resp.headers());
+ }
+ return respHeaders;
+ },
+ trailers: function() {
+ if (!respTrailers) {
+ respTrailers = convertMap(j_resp.trailers());
+ }
+ return respTrailers;
+ }
+ };
+
+ resp.__proto__ = j_resp;
+
+ handler(resp);
+ }
+ return wrapperHandler;
+ }
+
+ function wrapRequest(j_req) {
+
+ var reqHeaders = null;
+
+ var headersWritten = false;
+
+ function writeHeaders() {
+ if (reqHeaders && !headersWritten) {
+ var j_hdrs = j_req.headers();
+ for (var k in reqHeaders) {
+ j_hdrs.put(k, reqHeaders[k])
+ }
+ headersWritten = true;
+ }
+ }
+
+ var wrapped = {
+ headers: function() {
+ if (!reqHeaders) {
+ reqHeaders = convertMap(j_req.headers());
+ }
+ return reqHeaders;
+ },
+ putAllHeaders: function(other) {
+ var hdrs = wrapped.headers();
+ for (var k in other) {
+ hdrs[k] = other[k];
+ }
+ },
+ write: function(arg0, arg1, arg2) {
+ writeHeaders();
+ if (arg1) {
+ if (arg2) {
+ j_req.write(arg0, arg1, arg2);
+ } else {
+ j_req.write(arg0, arg1);
+ }
+ } else {
+ j_req.write(arg0);
+ }
+ return wrapped;
+ },
+ writeBuffer: function(buff) {
+ writeHeaders();
+ j_req.writeBuffer(buff);
+ },
+ continueHandler: function(handler) {
+ j_req.continueHandler(handler);
+ },
+ sendHead: function() {
+ writeHeaders();
+ j_req.sendHead();
+ return wrapped;
+ },
+ end: function(arg0, arg1) {
+ writeHeaders();
+ if (arg0) {
+ if (arg1) {
+ j_req.end(arg0, arg1);
+ } else {
+ j_req.end(arg0);
+ }
+ } else {
+ j_req.end();
+ }
+ }
+ };
+ wrapped.__proto__ = j_req;
+ return wrapped;
+ }
+
+ var that = {};
+
+ that.exceptionHandler = function(handler) {
+ j_client.exceptionHandler(handler);
+ return that;
+ }
+
+ that.setMaxPoolSize = function(size) {
+ j_client.setMaxPoolSize(size);
+ return that;
+ }
+
+ that.getMaxPoolSize = function() {
+ return j_client.getMaxPoolSize();
+ }
+
+ that.setKeepAlive = function(keepAlive) {
+ j_client.setKeepAlive(keepAlive);
+ return that;
+ }
+
+ that.setSSL = function(ssl) {
+ j_client.setSSL(ssl);
+ return that;
+ }
+
+ that.setKeyStorePath = function(path) {
+ j_client.setKeyStorePath(path);
+ return that;
+ }
+
+ that.setKeyStorePassword = function(password) {
+ j_client.setKeyStorePassword(password);
+ return that;
+ }
+
+ that.setTrustStorePath = function(path) {
+ j_client.setTrustStorePath(path);
+ return that;
+ }
+
+ that.setTrustStorePassword = function(password) {
+ j_client.setTrustStorePassword(password);
+ return that;
+ }
+
+ that.setTrustAll = function(trustAll) {
+ j_client.setTrustAll(trustAll);
+ return that;
+ }
+
+ that.setPort = function(port) {
+ j_client.setPort(port);
+ return that;
+ }
+
+ that.setHost = function(host) {
+ j_client.setHost(host);
+ return that;
+ }
+
+ that.connectWebsocket = function(uri, handler) {
+ j_client.connectWebsocket(uri, handler);
+ }
+
+ that.getNow = function(uri, handler) {
+ return wrapRequest(j_client.getNow(uri, wrapResponseHandler(handler)));
+ }
+
+ that.options = function(uri, handler) {
+ return wrapRequest(j_client.options(uri, wrapResponseHandler(handler)));
+ }
+
+ that.get = function(uri, handler) {
+ return wrapRequest(j_client.get(uri, wrapResponseHandler(handler)));
+ }
+
+ that.head = function(uri, handler) {
+ return wrapRequest(j_client.head(uri, wrapResponseHandler(handler)));
+ }
+
+ that.post = function(uri, handler) {
+ return wrapRequest(j_client.post(uri, wrapResponseHandler(handler)));
+ }
+
+ that.put = function(uri, handler) {
+ return wrapRequest(j_client.put(uri, wrapResponseHandler(handler)));
+ }
+
+ that.delete = function(uri, handler) {
+ return wrapRequest(j_client.delete(uri, wrapResponseHandler(handler)));
+ }
+
+ that.trace = function(uri, handler) {
+ return wrapRequest(j_client.trace(uri, wrapResponseHandler(handler)));
+ }
+
+ that.connect = function(uri, handler) {
+ return wrapRequest(j_client.connect(uri, wrapResponseHandler(handler)));
+ }
+
+ that.patch = function(uri, handler) {
+ return wrapRequest(j_client.patch(uri, wrapResponseHandler(handler)));
+ }
+
+ that.request = function(method, uri, handler) {
+ return wrapRequest(j_client.request(method, uri, wrapResponseHandler(handler)));
+ }
+
+ that.close = function() {
+ j_client.close();
+ }
+
+ that.setTCPNoDelay = function(tcpNoDelay) {
+ j_client.setTCPNoDelay(tcpNoDelay);
+ return that;
+ }
+
+ that.setSendBufferSize = function(size) {
+ j_client.setSendBufferSize(size);
+ return that;
+ }
+
+ that.setReceiveBufferSize = function(size) {
+ j_client.setReceiveBufferSize(size);
+ return that;
+ }
+
+ that.setTCPKeepAlive = function(keepAlive) {
+ j_client.setTCPKeepAlive(keepAlive);
+ return that;
+ }
+
+ that.setReuseAddress = function(reuse) {
+ j_client.setReuseAddress(reuse);
+ return that;
+ }
+
+ that.setSoLinger = function(linger) {
+ j_client.setSoLinger(linger);
+ return that;
+ }
+
+ that.setTrafficClass = function(klazz) {
+ j_client.setTrafficClass(klazz);
+ return that;
+ }
+
+ that.isTCPNoDelay = function() {
+ return j_client.isTCPNoDelay();
+ }
+
+ that.getSendBufferSize = function() {
+ return j_client.getSendBufferSize();
+ }
+
+ that.getReceiveBufferSize = function() {
+ return j_client.getReceiveBufferSize();
+ }
+
+ that.isSoLinger = function() {
+ return j_client.isSoLinger();
+ }
+
+ that.getTrafficClass = function() {
+ return j_client.getTrafficClass();
+ }
+
+ that.isSSL = function() {
+ return j_client.isSSL();
+ }
+
+ return that;
+
+ }
+
+ vertx.RouteMatcher = function() {
+
+ var j_rm = new org.vertx.java.core.http.RouteMatcher();
+
+ this.get = function(pattern, handler) {
+ j_rm.get(pattern, wrappedRequestHandler(handler));
+ }
+
+ this.put = function(pattern, handler) {
+ j_rm.put(pattern, wrappedRequestHandler(handler));
+ }
+
+ this.post = function(pattern, handler) {
+ j_rm.post(pattern, wrappedRequestHandler(handler));
+ }
+
+ this.delete = function(pattern, handler) {
+ j_rm.delete(pattern, wrappedRequestHandler(handler));
+ }
+
+ this.options = function(pattern, handler) {
+ j_rm.options(pattern, wrappedRequestHandler(handler));
+ }
+
+ this.head = function(pattern, handler) {
+ j_rm.head(pattern, wrappedRequestHandler(handler));
+ }
+
+ this.trace = function(pattern, handler) {
+ j_rm.trace(pattern, wrappedRequestHandler(handler));
+ }
+
+ this.connect = function(pattern, handler) {
+ j_rm.connect(pattern, wrappedRequestHandler(handler));
+ }
+
+ this.patch = function(pattern, handler) {
+ j_rm.patch(pattern, wrappedRequestHandler(handler));
+ }
+
+ this.all = function(pattern, handler) {
+ j_rm.all(pattern, wrappedRequestHandler(handler));
+ }
+
+ this.getWithRegEx = function(pattern, handler) {
+ j_rm.getWithRegEx(pattern, wrappedRequestHandler(handler));
+ }
+
+ this.putWithRegEx = function(pattern, handler) {
+ j_rm.putWithRegEx(pattern, wrappedRequestHandler(handler));