Skip to content

Commit

Permalink
fixup: extract consts
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert committed Sep 25, 2024
1 parent b6af7ec commit 3186010
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.openfeature.contrib.providers.flagd.resolver.grpc;

/**
* Constants for evaluation proto.
*/
public class Constants {
public static final String CONFIGURATION_CHANGE = "configuration_change";
public static final String PROVIDER_READY = "provider_ready";
public static final String FLAGS_KEY = "flags";
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ class EventStreamObserver implements StreamObserver<EventStreamResponse> {
private final Object sync;
private final Cache cache;

public static final String CONFIGURATION_CHANGE = "configuration_change";
public static final String PROVIDER_READY = "provider_ready";
static final String FLAGS_KEY = "flags";

/**
* Create a gRPC stream that get notified about flag changes.
*
Expand All @@ -44,10 +40,10 @@ class EventStreamObserver implements StreamObserver<EventStreamResponse> {
@Override
public void onNext(EventStreamResponse value) {
switch (value.getType()) {
case CONFIGURATION_CHANGE:
case Constants.CONFIGURATION_CHANGE:
this.handleConfigurationChangeEvent(value);
break;
case PROVIDER_READY:
case Constants.PROVIDER_READY:
this.handleProviderReadyEvent();
break;
default:
Expand Down Expand Up @@ -83,7 +79,7 @@ private void handleConfigurationChangeEvent(EventStreamResponse value) {
boolean cachingEnabled = this.cache.getEnabled();

Map<String, Value> data = value.getData().getFieldsMap();
Value flagsValue = data.get(FLAGS_KEY);
Value flagsValue = data.get(Constants.FLAGS_KEY);
if (flagsValue == null) {
if (cachingEnabled) {
this.cache.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void cacheBustingForKnownKeys() {
Value flagsValue = mock(Value.class);
Struct flagsStruct = mock(Struct.class);
HashMap<String, Value> fields = new HashMap<>();
fields.put(EventStreamObserver.FLAGS_KEY, flagsValue);
fields.put(Constants.FLAGS_KEY, flagsValue);
HashMap<String, Value> flags = new HashMap<>();
flags.put(key1, null);
flags.put(key2, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
Expand All @@ -19,9 +18,6 @@
import static org.mockito.Mockito.when;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

import org.junit.jupiter.api.Test;
Expand All @@ -40,7 +36,6 @@
import dev.openfeature.flagd.grpc.evaluation.ServiceGrpc;
import dev.openfeature.flagd.grpc.evaluation.ServiceGrpc.ServiceBlockingStub;
import dev.openfeature.flagd.grpc.evaluation.ServiceGrpc.ServiceStub;
import dev.openfeature.sdk.internal.TriConsumer;
import io.grpc.Channel;
import io.grpc.netty.NettyChannelBuilder;
import io.netty.channel.EventLoopGroup;
Expand Down Expand Up @@ -104,7 +99,7 @@ void initialization_succeed_with_connected_status() throws NoSuchFieldException,
doAnswer((InvocationOnMock invocation) -> {
EventStreamObserver eventStreamObserver = (EventStreamObserver) invocation.getArgument(1);
eventStreamObserver
.onNext(EventStreamResponse.newBuilder().setType(EventStreamObserver.PROVIDER_READY).build());
.onNext(EventStreamResponse.newBuilder().setType(Constants.PROVIDER_READY).build());
return null;
}).when(mockStub).eventStream(any(), any());

Expand Down

0 comments on commit 3186010

Please sign in to comment.