Skip to content

Remove thrift dataconverter #1009

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

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.function.Function;
import org.apache.thrift.protocol.TJSONProtocol;

/**
* Implements conversion through GSON JSON processor. To extend use {@link
* #JsonDataConverter(Function)} constructor. Thrift structures are converted using {@link
* TJSONProtocol}. When using thrift only one argument of a method is expected.
* #JsonDataConverter(Function)} constructor.
*
* @author fateev
*/
Expand Down Expand Up @@ -78,9 +76,7 @@ public JsonDataConverter(Function<GsonBuilder, GsonBuilder> builderInterceptor)
GsonBuilder gsonBuilder =
new GsonBuilder()
.serializeNulls()
.registerTypeAdapterFactory(new ThrowableTypeAdapterFactory())
.registerTypeAdapterFactory(new TBaseTypeAdapterFactory(metricsScope))
.registerTypeAdapterFactory(new TEnumTypeAdapterFactory());
.registerTypeAdapterFactory(new ThrowableTypeAdapterFactory());
GsonBuilder intercepted = builderInterceptor.apply(gsonBuilder);
gson = intercepted.create();
}
Expand Down

This file was deleted.

This file was deleted.

128 changes: 0 additions & 128 deletions src/test/java/com/uber/cadence/converter/JsonDataConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,150 +20,22 @@
import static org.junit.Assert.*;

import com.google.gson.JsonIOException;
import com.uber.cadence.EventType;
import com.uber.cadence.History;
import com.uber.cadence.HistoryEvent;
import com.uber.cadence.TaskList;
import com.uber.cadence.WorkflowExecutionStartedEventAttributes;
import com.uber.cadence.WorkflowType;
import com.uber.cadence.activity.Activity;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import org.junit.Test;

public class JsonDataConverterTest {

private final DataConverter converter = JsonDataConverter.getInstance();

static class TestData {
String val1;
// TBase value;
HistoryEvent val2;
// TEnum value;
EventType val3;

public TestData(String val1, HistoryEvent val2, EventType val3) {
this.val1 = val1;
this.val2 = val2;
this.val3 = val3;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TestData)) return false;
TestData testData = (TestData) o;
return Objects.equals(val1, testData.val1)
&& Objects.equals(val2, testData.val2)
&& val3 == testData.val3;
}

@Override
public int hashCode() {

return Objects.hash(val1, val2, val3);
}
}

@Test
public void testThrift() {
List<HistoryEvent> events = new ArrayList<>();
WorkflowExecutionStartedEventAttributes started =
new WorkflowExecutionStartedEventAttributes()
.setExecutionStartToCloseTimeoutSeconds(11)
.setIdentity("testIdentity")
.setInput("input".getBytes(StandardCharsets.UTF_8))
.setWorkflowType(new WorkflowType().setName("workflowType1"))
.setTaskList(new TaskList().setName("taskList1"));
events.add(
new HistoryEvent()
.setTimestamp(1234567)
.setEventId(321)
.setWorkflowExecutionStartedEventAttributes(started));
History history = new History().setEvents(events);
byte[] converted = converter.toData(history);
History fromConverted = converter.fromData(converted, History.class, History.class);
assertEquals(new String(converted, StandardCharsets.UTF_8), history, fromConverted);
}

@Test
public void testThriftArray() {
List<HistoryEvent> events = new ArrayList<>();
WorkflowExecutionStartedEventAttributes started =
new WorkflowExecutionStartedEventAttributes()
.setExecutionStartToCloseTimeoutSeconds(11)
.setIdentity("testIdentity")
.setInput("input".getBytes(StandardCharsets.UTF_8))
.setWorkflowType(new WorkflowType().setName("workflowType1"))
.setTaskList(new TaskList().setName("taskList1"));
events.add(
new HistoryEvent()
.setTimestamp(1234567)
.setEventId(321)
.setWorkflowExecutionStartedEventAttributes(started));
History history = new History().setEvents(events);
byte[] converted = converter.toData("abc", history);
Object[] fromConverted = converter.fromDataArray(converted, String.class, History.class);
assertEquals(new String(converted, StandardCharsets.UTF_8), "abc", fromConverted[0]);
assertEquals(new String(converted, StandardCharsets.UTF_8), history, fromConverted[1]);
}

@Test
public void testThriftFieldsInPOJO() {
WorkflowExecutionStartedEventAttributes started =
new WorkflowExecutionStartedEventAttributes()
.setExecutionStartToCloseTimeoutSeconds(11)
.setIdentity("testIdentity")
.setInput("input".getBytes(StandardCharsets.UTF_8))
.setWorkflowType(new WorkflowType().setName("workflowType1"))
.setTaskList(new TaskList().setName("taskList1"));

HistoryEvent historyEvent =
new HistoryEvent()
.setTimestamp(1234567)
.setEventId(321)
.setWorkflowExecutionStartedEventAttributes(started);

TestData testData = new TestData("test-thrift", historyEvent, EventType.ActivityTaskCompleted);

byte[] converted = converter.toData(testData);
TestData fromConverted = converter.fromData(converted, TestData.class, TestData.class);
assertEquals(new String(converted, StandardCharsets.UTF_8), testData, fromConverted);
}

@Test
public void testThriftFieldsInPOJOArray() {
WorkflowExecutionStartedEventAttributes started =
new WorkflowExecutionStartedEventAttributes()
.setExecutionStartToCloseTimeoutSeconds(11)
.setIdentity("testIdentity")
.setInput("input".getBytes(StandardCharsets.UTF_8))
.setWorkflowType(new WorkflowType().setName("workflowType1"))
.setTaskList(new TaskList().setName("taskList1"));

HistoryEvent historyEvent =
new HistoryEvent()
.setTimestamp(1234567)
.setEventId(321)
.setWorkflowExecutionStartedEventAttributes(started);

TestData testData = new TestData("test-thrift", historyEvent, EventType.ActivityTaskCompleted);

byte[] converted = converter.toData("abc", testData);
Object[] fromConverted = converter.fromDataArray(converted, String.class, TestData.class);
assertEquals(new String(converted, StandardCharsets.UTF_8), "abc", fromConverted[0]);
assertEquals(new String(converted, StandardCharsets.UTF_8), testData, fromConverted[1]);
}

public static void foo(List<UUID> arg) {}

@Test
Expand Down