Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request vitessio#59 from timofeyb/master
Browse files Browse the repository at this point in the history
Implemented VtoccBsonBlockingChannel and integration tests.
  • Loading branch information
alainjobart committed Jun 18, 2014
2 parents 1c3190c + f166f9d commit a230116
Show file tree
Hide file tree
Showing 36 changed files with 1,879 additions and 526 deletions.
7 changes: 4 additions & 3 deletions java/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ echo "[INFO] Checking for prerequisites..."
[ -z "$VTTOP" ] && echo "[ERROR] source dev.env first, VTTOP is empty" 1>&2 && exit 1
[ -z "$VTROOT" ] && echo "[ERROR] source dev.env first, VTROOT is empty" 1>&2 && exit 1
[ -z "$VTDATAROOT" ] && echo "[ERROR] source dev.env first, VTDATAROOT is empty" 1>&2 && exit 1
! sbt --version && echo "[ERROR] Install sbt" 1>&2 && exit 1
! mvn --version && echo "[ERROR] Install maven" 1>&2 && exit 1
! git --version && echo "[ERROR] Install git" 1>&2 && exit 1
type sbt >/dev/null 2>&1 || { echo >&2 "[ERROR] Install sbt from http://www.scala-sbt.org/release/tutorial/Installing-sbt-on-Linux.html. Aborting."; exit 1; }
type protoc >/dev/null 2>&1 || { echo >&2 "[ERROR] Install protoc with sudo apt-get install protobuf-compiler. Aborting."; exit 1; }
type mvn >/dev/null 2>&1 || { echo >&2 "[ERROR] Install maven with sudo apt-get install maven. Aborting."; exit 1; }
type git >/dev/null 2>&1 || { echo >&2 "[ERROR] Install git with sudo apt-get install git. Aborting."; exit 1; }

ACOLYTE_DIST="$VTROOT/dist/java/org/eu/acolyte/acolyte-core/1.0.13-PATCHED"
ACOLYTE="$VTTOP/third_party/acolyte"
Expand Down
8 changes: 6 additions & 2 deletions java/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.youtube.vitess</groupId>
Expand All @@ -25,6 +25,10 @@
<id>timofeyb</id>
<name>Timothy Basanov</name>
</developer>
<developer>
<id>GarethCOliver</id>
<name>Gareth Oliver</name>
</developer>
</developers>

<licenses>
Expand Down
105 changes: 52 additions & 53 deletions java/vtocc-client/src/main/java/com/github/youtube/vitess/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.common.base.Stopwatch;
import com.google.common.collect.Maps;

import com.github.youtube.vitess.jdbc.Driver;
import com.github.youtube.vitess.jdbc.bson.Driver;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
Expand All @@ -31,58 +31,6 @@ public class Client {

private static final Logger logger = LoggerFactory.getLogger(Client.class);

/**
* Parses command line parameters into a convenient class.
*/
public static final class CommandLineOptions {

public final int count;
public final Map<String, String> bindvars;
public final String server;
public final boolean verbose;
public final String sql;

public CommandLineOptions(int count, Map<String, String> bindvars, String server,
boolean verbose, String sql) {
this.count = count;
this.bindvars = bindvars;
this.server = server;
this.verbose = verbose;
this.sql = sql;
}

@SuppressWarnings("AccessStaticViaInstance")
private static final Options options = new Options()
.addOption(OptionBuilder.withLongOpt("count").hasArg()
.withDescription("how many times to run the query").create())
.addOption(OptionBuilder.withLongOpt("bindvars").withValueSeparator().hasArg()
.withDescription("bind vars as a json dictionary").create())
.addOption(OptionBuilder.withLongOpt("server").hasArg()
.withDescription(
"vtocc server as hostname:port/keyspace")
.create())
.addOption(OptionBuilder.withLongOpt("driver").hasArg()
.withDescription(
"which driver to use (one of vttable, vttablet-streaming, vtdb, vtdb-streaming)")
.create())
.addOption(
OptionBuilder.withLongOpt("verbose").hasArg().withDescription("show results").create());

public static CommandLineOptions parseCommandLine(String[] args) throws ParseException {
CommandLine line = new BasicParser().parse(options, args);
int count = Integer.parseInt(line.getOptionValue("count", "1"));
Map<String, String> bindvars = Maps.fromProperties(line.getOptionProperties("bindvars"));
String server = line.getOptionValue("server", "localhost:6603/test_keyspace");
boolean verbose = Boolean.parseBoolean(line.getOptionValue("verbose", "false"));
String sql = Joiner.on(' ').join(line.getArgList());
return new CommandLineOptions(count, bindvars, server, verbose, sql);
}

public static void printHelp() {
new HelpFormatter().printHelp("java -jar vtocc-client.jar", options);
}
}

@SuppressWarnings("AccessStaticViaInstance")
public static void main(String[] args) {
CommandLineOptions options = null;
Expand Down Expand Up @@ -152,4 +100,55 @@ private static void executeQuery(Connection connection, String sql, boolean verb
(float) queryStopwatch.elapsed(TimeUnit.NANOSECONDS) / TimeUnit.MILLISECONDS.toNanos(1),
rowIndex);
}

/**
* Parses command line parameters into a convenient class.
*/
public static final class CommandLineOptions {

@SuppressWarnings("AccessStaticViaInstance")
private static final Options options = new Options()
.addOption(OptionBuilder.withLongOpt("count").hasArg()
.withDescription("how many times to run the query").create())
.addOption(OptionBuilder.withLongOpt("bindvars").withValueSeparator().hasArg()
.withDescription("bind vars as a json dictionary").create())
.addOption(OptionBuilder.withLongOpt("server").hasArg()
.withDescription(
"vtocc server as hostname:port/keyspace")
.create())
.addOption(OptionBuilder.withLongOpt("driver").hasArg()
.withDescription(
"which driver to use (one of vttable, vttablet-streaming, vtdb, vtdb-streaming)")
.create())
.addOption(
OptionBuilder.withLongOpt("verbose").hasArg().withDescription("show results").create());
public final int count;
public final Map<String, String> bindvars;
public final String server;
public final boolean verbose;
public final String sql;

public CommandLineOptions(int count, Map<String, String> bindvars, String server,
boolean verbose, String sql) {
this.count = count;
this.bindvars = bindvars;
this.server = server;
this.verbose = verbose;
this.sql = sql;
}

public static CommandLineOptions parseCommandLine(String[] args) throws ParseException {
CommandLine line = new BasicParser().parse(options, args);
int count = Integer.parseInt(line.getOptionValue("count", "1"));
Map<String, String> bindvars = Maps.fromProperties(line.getOptionProperties("bindvars"));
String server = line.getOptionValue("server", "localhost:6603/test_keyspace");
boolean verbose = Boolean.parseBoolean(line.getOptionValue("verbose", "false"));
String sql = Joiner.on(' ').join(line.getArgList());
return new CommandLineOptions(count, bindvars, server, verbose, sql);
}

public static void printHelp() {
new HelpFormatter().printHelp("java -jar vtocc-client.jar", options);
}
}
}
161 changes: 133 additions & 28 deletions java/vtocc-jdbc-driver/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand All @@ -16,6 +16,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<VTROOT>${basedir}/../../../../../..</VTROOT>
<VTTOP>${basedir}/../..</VTTOP>
<VTDATAROOT>${basedir}/../../../../../../vtdataroot</VTDATAROOT>
<mysql.port>9999</mysql.port>
<vtocc.port>9000</vtocc.port>
<mysqlctl.port>9500</mysqlctl.port>
</properties>

<repositories>
Expand All @@ -32,12 +36,6 @@
<artifactId>acolyte-core</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<!-- Is a dependency of acolyte-core -->
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand All @@ -64,14 +62,14 @@
<version>17.0</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>2.12.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -92,13 +90,12 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7-b2</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<pluginRepositories>
<pluginRepository>
<id>dtrott</id>
Expand Down Expand Up @@ -162,29 +159,102 @@
<version>1.3</version>
<configuration>
<executable>bash</executable>
<arguments>
<argument>-ce</argument>
<argument>
source "$VTTOP/dev.env"
mkdir -p "$TEST_OUTPUT"
env | grep -v '\\' > "$TEST_OUTPUT/dev.env.properties"
</argument>
</arguments>
<environmentVariables>
<VTTOP>${VTTOP}</VTTOP>
<TEST_OUTPUT>${project.build.testOutputDirectory}</TEST_OUTPUT>
<VTDATAROOT>${VTDATAROOT}</VTDATAROOT>
</environmentVariables>
<workingDirectory>${VTTOP}</workingDirectory>
</configuration>
<executions>
<execution>
<id>process-devenv-properties</id>
<phase>process-test-resources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-ce</argument>
<argument>
source "$VTTOP/dev.env"
mkdir -p "$TEST_OUTPUT"
env | grep -v '\\' > "$TEST_OUTPUT/dev.env.properties"
</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>generate-sql-tests-json</id>
<phase>process-test-classes</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-ce</argument>
<argument>
mkdir -p "$TEST_OUTPUT"
python "$TEST_OUTPUT/gen_sql_tests_json.py" > \
"$TEST_OUTPUT/sql_tests.json"
python "$TEST_OUTPUT/gen_test_schema_sql.py" > \
"$TEST_OUTPUT/test_schema.sql"
</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>startup-sql-tests-json</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-ce</argument>
<argument>
export CANONICALIZED_VTDATAROOT="$(readlink -f \
"$VTDATAROOT")/vt_0000000000"
rm "$CANONICALIZED_VTDATAROOT" -rf
$VTROOT/bin/mysqlctl --tablet_uid=0 --mysql_port=${mysql.port} \
--port=${mysqlctl.port} init
$VTROOT/dist/mysql/bin/mysql "-S" \
"$CANONICALIZED_VTDATAROOT/mysql.sock" \
"-u" "vt_dba" \
"-e" "create database vt_test_keyspace ; set global read_only =
off"
</argument>
</arguments>
</configuration>
</execution>
<execution>
<id>teardown-sql-tests-json</id>
<phase>post-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<arguments>
<argument>-c</argument>
<argument>
$VTROOT/bin/mysqlctl --tablet_uid=0 --mysql_port=${mysql.port} \
--port=${mysqlctl.port} shutdown
</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- Run unit tests excluding integration tests -->
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<!-- Generate html reports -->
<artifactId>maven-surefire-report-plugin</artifactId>
Expand All @@ -201,14 +271,49 @@
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<id>make-assembly</id>
<!-- this is used for inheritance merges -->
<phase>package</phase>
<!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- Runs integration tests -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<systemProperties>
<vtocc.port>${vtocc.port}</vtocc.port>
<VTDATAROOT>${VTDATAROOT}/vt_0000000000</VTDATAROOT>
<VTROOT>${VTROOT}</VTROOT>
<org.slf4j.simpleLogger.defaultLogLevel>
debug
</org.slf4j.simpleLogger.defaultLogLevel>
</systemProperties>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit a230116

Please sign in to comment.