Skip to content

Commit

Permalink
Serving should not throw exception when key not found in Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
khorshuheng committed Mar 19, 2020
1 parent e9069a8 commit 4bee000
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ private List<byte[]> sendMultiGet(List<RedisKey> keys) {
.collect(Collectors.toList())
.toArray(new byte[0][0]);
return syncCommands.mget(binaryKeys).stream()
.map(io.lettuce.core.Value::getValue)
.map(keyValue -> keyValue.getValueOrElse(null))
.collect(Collectors.toList());
} catch (Exception e) {
throw Status.NOT_FOUND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,39 +377,29 @@ public void shouldReturnResponseWithUnsetValuesIfKeysNotPresent() {
.putFields("entity2", strValue("b")))
.build();

List<FeatureRow> featureRows =
Lists.newArrayList(
FeatureRow.newBuilder()
.setEventTimestamp(Timestamp.newBuilder().setSeconds(100))
.addAllFields(
Lists.newArrayList(
Field.newBuilder().setName("entity1").setValue(intValue(1)).build(),
Field.newBuilder().setName("entity2").setValue(strValue("a")).build(),
Field.newBuilder().setName("feature1").setValue(intValue(1)).build(),
Field.newBuilder().setName("feature2").setValue(intValue(1)).build()))
.setFeatureSet("featureSet:1")
.build(),
FeatureRow.newBuilder()
.setEventTimestamp(Timestamp.newBuilder())
.addAllFields(
Lists.newArrayList(
Field.newBuilder().setName("entity1").setValue(intValue(2)).build(),
Field.newBuilder().setName("entity2").setValue(strValue("b")).build(),
Field.newBuilder().setName("feature1").build(),
Field.newBuilder().setName("feature2").build()))
.setFeatureSet("featureSet:1")
.build());

FeatureSetRequest featureSetRequest =
FeatureSetRequest.newBuilder()
.addAllFeatureReferences(request.getFeaturesList())
.setSpec(getFeatureSetSpec())
.build();

FeatureRow featureRowPresent =
FeatureRow.newBuilder()
.setEventTimestamp(Timestamp.newBuilder().setSeconds(100))
.addAllFields(
Lists.newArrayList(
Field.newBuilder().setName("entity1").setValue(intValue(1)).build(),
Field.newBuilder().setName("entity2").setValue(strValue("a")).build(),
Field.newBuilder().setName("feature1").setValue(intValue(1)).build(),
Field.newBuilder().setName("feature2").setValue(intValue(1)).build()))
.setFeatureSet("featureSet:1")
.build();

List<KeyValue<byte[], byte[]>> featureRowBytes =
featureRows.stream()
.map(x -> KeyValue.from(new byte[1], Optional.of(x.toByteArray())))
.collect(Collectors.toList());
Lists.newArrayList(
KeyValue.from(new byte[1], Optional.of(featureRowPresent.toByteArray())),
KeyValue.from(new byte[1], Optional.empty()));

when(specService.getFeatureSets(request.getFeaturesList()))
.thenReturn(Collections.singletonList(featureSetRequest));
when(connection.sync()).thenReturn(syncCommands);
Expand Down

0 comments on commit 4bee000

Please sign in to comment.