Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update thrift dependency to 0.19.0 #855

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ This doc is intended for contributors to `cadence-java-client` (hopefully that's
## Development Environment

* Java 11 (currently, we use Java 11 to compile Java 8 code).
* Thrift 0.9.3 (use [homebrew](https://formulae.brew.sh/formula/thrift@0.9) or [distribution](https://downloads.apache.org/thrift/0.9.3/))
* Thrift 0.19.0 (use [homebrew](https://formulae.brew.sh/formula/thrift@0.19) or [distribution](https://downloads.apache.org/thrift/0.19.0/))
* Gradle build tool [6.x](https://github.com/uber/cadence-java-client/blob/master/gradle/wrapper/gradle-wrapper.properties)
* Docker

:warning: Note 1: You must install the 0.9.x version of Thrift. Otherwise compiling would fail at error `error: package org.apache.thrift.annotation does not exist`
:warning: Note 1: You must install the 0.19.x version of Thrift. Otherwise compiling would fail at error `error: package org.apache.thrift.annotation does not exist`

:warning: Note 2: It's currently compatible with Java 8 compiler but no guarantee in the future.

Expand Down
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
dependencies {
classpath "gradle.plugin.org.jruyi.gradle:thrift-gradle-plugin:0.4.1"
classpath "gradle.plugin.org.jruyi.gradle:thrift-gradle-plugin:0.4.2"
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.11'
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ dependencies {

compile group: 'com.uber.tchannel', name: 'tchannel-core', version: '0.8.30'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.36'
compile group: 'org.apache.thrift', name: 'libthrift', version: '0.9.3'
compile group: 'org.apache.thrift', name: 'libthrift', version: '0.19.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.10'
compile group: 'com.uber.m3', name: 'tally-core', version: '0.11.1'
compile group: 'com.google.guava', name: 'guava', version: '31.1-jre'
Expand All @@ -82,6 +82,7 @@ dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'com.googlecode.junit-toolbox', name: 'junit-toolbox', version: '2.4'
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
testCompile group: 'commons-codec', name:'commons-codec', version: '1.16.0'
testCompile group: 'io.grpc', name: 'grpc-testing', version: '1.54.2'
testImplementation 'io.opentracing:opentracing-mock:0.33.0'
}
Expand Down
2 changes: 1 addition & 1 deletion docker/buildkite/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
FROM adoptopenjdk/openjdk11:jdk-11.0.10_9-alpine

# Apache Thrift version
ENV APACHE_THRIFT_VERSION=0.9.3
ENV APACHE_THRIFT_VERSION=0.19.0

# Install dependencies using apk
RUN apk update && apk add --virtual wget ca-certificates wget && apk add --virtual build-dependencies build-base gcc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.thrift.TException;
import org.apache.thrift.TSerializer;
import org.apache.thrift.protocol.TJSONProtocol;
import org.apache.thrift.transport.TTransportException;

/**
* Special handling of TBase message serialization and deserialization. This is to support for
Expand All @@ -48,8 +49,7 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
@Override
public void write(JsonWriter jsonWriter, T value) throws IOException {
try {
String result =
newThriftSerializer().toString((TBase) value, StandardCharsets.UTF_8.name());
String result = newThriftSerializer().toString((TBase) value);
jsonWriter.value(result);
} catch (TException e) {
throw new DataConverterException("Failed to serialize TBase", e);
Expand All @@ -73,11 +73,11 @@ public T read(JsonReader jsonReader) throws IOException {
return result;
}

private static TSerializer newThriftSerializer() {
private static TSerializer newThriftSerializer() throws TTransportException {
return new TSerializer(new TJSONProtocol.Factory());
}

private static TDeserializer newThriftDeserializer() {
private static TDeserializer newThriftDeserializer() throws TTransportException {
return new TDeserializer(new TJSONProtocol.Factory());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.thrift.TDeserializer;
import org.apache.thrift.TException;
import org.apache.thrift.TSerializer;
import org.apache.thrift.transport.TTransportException;

/** Utility functions shared by the implementation code. */
public final class InternalUtils {
Expand Down Expand Up @@ -167,10 +168,10 @@ public static SearchAttributes convertMapToSearchAttributes(
// This method serializes history to blob data
public static DataBlob SerializeFromHistoryToBlobData(History history) {

// TODO: move to global dependency after https://issues.apache.org/jira/browse/THRIFT-2218
TSerializer serializer = new TSerializer();
DataBlob blob = new DataBlob();
try {
// TODO: move to global dependency after https://issues.apache.org/jira/browse/THRIFT-2218
TSerializer serializer = new TSerializer();
blob.setData(serializer.serialize(history));
} catch (org.apache.thrift.TException err) {
throw new RuntimeException("Serialize history to blob data failed", err);
Expand Down Expand Up @@ -215,7 +216,12 @@ public static History DeserializeFromBlobDataToHistory(
public static List<DataBlob> SerializeFromHistoryEventToBlobData(List<HistoryEvent> events) {

// TODO: move to global dependency after https://issues.apache.org/jira/browse/THRIFT-2218
TSerializer serializer = new TSerializer();
TSerializer serializer;
try {
serializer = new TSerializer();
} catch (TTransportException err) {
throw new RuntimeException("Serialize history event to blob data failed", err);
}
List<DataBlob> blobs = Lists.newArrayListWithCapacity(events.size());
for (HistoryEvent event : events) {
DataBlob blob = new DataBlob();
Expand Down