Skip to content

Commit

Permalink
Merge branch 'main' into feat/gherkin-rework
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Schrottner <[email protected]>
  • Loading branch information
aepfli committed Jan 15, 2025
2 parents 2b81d5b + 514004f commit 0328d1b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 67 deletions.
5 changes: 4 additions & 1 deletion providers/flagd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>1.5.4</version>
<version>1.5.5</version>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -155,12 +155,15 @@
<version>1.20.4</version>
<scope>test</scope>
</dependency>
<!-- uncomment for logoutput during test runs -->
<!--
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.16</version>
<scope>test</scope>
</dependency>
-->
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public synchronized void initialize(EvaluationContext evaluationContext) throws
this.flagResolver.init();
// block till ready - this works with deadline fine for rpc, but with in_process we also need to take parsing
// into the equation
Util.busyWaitAndCheck(this.deadline + 1000, () -> initialized);
// TODO: evaluate where we are losing time, so we can remove this magic number - follow up
Util.busyWaitAndCheck(this.deadline + 200, () -> initialized);
}

@Override
Expand Down Expand Up @@ -184,6 +185,7 @@ EvaluationContext getEnrichedContext() {
return enrichedContext;
}

@SuppressWarnings("checkstyle:fallthrough")
private void onProviderEvent(FlagdProviderEvent flagdProviderEvent) {

syncMetadata = flagdProviderEvent.getSyncMetadata();
Expand Down Expand Up @@ -211,6 +213,8 @@ private void onProviderEvent(FlagdProviderEvent flagdProviderEvent) {
}
previousEvent = ProviderEvent.PROVIDER_ERROR;
break;
default:
log.info("Unknown event {}", flagdProviderEvent.getEvent());
}
}

Expand Down Expand Up @@ -247,7 +251,6 @@ private void onError() {
this.emitProviderError(ProviderEventDetails.builder()
.message("there has been an error")
.build());
;
},
gracePeriod,
TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@ public void shutdown() throws InterruptedException {
}
}

private synchronized void onInitialConnect() {
connected = true;
restartStream();
}

/**
* Handles the event when the GRPC channel becomes ready, marking the connection as established.
* Cancels any pending reconnection task and restarts the event stream.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.steps")
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.picocontainer.PicoFactory")
@IncludeTags({"rpc"})
@ExcludeTags({"targetURI"})
@ExcludeTags({"targetURI", "unixsocket"})
@Testcontainers
public class RunRpcTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,13 @@ public class ProviderSteps extends AbstractSteps {

public static final int UNAVAILABLE_PORT = 9999;
static Map<ProviderType, FlagdContainer> containers = new HashMap<>();
static Map<ProviderType, Map<Config.Resolver, String>> proxyports = new HashMap<>();
public static Network network = Network.newNetwork();
public static ToxiproxyContainer toxiproxy =
new ToxiproxyContainer("ghcr.io/shopify/toxiproxy:2.5.0").withNetwork(network);
public static ToxiproxyClient toxiproxyClient;

static Path sharedTempDir;

static {
try {
sharedTempDir = Files.createDirectories(
Paths.get("tmp/" + RandomStringUtils.randomAlphanumeric(8).toLowerCase() + "/"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private Timer restartTimer;

public ProviderSteps(State state) {
super(state);
}
Expand All @@ -83,6 +71,8 @@ public static void beforeAll() throws IOException {
ProviderType.DEFAULT, new FlagdContainer().withNetwork(network).withNetworkAliases("default"));
containers.put(
ProviderType.SSL, new FlagdContainer("ssl").withNetwork(network).withNetworkAliases("ssl"));
sharedTempDir = Files.createDirectories(
Paths.get("tmp/" + RandomStringUtils.randomAlphanumeric(8).toLowerCase() + "/"));
containers.put(
ProviderType.SOCKET,
new FlagdContainer("socket")
Expand Down Expand Up @@ -209,7 +199,7 @@ public void run() {
}
}
};
restartTimer = new Timer("Timer" + randomizer);
Timer restartTimer = new Timer("Timer" + randomizer);

restartTimer.schedule(task, seconds * 1000L);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
package dev.openfeature.contrib.providers.flagd.resolver.grpc;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.google.protobuf.Struct;
import dev.openfeature.flagd.grpc.evaluation.Evaluation.EventStreamResponse;
import dev.openfeature.sdk.ProviderEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

class EventStreamObserverTest {

/* @Nested
@Nested
class StateChange {

Cache cache;
List<Boolean> states;
List<ProviderEvent> states;
EventStreamObserver stream;
Runnable reconnect;
Object sync;

@BeforeEach
void setUp() {
states = new ArrayList<>();
cache = mock(Cache.class);
reconnect = mock(Runnable.class);
when(cache.getEnabled()).thenReturn(true);
stream = new EventStreamObserver(cache, (state, changed) -> states.add(state));
stream = new EventStreamObserver(
(state) -> states.add(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED),
(state) -> states.add(state.getEvent()));
}

@Test
Expand All @@ -29,42 +42,7 @@ public void change() {
when(flagData.getFieldsMap()).thenReturn(new HashMap<>());
stream.onNext(resp);
// we notify that we are ready
assertEquals(1, states.size());
assertTrue(states.get(0));
// we flush the cache
verify(cache, atLeast(1)).clear();
}
@Test
public void cacheBustingForKnownKeys() {
final String key1 = "myKey1";
final String key2 = "myKey2";
EventStreamResponse resp = mock(EventStreamResponse.class);
Struct flagData = mock(Struct.class);
Value flagsValue = mock(Value.class);
Struct flagsStruct = mock(Struct.class);
HashMap<String, Value> fields = new HashMap<>();
fields.put(Constants.FLAGS_KEY, flagsValue);
HashMap<String, Value> flags = new HashMap<>();
flags.put(key1, null);
flags.put(key2, null);
when(resp.getType()).thenReturn("configuration_change");
when(resp.getData()).thenReturn(flagData);
when(flagData.getFieldsMap()).thenReturn(fields);
when(flagsValue.getStructValue()).thenReturn(flagsStruct);
when(flagsStruct.getFieldsMap()).thenReturn(flags);
stream.onNext(resp);
// we notify that the configuration changed
assertEquals(1, states.size());
assertTrue(states.get(0));
// we did NOT flush the whole cache
verify(cache, atMost(0)).clear();
// we only clean the two keys
verify(cache, times(1)).remove(eq(key1));
verify(cache, times(1)).remove(eq(key2));
assertThat(states).hasSize(1).contains(ProviderEvent.PROVIDER_CONFIGURATION_CHANGED);
}
}*/
}
}
2 changes: 0 additions & 2 deletions providers/flagd/src/test/resources/simplelogger.properties

This file was deleted.

0 comments on commit 0328d1b

Please sign in to comment.