Skip to content

Commit efc6bec

Browse files
authored
feat: changed flush to clean execution history too (#379) (#380)
* feat: changed flush to clean execution history too (#379) * chore: added back TestMethodOrder (for windows agent test) * test: moved throttle tests to suite
1 parent 9d65b0c commit efc6bec

19 files changed

+165
-123
lines changed

src/main/java/com/switcherapi/client/model/SwitcherBuilder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import com.switcherapi.client.exception.SwitcherContextException;
55
import org.apache.commons.lang3.StringUtils;
66

7-
import java.util.ArrayList;
8-
import java.util.List;
9-
import java.util.Objects;
7+
import java.util.*;
108

119
/**
1210
* Builder class that simplifies how input are programmatically wrapped inside the Switcher.
@@ -17,6 +15,8 @@
1715
public abstract class SwitcherBuilder implements Switcher {
1816

1917
protected final SwitcherProperties properties;
18+
19+
protected final Map<List<Entry>, SwitcherResult> historyExecution;
2020

2121
protected long delay;
2222

@@ -32,16 +32,18 @@ public abstract class SwitcherBuilder implements Switcher {
3232

3333
protected SwitcherBuilder(final SwitcherProperties properties) {
3434
this.properties = properties;
35+
this.historyExecution = new HashMap<>();
3536
this.entry = new ArrayList<>();
3637
this.delay = 0;
3738
}
3839

3940
/**
40-
* Clear all entries previously added
41+
* Clear all entries previously added and history of executions.
4142
*
4243
* @return {@link SwitcherBuilder}
4344
*/
4445
public SwitcherBuilder flush() {
46+
this.historyExecution.clear();
4547
this.entry.clear();
4648
return this;
4749
}

src/main/java/com/switcherapi/client/model/SwitcherRequest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ public final class SwitcherRequest extends SwitcherBuilder {
2323
private final SwitcherExecutor switcherExecutor;
2424

2525
private final String switcherKey;
26-
27-
private final Map<List<Entry>, SwitcherResult> historyExecution;
2826

2927
private AsyncSwitcher asyncSwitcher;
3028

@@ -41,7 +39,6 @@ public SwitcherRequest(final String switcherKey,
4139
super(switcherProperties);
4240
this.switcherExecutor = switcherExecutor;
4341
this.switcherKey = switcherKey;
44-
this.historyExecution = new HashMap<>();
4542
}
4643

4744
@Override

src/test/java/com/switcherapi/client/SwitcherBasicCriteriaResponseTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.io.IOException;
1717

18+
import static com.switcherapi.client.remote.Constants.DEFAULT_ENV;
1819
import static org.junit.jupiter.api.Assertions.*;
1920

2021
class SwitcherBasicCriteriaResponseTest extends MockWebServerHelper {
@@ -31,7 +32,7 @@ static void setup() throws IOException {
3132
.local(false)
3233
.snapshotLocation(null)
3334
.snapshotSkipValidation(false)
34-
.environment("default")
35+
.environment(DEFAULT_ENV)
3536
.silentMode(null)
3637
.snapshotAutoLoad(false)
3738
.snapshotAutoUpdateInterval(null));

src/test/java/com/switcherapi/client/SwitcherBasicTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.io.IOException;
1313

14+
import static com.switcherapi.client.remote.Constants.DEFAULT_ENV;
1415
import static org.junit.jupiter.api.Assertions.assertFalse;
1516
import static org.junit.jupiter.api.Assertions.assertTrue;
1617

@@ -28,7 +29,7 @@ static void setup() throws IOException {
2829
.local(false)
2930
.snapshotLocation(null)
3031
.snapshotSkipValidation(false)
31-
.environment("default")
32+
.environment(DEFAULT_ENV)
3233
.silentMode(null)
3334
.snapshotAutoLoad(false)
3435
.snapshotAutoUpdateInterval(null));

src/test/java/com/switcherapi/client/SwitcherContextBuilderTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import static com.switcherapi.SwitchersBase.*;
1313
import static com.switcherapi.client.SwitcherContextValidator.ERR_LOCAL;
14+
import static com.switcherapi.client.remote.Constants.DEFAULT_ENV;
1415
import static org.junit.jupiter.api.Assertions.*;
1516

1617
class SwitcherContextBuilderTest {
@@ -26,7 +27,7 @@ void shouldReturnSuccess() {
2627
.apiKey("API_KEY")
2728
.domain("switcher-domain")
2829
.component("switcher-client")
29-
.environment("default")
30+
.environment(DEFAULT_ENV)
3031
.snapshotLocation(SNAPSHOTS_LOCAL)
3132
.local(true));
3233

@@ -46,7 +47,7 @@ void shouldReturnError_snapshotNotLoaded() {
4647
.apiKey("API_KEY")
4748
.domain("switcher-domain")
4849
.component("switcher-client")
49-
.environment("default")
50+
.environment(DEFAULT_ENV)
5051
.snapshotLocation(null)
5152
.local(true));
5253

src/test/java/com/switcherapi/client/SwitcherContextRemoteExecutorTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.io.IOException;
1313

14+
import static com.switcherapi.client.remote.Constants.DEFAULT_ENV;
1415
import static org.junit.jupiter.api.Assertions.*;
1516

1617
class SwitcherContextRemoteExecutorTest extends MockWebServerHelper {
@@ -40,7 +41,7 @@ void shouldConfigureRemotePoolSize() {
4041
.apiKey("API_KEY")
4142
.domain("switcher-domain")
4243
.component("switcher-client-pool-test")
43-
.environment("default")
44+
.environment(DEFAULT_ENV)
4445
.poolConnectionSize(1)
4546
.local(false));
4647

@@ -66,7 +67,7 @@ void shouldConfigureRemoteTimeout() {
6667
.apiKey("API_KEY")
6768
.domain("switcher-domain")
6869
.component("switcher-client-timeout-test")
69-
.environment("default")
70+
.environment(DEFAULT_ENV)
7071
.timeoutMs(500)
7172
.local(false));
7273

src/test/java/com/switcherapi/client/SwitcherFail1Test.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.io.IOException;
1616

17+
import static com.switcherapi.client.remote.Constants.DEFAULT_ENV;
1718
import static org.junit.jupiter.api.Assertions.*;
1819

1920
class SwitcherFail1Test extends MockWebServerHelper {
@@ -43,7 +44,7 @@ void resetSwitcherContextState() {
4344
.local(false)
4445
.snapshotLocation(null)
4546
.snapshotSkipValidation(false)
46-
.environment("default")
47+
.environment(DEFAULT_ENV)
4748
.silentMode(null)
4849
.snapshotAutoLoad(false)
4950
.snapshotAutoUpdateInterval(null));

src/test/java/com/switcherapi/client/SwitcherFail2Test.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import java.io.IOException;
1515

16+
import static com.switcherapi.client.remote.Constants.DEFAULT_ENV;
1617
import static org.junit.jupiter.api.Assertions.assertEquals;
1718
import static org.junit.jupiter.api.Assertions.assertThrows;
1819

@@ -40,7 +41,7 @@ void resetSwitcherContextState() {
4041
.local(false)
4142
.snapshotLocation(null)
4243
.snapshotSkipValidation(false)
43-
.environment("default")
44+
.environment(DEFAULT_ENV)
4445
.silentMode(null)
4546
.snapshotAutoLoad(false)
4647
.snapshotAutoUpdateInterval(null));

src/test/java/com/switcherapi/client/SwitcherSilentModeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.IOException;
1515
import java.nio.file.Paths;
1616

17+
import static com.switcherapi.client.remote.Constants.DEFAULT_ENV;
1718
import static org.junit.jupiter.api.Assertions.assertTrue;
1819

1920
class SwitcherSilentModeTest extends MockWebServerHelper {
@@ -41,7 +42,7 @@ void resetSwitcherContextState() {
4142
.local(false)
4243
.snapshotLocation(null)
4344
.snapshotSkipValidation(false)
44-
.environment("default")
45+
.environment(DEFAULT_ENV)
4546
.silentMode(null)
4647
.snapshotAutoLoad(false)
4748
.snapshotAutoUpdateInterval(null));

src/test/java/com/switcherapi/client/SwitcherSnapshotLookupTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.nio.file.Files;
1515
import java.nio.file.Paths;
1616

17+
import static com.switcherapi.client.remote.Constants.DEFAULT_ENV;
1718
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
1819
import static org.junit.jupiter.api.Assertions.assertThrows;
1920

@@ -52,7 +53,7 @@ void resetSwitcherContextState() {
5253
.local(false)
5354
.snapshotLocation(null)
5455
.snapshotSkipValidation(false)
55-
.environment("default")
56+
.environment(DEFAULT_ENV)
5657
.silentMode(null)
5758
.snapshotAutoLoad(false)
5859
.snapshotAutoUpdateInterval(null));

0 commit comments

Comments
 (0)