Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloboschi committed Aug 22, 2024
1 parent 6a0e0f9 commit 802c251
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,11 @@ void testJsonValueFieldOutput() throws Exception {

public static Object[][] jsonStringFieldOutput() {
return new Object[][] {
{Schema.STRING, "{\"name\":\"Jane\"}", "{\"name\":\"Jane\",\"chat\":\"result\"}"},
{Schema.STRING, "{\"name\":\"Jane\"}", "{\"chat\":\"result\",\"name\":\"Jane\"}"},
{
Schema.BYTES,
"{\"name\":\"Jane\"}".getBytes(StandardCharsets.UTF_8),
"{\"name\":\"Jane\",\"chat\":\"result\"}".getBytes(StandardCharsets.UTF_8)
"{\"chat\":\"result\",\"name\":\"Jane\"}".getBytes(StandardCharsets.UTF_8)
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,7 @@ void testStringJson(Schema schema) throws Exception {
assertEquals(outputRecord.getSchema(), schema);

Object expected =
"{\"name\":\"Jane\",\"age\":\"43\",\"date\":18999,\"timestamp\":1672525445006,\"time\":83085006,"
+ "\"integerStr\":\"13360\"}";
"{\"name\":\"Jane\",\"age\":\"43\",\"date\":18999,\"timestamp\":1672525445006,\"time\":83085006,\"integerStr\":\"13360\"}";
if (schemaType == SchemaType.BYTES) {
expected = ((String) expected).getBytes(StandardCharsets.UTF_8);
assertArrayEquals((byte[]) outputRecord.getValue(), (byte[]) expected);
Expand Down Expand Up @@ -485,8 +484,7 @@ void testKVStringJson(Schema<?> schema) throws Exception {

assertEquals(messageValue.getValue(), 42);
Object expected =
"{\"name\":\"Jane\",\"age\":\"44\",\"date\":18999,\"timestamp\":1672525445006,\"time\":83085006,"
+ "\"integerStr\":\"13360\"}";
"{\"name\":\"Jane\",\"age\":\"44\",\"date\":18999,\"timestamp\":1672525445006,\"time\":83085006,\"integerStr\":\"13360\"}";
if (schemaType == SchemaType.BYTES) {
expected = ((String) expected).getBytes(StandardCharsets.UTF_8);
assertArrayEquals((byte[]) messageValue.getKey(), (byte[]) expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ void testKeyValueStringJson() throws Exception {

assertEquals(
messageValue.getValue(),
"{\"valueField1\":\"value1\",\"valueField2\":\"value2\","
+ "\"valueField3\":\"value3\",\"keyField1\":\"key1\",\"keyField2\":\"key2\",\"keyField3\":\"key3\"}");
"{\"valueField1\":\"value1\",\"valueField2\":\"value2\",\"valueField3\":\"value3\",\"keyField1\":\"key1\",\"keyField2\":\"key2\",\"keyField3\":\"key3\"}");
}

@Test
Expand Down Expand Up @@ -143,8 +142,7 @@ void testKeyValueBytesJson() throws Exception {

assertEquals(
new String((byte[]) messageValue.getValue(), StandardCharsets.UTF_8),
"{\"valueField1\":\"value1\",\"valueField2\":\"value2\",\"valueField3\":\"value3\","
+ "\"keyField1\":\"key1\",\"keyField2\":\"key2\",\"keyField3\":\"key3\"}");
"{\"valueField1\":\"value1\",\"valueField2\":\"value2\",\"valueField3\":\"value3\",\"keyField1\":\"key1\",\"keyField2\":\"key2\",\"keyField3\":\"key3\"}");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,7 @@ public static ApplicationWithPackageInfo buildApplicationInstance(
if (defaultsHolder.globals != null && !defaultsHolder.globals.isEmpty()) {
applicationWithPackageInfo.hasInstanceDefinition = true;
parseInstance(
"instance:",
applicationWithPackageInfo.getApplication(),
defaultsHolder.globals);
"{}", applicationWithPackageInfo.getApplication(), defaultsHolder.globals);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void testParseRealDirectoryWithDefaults() throws Exception {
String instanceContentWithEmptyGlobals =
"""
instance:
globals:
globals: {}
""";
applicationWithPackageInfo =
ModelBuilder.buildApplicationInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private void checkSetupJob(Job job) {

assertEquals(2, configMap.getData().size());
assertEquals(
"{\"applicationId\":\"my-app\",\"tenant\":\"my-tenant\",\"application\":\"{\\\"modules\\\": {}}\",\"codeArchiveId\":null}",
"{\"applicationId\":\"my-app\",\"tenant\":\"my-tenant\",\"application\":\"{\\\"modules\\\": {}}\"}",
configMap.getData().get("app-config"));

assertEquals("{}", configMap.getData().get("cluster-runtime-config"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ tenant, appId, application, buildInstanceYaml(), expectedAgents)) {

String expected =
"""
{"question":"the car","session-id":"2139847128764192","answer":"A car is a vehicle","prompt":"{\\"options\\":{\\"type\\":\\"ai-chat-completions\\",\\"when\\":null,\\"model\\":\\"ai21.j2-mid-v1\\",\\"messages\\":[{\\"role\\":null,\\"content\\":\\"What can you tell me about {{{ value.question }}} ?\\"}],\\"stream-to-topic\\":null,\\"stream-response-completion-field\\":null,\\"min-chunks-per-message\\":3,\\"completion-field\\":\\"value.answer\\",\\"stream\\":true,\\"log-field\\":\\"value.prompt\\",\\"max-tokens\\":null,\\"temperature\\":null,\\"top-p\\":null,\\"logit-bias\\":null,\\"user\\":null,\\"stop\\":null,\\"presence-penalty\\":null,\\"frequency-penalty\\":null,\\"options\\":{\\"request-parameters\\":{\\"maxTokens\\":5,\\"temperature\\":0.2},\\"response-completions-expression\\":\\"completions[0].data.text\\"}},\\"messages\\":[{\\"role\\":null,\\"content\\":\\"What can you tell me about the car ?\\"}],\\"model\\":\\"ai21.j2-mid-v1\\"}"}"""
.formatted(prompt, outputTopic);
{"answer":"A car is a vehicle","prompt":"{\\"messages\\":[{\\"content\\":\\"What can you tell me about the car ?\\"}],\\"model\\":\\"ai21.j2-mid-v1\\",\\"options\\":{\\"completion-field\\":\\"value.answer\\",\\"log-field\\":\\"value.prompt\\",\\"messages\\":[{\\"content\\":\\"%s\\"}],\\"min-chunks-per-message\\":3,\\"model\\":\\"ai21.j2-mid-v1\\",\\"options\\":{\\"request-parameters\\":{\\"maxTokens\\":5,\\"temperature\\":0.2},\\"response-completions-expression\\":\\"completions[0].data.text\\"},\\"stream\\":true,\\"type\\":\\"ai-chat-completions\\"}}","question":"the car","session-id":"2139847128764192"}"""
.formatted(prompt);
waitForMessages(consumer, List.of(expected));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void testCassandra() throws Exception {
waitForMessages(
consumer,
List.of(
"{\"documentId\":2,\"queryresult\":{\"name\":\"A\",\"description\":\"A description\",\"id\":1},\"name\":\"A\",\"description\":\"A description\"}"));
"{\"description\":\"A description\",\"documentId\":2,\"name\":\"A\",\"queryresult\":{\"description\":\"A description\",\"id\":1,\"name\":\"A\"}}"));

CqlSessionBuilder builder = new CqlSessionBuilder();
builder.addContactPoint(cassandra.getContactPoint());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void testCassandra() throws Exception {
waitForMessages(
consumer,
List.of(
"{\"documentId\":2,\"embeddings\":[0.1,0.2,0.3,0.4,0.5],\"queryresult\":{\"embeddings\":null,\"name\":\"A\",\"description\":\"A description\",\"id\":1},\"name\":\"A\",\"description\":\"A description\"}"));
"{\"description\":\"A description\",\"documentId\":2,\"embeddings\":[0.1,0.2,0.3,0.4,0.5],\"name\":\"A\",\"queryresult\":{\"description\":\"A description\",\"id\":1,\"name\":\"A\"}}"));

CqlSessionBuilder builder = new CqlSessionBuilder();
builder.addContactPoint(cassandra.getContactPoint());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ tenant, appId, application, buildInstanceYaml(), expectedAgents)) {

String expected =
"""
{"question":"the car","session-id":"2139847128764192","answer":"A car is a vehicle","prompt":"{\\"options\\":{\\"type\\":\\"ai-chat-completions\\",\\"when\\":null,\\"model\\":\\"gpt-35-turbo\\",\\"messages\\":[{\\"role\\":\\"user\\",\\"content\\":\\"%s\\"}],\\"stream-to-topic\\":\\"%s\\",\\"stream-response-completion-field\\":\\"value\\",\\"min-chunks-per-message\\":3,\\"completion-field\\":\\"value.answer\\",\\"stream\\":true,\\"log-field\\":\\"value.prompt\\",\\"max-tokens\\":null,\\"temperature\\":null,\\"top-p\\":null,\\"logit-bias\\":null,\\"user\\":null,\\"stop\\":null,\\"presence-penalty\\":null,\\"frequency-penalty\\":null,\\"options\\":null},\\"messages\\":[{\\"role\\":\\"user\\",\\"content\\":\\"What can you tell me about the car ?\\"}],\\"model\\":\\"gpt-35-turbo\\"}"}"""
{"answer":"A car is a vehicle","prompt":"{\\"messages\\":[{\\"role\\":\\"user\\",\\"content\\":\\"What can you tell me about the car ?\\"}],\\"model\\":\\"gpt-35-turbo\\",\\"options\\":{\\"completion-field\\":\\"value.answer\\",\\"log-field\\":\\"value.prompt\\",\\"messages\\":[{\\"content\\":\\"%s\\",\\"role\\":\\"user\\"}],\\"min-chunks-per-message\\":3,\\"model\\":\\"gpt-35-turbo\\",\\"stream\\":true,\\"stream-response-completion-field\\":\\"value\\",\\"stream-to-topic\\":\\"%s\\",\\"type\\":\\"ai-chat-completions\\"}}","question":"the car","session-id":"2139847128764192"}"""
.formatted(prompt, streamToTopic);
List<Record> mainOutputRecords = waitForMessages(consumer, List.of(expected));
Record record = mainOutputRecords.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ tenant, appId, application, buildInstanceYaml(), expectedAgents)) {
Set<String> expectedMessages = new HashSet<>();
for (String embedding : config.expectedEmbeddings) {
String expected =
"{\"name\":\"some name\",\"description\":\"some description\",\"embeddings\":%s}"
"{\"description\":\"some description\",\"embeddings\":%s,\"name\":\"some name\"}"
.formatted(embedding);
expectedMessages.add(expected);
}
Expand Down Expand Up @@ -528,11 +528,11 @@ tenant, appId, application, buildInstanceYaml(), expectedAgents)) {
};
}
String expectedContent =
"{\"name\":\" "
+ name
+ "\",\"description\":\"some description\",\"embeddings\":"
"{\"description\":\"some description\",\"embeddings\":"
+ embeddings
+ "}";
+ "\"name\":\" "
+ name
+ "\"}";
expected.add(expectedContent);
}

Expand Down Expand Up @@ -688,7 +688,7 @@ tenant, appId, application, buildInstanceYaml(), expectedAgents)) {
waitForMessages(
consumer,
List.of(
"{\"name\":\"foo\",\"embeddings\":[1.0,5.400000095367432,8.699999809265137]}"));
"{\"embeddings\":[1.0,5.400000095367432,8.699999809265137],\"name\":\"foo\"}"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void test(boolean https, String host, int port, String apiKey) throws Exc
waitForMessages(
consumer,
List.of(
"{\"embeddings\":[1,1,2],\"query-result\":[{\"embeddings\":[1,1,1],\"similarity\":0.9394879,\"index\":\"my-index-000\",\"id\":\"key9\",\"content\":\"hello9\"}]}"));
"{\"embeddings\":[1,1,2],\"query-result\":[{\"content\":\"hello9\",\"embeddings\":[1,1,1],\"id\":\"key9\",\"index\":\"my-index-000\",\"similarity\":0.93994164}]}"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void testGetJson() throws Exception {

final String e1 =
"""
{"id":"my-model","classification":"good","api":{"id":"my-model","created":"2021-08-31T12:00:00Z","model":"gpt-35-turbo","object":"text-generation","choices":[{"text":"It is a car."}]}}""";
{"api":{"choices":[{"text":"It is a car."}],"created":"2021-08-31T12:00:00Z","id":"my-model","model":"gpt-35-turbo","object":"text-generation"},"classification":"good","id":"my-model"}""";
runAndAssertMessage(application, e1);
}

Expand Down Expand Up @@ -128,7 +128,7 @@ void testGetRawText() throws Exception {

final String e1 =
"""
{"id":"my-model","classification":"good","api":"some-string"}""";
{"api":"some-string","classification":"good","id":"my-model"}""";
runAndAssertMessage(application, e1);
}

Expand Down Expand Up @@ -182,7 +182,7 @@ void testPostWithBody() throws Exception {

final String e1 =
"""
{"id":"my-model","classification":"good","api":{"id":"my-model","created":"2021-08-31T12:00:00Z","model":"gpt-35-turbo","object":"text-generation","choices":[{"text":"It is a car."}]}}""";
{"api":{"choices":[{"text":"It is a car."}],"created":"2021-08-31T12:00:00Z","id":"my-model","model":"gpt-35-turbo","object":"text-generation"},"classification":"good","id":"my-model"}""";
runAndAssertMessage(application, e1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ public void test() throws Exception {
waitForMessages(
consumer,
List.of(
"{\"embeddings\":[999,999,5],\"query-result\":[{\"score\":1.0,"
+ "\"document\":{\"embeddings\":[999,999,5],\"content\":\"hello5\"},"
+ "\"index\":\"my-index-1\",\"id\":\"key5\"}]}"));
"{\"embeddings\":[999,999,5],\"query-result\":[{\"document\":{\"content\":\"hello5\",\"embeddings\":[999,999,5]},\"id\":\"key5\",\"index\":\"my-index-1\",\"score\":1.0}]}"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ public void testSplitThenJson(boolean useIntermediateTopic) throws Exception {
waitForMessages(
consumer,
List.of(
"{\"chunk_text_length\":\"47\",\"text\":\"This text is written in English, but it is very\",\"text_num_chunks\":\"3\",\"chunk_id\":\"0\",\"chunk_num_tokens\":\"47\"}",
"{\"chunk_text_length\":\"5\",\"text\":\"long,\",\"text_num_chunks\":\"3\",\"chunk_id\":\"1\",\"chunk_num_tokens\":\"5\"}",
"{\"chunk_text_length\":\"40\",\"text\":\"so you may want to split it into chunks.\",\"text_num_chunks\":\"3\",\"chunk_id\":\"2\",\"chunk_num_tokens\":\"40\"}"));
"{\"chunk_id\":\"0\",\"chunk_num_tokens\":\"47\",\"chunk_text_length\":\"47\",\"text\":\"This text is written in English, but it is very\",\"text_num_chunks\":\"3\"}",
"{\"chunk_id\":\"1\",\"chunk_num_tokens\":\"5\",\"chunk_text_length\":\"5\",\"text\":\"long,\",\"text_num_chunks\":\"3\"}",
"{\"chunk_id\":\"2\",\"chunk_num_tokens\":\"40\",\"chunk_text_length\":\"40\",\"text\":\"so you may want to split it into chunks.\",\"text_num_chunks\":\"3\"}"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void accept(Object o) {
assertEquals("AssetDeleted", read.get("type"));
assertEquals("Asset", read.get("category"));
assertEquals(
"{\"tenant\":\"tenant\",\"applicationId\":\"app\",\"asset\":{\"id\":\"my-table\",\"name\":\"my-table\",\"config\":{\"datasource\":{\"configuration\":{\"service\":\"jdbc\",\"driverClass\":\"org.postgresql.Driver\",\"url\":\"bar\"}},\"table\":\"my-table\"},\"creation-mode\":\"create-if-not-exists\",\"deletion-mode\":\"delete\",\"asset-type\":\"mock-database-resource\",\"events-topic\":\"%s\"}}"
"{\"applicationId\":\"app\",\"asset\":{\"asset-type\":\"mock-database-resource\",\"config\":{\"datasource\":{\"configuration\":{\"driverClass\":\"org.postgresql.Driver\",\"service\":\"jdbc\",\"url\":\"bar\"}},\"table\":\"my-table\"},\"creation-mode\":\"create-if-not-exists\",\"deletion-mode\":\"delete\",\"events-topic\":\"%s\",\"id\":\"my-table\",\"name\":\"my-table\"},\"tenant\":\"tenant\"}"
.formatted(eventsTopic),
ObjectMapperFactory.getDefaultMapper()
.writeValueAsString(read.get("source")));
Expand Down Expand Up @@ -240,7 +240,7 @@ public void accept(Object o) {
assertEquals("AssetCreationFailed", read.get("type"));
assertEquals("Asset", read.get("category"));
assertEquals(
"{\"tenant\":\"tenant\",\"applicationId\":\"app\",\"asset\":{\"id\":\"my-table\",\"name\":\"my-table\",\"config\":{\"fail\":true,\"datasource\":{\"configuration\":{\"service\":\"jdbc\",\"driverClass\":\"org.postgresql.Driver\",\"url\":\"bar\"}}},\"creation-mode\":\"create-if-not-exists\",\"deletion-mode\":\"delete\",\"asset-type\":\"mock-database-resource\",\"events-topic\":\"%s\"}}"
"{\"applicationId\":\"app\",\"asset\":{\"asset-type\":\"mock-database-resource\",\"config\":{\"datasource\":{\"configuration\":{\"driverClass\":\"org.postgresql.Driver\",\"service\":\"jdbc\",\"url\":\"bar\"}},\"fail\":true},\"creation-mode\":\"create-if-not-exists\",\"deletion-mode\":\"delete\",\"events-topic\":\"%s\",\"id\":\"my-table\",\"name\":\"my-table\"},\"tenant\":\"tenant\"}"
.formatted(eventsTopic),
ObjectMapperFactory.getDefaultMapper()
.writeValueAsString(read.get("source")));
Expand Down
Loading

0 comments on commit 802c251

Please sign in to comment.