Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/main/java/io/reactiverse/voltdbclient/VoltClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import org.voltdb.client.ClientResponse;

/**
* VoltDb client that can connect to one or more nodes in a volt cluster.
Expand Down Expand Up @@ -51,7 +52,6 @@ static VoltClient create(Vertx vertx, VoltClientOptions options) {
return new VoltClientImpl(vertx, options);
}


/**
* Create a connection to a VoltDB node and add it to the set of connections.
*
Expand All @@ -61,6 +61,18 @@ static VoltClient create(Vertx vertx, VoltClientOptions options) {
@Fluent
VoltClient createConnection(Handler<AsyncResult<Void>> resultHandler);

/**
* Invoke a replicated procedure.
*
* @param procName class name (not qualified by package) of the procedure to execute.
* @param parameters vararg list of procedure's parameter values.
* @param resultHandler holds the result of stored procedure invokation.
* @return reference to this, for fluency.
*/
@Fluent
VoltClient callProcedure(String procName, Object[] parameters, Handler<AsyncResult<ClientResponse>> resultHandler);


/**
* Close the client and release its resources.
*
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/io/reactiverse/voltdbclient/impl/VoltClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@

import io.reactiverse.voltdbclient.VoltClient;
import io.reactiverse.voltdbclient.VoltClientOptions;
import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.*;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import org.voltdb.client.Client;
import org.voltdb.client.ClientConfig;
import org.voltdb.client.ClientFactory;
import org.voltdb.client.ClientStatusListenerExt;
import org.voltdb.client.*;

import java.io.IOException;
import java.net.UnknownHostException;
Expand Down Expand Up @@ -72,6 +66,23 @@ public VoltClient createConnection(Handler<AsyncResult<Void>> resultHandler) {
return this;
}

@Override
public VoltClient callProcedure(String procName, Object[] parameters, Handler<AsyncResult<ClientResponse>> resultHandler) {
try {
boolean queued = client.callProcedure(clientResponse -> {
resultHandler.handle(Future.succeededFuture(clientResponse));
}, procName, parameters);

if (!queued) {
// to be tested.
}
} catch (IOException e) {
log.error("Error occurred while calling procedure: " + procName, e);
resultHandler.handle(Future.failedFuture(e));
}
return this;
}

@Override
public void close(Handler<AsyncResult<Void>> resultHandler) {
context.executeBlocking(event -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
import io.reactiverse.voltdbclient.VoltClient;
import io.reactiverse.voltdbclient.VoltClientOptions;
import io.vertx.core.Vertx;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.RunTestOnContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.junit.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertTrue;

/**
* Tests the {@link io.reactiverse.voltdbclient.VoltClient}
*
Expand Down Expand Up @@ -67,16 +70,16 @@ public void setUp(TestContext context) {
public void testCreateConnection(TestContext context) {
Async async = context.async();
voltClient.createConnection(event -> {
Assert.assertTrue(event.succeeded());
assertTrue(event.succeeded());
async.complete();
});
}


@After
public void tearDown(TestContext context) {
voltClient.close(event -> {
vertx.close(context.asyncAssertSuccess());
});

}
}