-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitcherContextRemoteExecutorTest.java
More file actions
88 lines (70 loc) · 2.49 KB
/
SwitcherContextRemoteExecutorTest.java
File metadata and controls
88 lines (70 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.switcherapi.client;
import com.switcherapi.Switchers;
import com.switcherapi.SwitchersBase;
import com.switcherapi.client.exception.SwitcherRemoteException;
import com.switcherapi.client.model.SwitcherRequest;
import com.switcherapi.client.service.WorkerName;
import com.switcherapi.fixture.MockWebServerHelper;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import static com.switcherapi.client.remote.Constants.DEFAULT_ENV;
import static org.junit.jupiter.api.Assertions.*;
class SwitcherContextRemoteExecutorTest extends MockWebServerHelper {
@BeforeAll
static void setup() throws IOException {
MockWebServerHelper.setupMockServer();
}
@AfterAll
static void tearDown() {
MockWebServerHelper.tearDownMockServer();
}
@Test
void shouldConfigureRemotePoolSize() {
//auth
givenResponse(generateMockAuth(10));
//criteria
givenResponse(generateCriteriaResponse("true", false));
//given
SwitchersBase.configure(ContextBuilder.builder(true)
.context(SwitchersBase.class.getName())
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
.apiKey("API_KEY")
.domain("switcher-domain")
.component("switcher-client-pool-test")
.environment(DEFAULT_ENV)
.poolConnectionSize(1)
.local(false));
SwitchersBase.initializeClient();
//test
SwitcherRequest switcher = SwitchersBase.getSwitcher(Switchers.USECASE11);
assertTrue(switcher.isItOn());
//assert pool size
long count = Thread.getAllStackTraces().keySet().stream().filter(thread ->
thread.getName().contains(String.format("%s-%s", WorkerName.SWITCHER_REMOTE_WORKER, "switcher-client-pool-test"))).count();
assertEquals(1, count);
}
@Test
void shouldConfigureRemoteTimeout() {
//auth
givenResponse(generateMockAuth(10));
//criteria
givenResponse(generateTimeOut(1000));
//given
SwitchersBase.configure(ContextBuilder.builder(true)
.context(SwitchersBase.class.getName())
.url(String.format("http://localhost:%s", mockBackEnd.getPort()))
.apiKey("API_KEY")
.domain("switcher-domain")
.component("switcher-client-timeout-test")
.environment(DEFAULT_ENV)
.timeoutMs(500)
.local(false));
SwitchersBase.initializeClient();
//test
SwitcherRequest switcher = SwitchersBase.getSwitcher(Switchers.USECASE11);
Exception ex = assertThrows(SwitcherRemoteException.class, switcher::isItOn);
assertEquals("request timed out", ex.getCause().getMessage());
}
}