Last active
August 29, 2015 14:04
-
-
Save rodrigoSaladoAnaya/fd7021d15fc63bca0152 to your computer and use it in GitHub Desktop.
Como hacer una prueba de integración a un verticle Vert.x
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
package corg.grails.gertx | |
import org.junit.Ignore | |
import spock.lang.Shared | |
import spock.lang.Specification | |
import org.vertx.java.core.AsyncResult | |
import org.vertx.java.core.Handler | |
import org.vertx.java.core.eventbus.EventBus | |
import org.vertx.java.core.eventbus.Message | |
import org.vertx.java.core.json.JsonObject | |
import org.vertx.java.platform.PlatformLocator | |
class GertxSpecification extends Specification { | |
@Shared def platformManager | |
@Shared def vertx | |
@Shared EventBus eventBus | |
@Shared URL[] classpath = new URL[1] | |
@Override | |
def setupSpec() { | |
platformManager = PlatformLocator.factory.createPlatformManager() | |
vertx = platformManager.vertx() | |
eventBus = vertx.eventBus() | |
def classPathUrl = new File('./grails-app/gertx').toURI().toURL() | |
classpath[0] = classPathUrl | |
} | |
@Ignore | |
void deployVerticle(vertilceName) { | |
def wait = true | |
platformManager.deployVerticle( | |
vertilceName, | |
null, | |
classpath, | |
1, | |
null, | |
new Handler<AsyncResult<String>>() { | |
void handle(AsyncResult<String> asyncResult) { | |
if (asyncResult.succeeded()) { | |
println "'${vertilceName}' is charged." | |
} else { | |
println "Unable to charge '${vertilceName}': ${asyncResult.cause()}." | |
} | |
wait = false | |
} | |
} | |
) | |
while (wait) { | |
sleep(1000) | |
} | |
} | |
@Ignore | |
def sendAgrs(address, agrs) { | |
def wait = true | |
def body = null | |
eventBus.sendWithTimeout(address, agrs, 15000, new Handler<AsyncResult<Message<JsonObject>>>() { | |
void handle(AsyncResult<Message<JsonObject>> result) { | |
if (result.succeeded()) { | |
body = result.result().body() | |
} else { | |
println "Error '${address}': ${result.cause()}" | |
} | |
wait = false | |
} | |
}) | |
while (wait) { | |
sleep(1000) | |
} | |
return body | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment