Skip to content

Commit

Permalink
client tests, client publish scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
scivey committed Oct 9, 2015
1 parent b41e402 commit 8b25508
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 16 deletions.
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ thrift-py:
mv ./clients/python/client/relevanced_client/gen-py ./clients/python/client/relevanced_client/gen_py

thrift-node:
thrift-0.9 --gen js:node -o ./clients/nodejs/client/relevancedClient src/RelevancedProtocol.thrift
rm -rf ./clients/nodejs/client/gen-nodejs
mkdir -p build/thrift
thrift-0.9 --gen js:node -o build/thrift src/RelevancedProtocol.thrift
mv ./build/thrift/gen-nodejs ./clients/nodejs/client/

thrift-java:
rm -rf clients/java/client/src/main/java/org/relevanced/client/gen_thrift_protocol
Expand Down Expand Up @@ -87,3 +90,16 @@ deb-package-remote:

docker-sh:
sudo docker run --rm -t -i relevanced/relevanced /bin/bash

smoketest-node:
node ./clients/nodejs/client/test/functionalSmoketest.js

smoketest-java:
cd ./clients/java/client && sbt run

publish-node:
cd ./clients/nodejs/client/ && npm publish

publish-python:
cd ./clients/python/client && python register -r pypi
cd ./clients/python/client && python sdist upload -r pypi
3 changes: 2 additions & 1 deletion clients/java/client/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ mainClass in (Compile, run) := Some("org.relevanced.client.Main")

// library dependencies. (org name) % (project name) % (version)
libraryDependencies ++= Seq(
"org.apache.thrift" % "libthrift" % "0.9.2"
"org.apache.thrift" % "libthrift" % "0.9.2",
"org.slf4j" % "slf4j-jdk14" % "1.7.12"
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
package org.relevanced.client;

import java.lang.System;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.apache.thrift.TException;

public class Main {
public static void main(String [] args) {
System.out.println("start");
RelevancedBlockingClient client = new RelevancedBlockingClient("localhost", 8097);
try {
RelevancedBlockingClient client = new RelevancedBlockingClient("localhost", 8097);
client.connect();
List<String> centroids = client.listAllCentroids();
System.out.println("number of centroids: " + centroids.size());
System.out.println(centroids);
List<String> documents = client.listAllDocuments();
System.out.println("number of documents: " + documents.size());
int docIndex = new Random().nextInt(documents.size());
String docId = documents.get(docIndex);
String centroidId = centroids.get(0);
System.out.println("comparing " + docId + " against " + centroidId + "...");
double similarity = client.getDocumentSimilarity(centroidId, docId);
System.out.println("result: " + similarity);

} catch (TException err) {
err.printStackTrace();
}
System.out.println("end");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@
import org.relevanced.client.gen_thrift_protocol.Status;
import org.relevanced.client.gen_thrift_protocol.StatusCode;

import org.relevanced.client.exceptions.CentroidAlreadyExists;
import org.relevanced.client.exceptions.CentroidDoesNotExist;
import org.relevanced.client.exceptions.ConnectionError;
import org.relevanced.client.exceptions.DocumentAlreadyExists;
import org.relevanced.client.exceptions.DocumentDoesNotExist;
import org.relevanced.client.exceptions.RelevancedException;
import org.relevanced.client.exceptions.UnknownException;

public class RelevancedBlockingClient {
public Relevanced.Client thriftClient_;
public TTransport thriftTransport_;
Expand All @@ -38,13 +30,17 @@ public class RelevancedBlockingClient {
public RelevancedBlockingClient(String host, int port) {
hostname_ = host;
portNum_ = port;
}

public void connect() throws TException {
try {
thriftTransport_ = new TSocket(hostname_, portNum_);
thriftTransport_.open();
thriftProtocol_ = new TBinaryProtocol(thriftTransport_);
thriftClient_ = new Relevanced.Client(thriftProtocol_);
} catch (TException err) {
err.printStackTrace();
throw err;
}
}

Expand Down Expand Up @@ -96,7 +92,7 @@ public String createCentroid(String name) throws TException {
return response.id;
}

public Boolean deleteCentroid(String name) throws TException {
public String deleteCentroid(String name) throws TException {
CrudResponse response;
response = thriftClient_.deleteCentroid(name);
return response.id;
Expand All @@ -120,8 +116,7 @@ public List<String> listAllDocuments() throws TException {
}

public List<String> listAllCentroids() throws TException {
List<String> centroids = thriftClient_.listAllCentroids();
return centroids;
return thriftClient_.listAllCentroids();
}

public List<String> listAllDocumentsForCentroid(String centroidId) throws TException {
Expand Down
2 changes: 1 addition & 1 deletion clients/nodejs/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "relevanced-client",
"version": "0.8.0a3",
"version": "0.9.0rc1",
"description": "client for relevanced-server",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions clients/nodejs/client/test/functionalSmoketest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ var log = _.bind(console.log, console);

var main = function() {
var client = new RelevancedClient('localhost', 8097);
client.getServerMetadata().then(function(metadata) {
log('server metadata: ');
log(metadata);
}).catch(log);
client.listAllCentroids().then(function(centroids) {
log("Centroid count: ", centroids.length);
log(centroids);
Expand Down
2 changes: 1 addition & 1 deletion clients/python/client/relevanced_client/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '0.8.0a3'
VERSION = '0.9.0rc1'

0 comments on commit 8b25508

Please sign in to comment.