Skip to content

Commit 2e87f97

Browse files
committed
working no coverage
Signed-off-by: davidradl <[email protected]>
1 parent 42d4b0b commit 2e87f97

File tree

7 files changed

+43
-32
lines changed

7 files changed

+43
-32
lines changed

src/main/java/com/getindata/connectors/http/HttpStatusCodeValidationFailedException.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.getindata.connectors.http;
22

3+
import java.io.IOException;
34
import java.net.http.HttpResponse;
45

56
import lombok.Getter;
67

78
@Getter
8-
public class HttpStatusCodeValidationFailedException extends Exception {
9+
public class HttpStatusCodeValidationFailedException extends IOException {
910
private final HttpResponse<?> response;
1011

1112
public HttpStatusCodeValidationFailedException(String message, HttpResponse<?> response) {

src/main/java/com/getindata/connectors/http/internal/retry/HttpClientWithRetry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public <T> HttpResponse<T> send(
5757
"Incorrect response code: " + response.statusCode(), response);
5858
}
5959
return response;
60-
} catch (IOException | InterruptedException | HttpStatusCodeValidationFailedException e) {
60+
} catch (IOException | InterruptedException e) {
6161
throw e; //re-throw without wrapping
6262
} catch (Throwable t) {
6363
throw new RuntimeException("Unexpected exception", t);

src/main/java/com/getindata/connectors/http/internal/table/lookup/HttpLookupTableSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected LookupRuntimeProvider getLookupRuntimeProvider(LookupRow lookupRow,
126126
pollingClientFactory) {
127127
MetadataConverter[] metadataConverters={};
128128
if (this.metadataKeys != null) {
129-
this.metadataKeys.stream()
129+
metadataConverters = this.metadataKeys.stream()
130130
.map(
131131
k ->
132132
Stream.of(HttpLookupTableSource.ReadableMetadata.values())

src/main/java/com/getindata/connectors/http/internal/table/lookup/HttpTableLookupFunction.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,25 @@ public void open(FunctionContext context) throws Exception {
8181
public Collection<RowData> lookup(RowData keyRow) {
8282
localHttpCallCounter.incrementAndGet();
8383
List<RowData> outputList = new ArrayList<>();
84-
// TODO turn into a constant?
8584
final int metadataArity = metadataConverters.length;
8685
try {
8786
Collection<RowData> httpCollector = client.pull(keyRow);
88-
if (httpCollector.size() != 1) {
89-
throw new RuntimeException("Expected 1 row data got " + httpCollector.size());
90-
}
91-
GenericRowData physicalRow = (GenericRowData) httpCollector.iterator().next();
92-
final int physicalArity = physicalRow.getArity();
93-
final GenericRowData producedRow =
87+
// When there are no metadata columns or we have no results then
88+
// return what the client pulls.
89+
if (this.fail_job_on_error || httpCollector.size() == 0) {
90+
localHttpCallCounter.incrementAndGet();
91+
return httpCollector;
92+
} else {
93+
GenericRowData physicalRow = (GenericRowData) httpCollector.iterator().next();
94+
final int physicalArity = physicalRow.getArity();
95+
final GenericRowData producedRow =
9496
new GenericRowData(physicalRow.getRowKind(), physicalArity + metadataArity);
95-
// We need to copy in the physical row into the producedRow
96-
for (int pos = 0; pos < physicalArity; pos++) {
97-
producedRow.setField(pos, physicalRow.getField(pos));
97+
// We need to copy in the physical row into the producedRow
98+
for (int pos = 0; pos < physicalArity; pos++) {
99+
producedRow.setField(pos, physicalRow.getField(pos));
100+
}
101+
outputList.add(producedRow);
98102
}
99-
outputList.add(producedRow);
100103
} catch (Exception e) {
101104
if (this.fail_job_on_error) throw e;
102105
Throwable cause =e.getCause();

src/test/java/com/getindata/connectors/http/internal/table/lookup/AsyncHttpTableLookupFunctionTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void shouldEvaluateInAsyncWay() throws InterruptedException {
7979
assertThat(latch.await(3, TimeUnit.SECONDS))
8080
.withFailMessage(
8181
"Future complete in AsyncHttpTableLookupFunction was not called"
82-
+ " for at lest one event.")
82+
+ " for at least one event.")
8383
.isEqualTo(true);
8484

8585
assertThat(result.size()).isEqualTo(rowKeys.length);
@@ -120,7 +120,7 @@ void shouldHandleExceptionOnOneThread() throws InterruptedException {
120120
assertThat(latch.await(3, TimeUnit.SECONDS))
121121
.withFailMessage(
122122
"Future complete in AsyncHttpTableLookupFunction was not called"
123-
+ " for at lest one event.")
123+
+ " for at least one event.")
124124
.isEqualTo(true);
125125

126126
assertThat(wasException).isTrue();
@@ -159,13 +159,13 @@ void shouldHandleEmptyCollectionResult() throws InterruptedException {
159159
assertThat(latch.await(3, TimeUnit.SECONDS))
160160
.withFailMessage(
161161
"Future complete in AsyncHttpTableLookupFunction was not called"
162-
+ " for at lest one event.")
162+
+ " for at least one event.")
163163
.isEqualTo(true);
164164

165165
assertThat(completeCount.get())
166166
.withFailMessage(
167167
"Future complete in AsyncHttpTableLookupFunction was not called"
168-
+ " for at lest one event.")
168+
+ " for at least one event.")
169169
.isEqualTo(rowKeys.length);
170170

171171
// -1 since one will have one empty result.

src/test/java/com/getindata/connectors/http/internal/table/lookup/HttpLookupTableSourceITCaseTest.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.SortedSet;
1010
import java.util.TreeSet;
1111
import java.util.concurrent.TimeUnit;
12+
import java.util.concurrent.TimeoutException;
1213

1314
import com.github.tomakehurst.wiremock.WireMockServer;
1415
import com.github.tomakehurst.wiremock.client.MappingBuilder;
@@ -44,6 +45,7 @@
4445
import static org.assertj.core.api.Assertions.assertThat;
4546
import static org.junit.jupiter.api.Assertions.assertAll;
4647
import static org.junit.jupiter.api.Assertions.assertEquals;
48+
import static org.junit.jupiter.api.Assertions.assertThrows;
4749

4850
@Slf4j
4951
class HttpLookupTableSourceITCaseTest {
@@ -208,7 +210,7 @@ void testHttpLookupJoinWithMetadata(String methodName) throws Exception {
208210
SortedSet<Row> rows = testLookupJoinWithMetadata(lookupTableWithMetadata, 4);
209211

210212
// THEN
211-
assertEnrichedRows(rows);
213+
assertEnrichedRowsWithMetadata(rows);
212214
}
213215

214216
@Test
@@ -238,13 +240,7 @@ void testHttpLookupJoinNoDataFromEndpoint() {
238240
+ ")";
239241

240242
// WHEN/THEN
241-
//assertThrows(TimeoutException.class, () -> testLookupJoin(lookupTable, 4));
242-
try {
243-
testLookupJoin(lookupTable, 4);
244-
} catch (Exception e) {
245-
e.printStackTrace();
246-
throw new RuntimeException("aaabbbb",e);
247-
}
243+
assertThrows(TimeoutException.class, () -> testLookupJoin(lookupTable, 4));
248244
}
249245

250246
@Test
@@ -1035,24 +1031,32 @@ private void createLookupAndSourceTables(String lookupTable, int maxRows) {
10351031
tEnv.executeSql(sourceTable);
10361032
tEnv.executeSql(lookupTable);
10371033
}
1038-
10391034
private void assertEnrichedRows(Collection<Row> collectedRows) {
1035+
assertEnrichedRows(collectedRows, 6);
1036+
}
1037+
1038+
private void assertEnrichedRowsWithMetadata(Collection<Row> collectedRows) {
1039+
assertEnrichedRows(collectedRows, 9);
1040+
}
1041+
1042+
private void assertEnrichedRows(Collection<Row> collectedRows, int rowArity) {
10401043
// validate every row and its column.
10411044
assertAll(() -> {
10421045
assertThat(collectedRows.size()).isEqualTo(4);
10431046
int intElement = 0;
10441047
for (Row row : collectedRows) {
10451048
intElement++;
1046-
assertThat(row.getArity()).isEqualTo(6);
1047-
1048-
// "id" nad "id2" columns should be different for every row.
1049+
assertThat(row.getArity()).isEqualTo(rowArity);
1050+
// "id" and "id2" columns should be different for every row.
10491051
assertThat(row.getField("id")).isEqualTo(String.valueOf(intElement));
10501052
assertThat(row.getField("id2")).isEqualTo(String.valueOf(intElement + 1));
10511053

10521054
assertThat(row.getField("uuid"))
10531055
.isEqualTo("fbb68a46-80a9-46da-9d40-314b5287079c");
10541056
assertThat(row.getField("isActive")).isEqualTo(true);
10551057
assertThat(row.getField("balance")).isEqualTo("$1,729.34");
1058+
// We don't need to assert on the metadata values since they're not part of the test
1059+
// but we could add assertions here if needed
10561060
}
10571061
}
10581062
);
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
import org.apache.flink.configuration.Configuration;
66
import org.apache.flink.configuration.ReadableConfig;
77
import org.jetbrains.annotations.NotNull;
8+
import org.junit.jupiter.api.Test;
89
import static org.assertj.core.api.Assertions.assertThat;
910

1011
import static com.getindata.connectors.http.internal.table.lookup.HttpLookupConnectorOptions.SOURCE_LOOKUP_FAIL_JOB_ON_ERROR;
1112

12-
public class TestHttpTableLookupFunction {
13-
13+
public class HttpTableLookupFunctionTest {
14+
@Test
1415
void testconstructor() {
1516
assertThat(getHttpTableLookupFunction(null).getFail_job_on_error()).isTrue();
1617
assertThat(getHttpTableLookupFunction(true).getFail_job_on_error()).isTrue();
1718
assertThat(getHttpTableLookupFunction(false).getFail_job_on_error()).isFalse();
1819
}
20+
@Test
1921
private static @NotNull HttpTableLookupFunction getHttpTableLookupFunction(Boolean flag) {
2022
ReadableConfig readableConfig;
2123
if (flag == null ) {
@@ -37,4 +39,5 @@ void testconstructor() {
3739
null);
3840
return httpTableLookupFunction;
3941
}
42+
4043
}

0 commit comments

Comments
 (0)