Skip to content

Commit 9ccde43

Browse files
committed
Ref #29447: add more tests
1 parent 8c73969 commit 9ccde43

14 files changed

Lines changed: 523 additions & 82 deletions

src/main/java/eu/openanalytics/containerproxy/backend/dispatcher/proxysharing/IDelegateProxyStore.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@
2121
package eu.openanalytics.containerproxy.backend.dispatcher.proxysharing;
2222

2323
import eu.openanalytics.containerproxy.backend.dispatcher.proxysharing.store.DelegateProxy;
24+
import eu.openanalytics.containerproxy.backend.dispatcher.proxysharing.store.DelegateProxyStatus;
2425

2526
import java.util.Collection;
27+
import java.util.stream.Stream;
2628

2729
public interface IDelegateProxyStore {
2830

2931
Collection<DelegateProxy> getAllDelegateProxies();
3032

33+
default Stream<DelegateProxy> getAllDelegateProxies(DelegateProxyStatus delegateProxyStatus) {
34+
return getAllDelegateProxies().stream().filter(it -> it.getDelegateProxyStatus().equals(delegateProxyStatus));
35+
}
36+
3137
void addDelegateProxy(DelegateProxy delegateProxy);
3238

3339
void removeDelegateProxy(String delegateProxyId);

src/main/java/eu/openanalytics/containerproxy/backend/dispatcher/proxysharing/ProxySharingScaler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public class ProxySharingScaler {
9393
private final Logger logger = LoggerFactory.getLogger(getClass());
9494
private final ProxySpec proxySpec;
9595
private final String proxySpecHash;
96-
private ReconcileStatus lastReconcileStatus = ReconcileStatus.Stable;
96+
protected ReconcileStatus lastReconcileStatus = ReconcileStatus.Stable;
9797
private Instant lastScaleUp = null;
9898

9999
@Inject
@@ -640,7 +640,7 @@ private void log(Seat seat, String message) {
640640
logger.info("[{} {} {}] " + message, kv("specId", proxySpec.getId()), kv("delegateProxyId", seat.getDelegateProxyId()), kv("seatId", seat.getId()));
641641
}
642642

643-
private enum ReconcileStatus {
643+
public enum ReconcileStatus {
644644
Stable,
645645
ScaleUp,
646646
ScaleDown

src/main/java/eu/openanalytics/containerproxy/backend/dispatcher/proxysharing/store/redis/RedisDelegateProxyStore.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import eu.openanalytics.containerproxy.backend.dispatcher.proxysharing.IDelegateProxyStore;
2424
import eu.openanalytics.containerproxy.backend.dispatcher.proxysharing.store.DelegateProxy;
25+
import eu.openanalytics.containerproxy.backend.dispatcher.proxysharing.store.DelegateProxyStatus;
2526
import org.springframework.data.redis.core.BoundHashOperations;
2627

2728
import java.util.Collection;

src/main/java/eu/openanalytics/containerproxy/service/session/redis/RedisSessionService.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.commons.logging.LogFactory;
3131
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
3232
import org.springframework.data.redis.core.RedisTemplate;
33+
import org.springframework.scheduling.annotation.Scheduled;
3334
import org.springframework.security.core.Authentication;
3435
import org.springframework.security.core.context.SecurityContext;
3536
import org.springframework.session.Session;
@@ -41,8 +42,6 @@
4142
import java.time.Instant;
4243
import java.util.HashSet;
4344
import java.util.Set;
44-
import java.util.Timer;
45-
import java.util.TimerTask;
4645
import java.util.regex.Matcher;
4746
import java.util.regex.Pattern;
4847

@@ -71,12 +70,6 @@ public class RedisSessionService extends AbstractSessionService {
7170
public void init() {
7271
keyPattern = redisSessionConfig.getRedisNamespace() + ":sessions:*";
7372
redisTemplate = (RedisTemplate<String, Object>) redisIndexedSessionRepository.getSessionRedisOperations();
74-
new Timer().schedule(new TimerTask() {
75-
@Override
76-
public void run() {
77-
updateCachedUsersLoggedInCount();
78-
}
79-
}, 0, CACHE_UPDATE_INTERVAL);
8073
}
8174

8275
@Override
@@ -112,6 +105,7 @@ public String extractSessionIdFromExchange(HttpServerExchange exchange) {
112105
* using an HTTP request.
113106
* See the warning at https://redis.io/commands/keys .
114107
*/
108+
@Scheduled(fixedDelay = CACHE_UPDATE_INTERVAL)
115109
private void updateCachedUsersLoggedInCount() {
116110
Set<String> keys = redisTemplate.keys(keyPattern);
117111

src/main/java/eu/openanalytics/containerproxy/service/session/undertow/UndertowSessionService.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@
3030
import org.apache.commons.logging.Log;
3131
import org.apache.commons.logging.LogFactory;
3232
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
33+
import org.springframework.scheduling.annotation.Scheduled;
3334
import org.springframework.security.core.Authentication;
3435
import org.springframework.security.core.context.SecurityContext;
3536
import org.springframework.stereotype.Component;
3637

37-
import javax.annotation.PostConstruct;
3838
import javax.inject.Inject;
3939
import java.time.Instant;
4040
import java.util.HashSet;
4141
import java.util.Set;
42-
import java.util.Timer;
43-
import java.util.TimerTask;
4442

4543
@Component
4644
@ConditionalOnProperty(name = "spring.session.store-type", havingValue = "none")
@@ -58,16 +56,6 @@ public class UndertowSessionService extends AbstractSessionService {
5856

5957
private Integer cachedActiveUsersCount = null;
6058

61-
@PostConstruct
62-
public void init() {
63-
new Timer().schedule(new TimerTask() {
64-
@Override
65-
public void run() {
66-
updateCachedUsersLoggedInCount();
67-
}
68-
}, 0, CACHE_UPDATE_INTERVAL);
69-
}
70-
7159
@Override
7260
public Integer getLoggedInUsersCount() {
7361
return cachedUsersLoggedInCount;
@@ -111,6 +99,7 @@ public String extractSessionIdFromExchange(HttpServerExchange exchange) {
11199
* {@link eu.openanalytics.containerproxy.service.session.redis.RedisSessionService}, but still it needs to loop
112100
* over all sessions in the Servlet).
113101
*/
102+
@Scheduled(fixedDelay = CACHE_UPDATE_INTERVAL)
114103
private void updateCachedUsersLoggedInCount() {
115104
InMemorySessionManager instance = this.customInMemorySessionManagerFactory.getInstance();
116105
if (instance == null) {

src/test/java/eu/openanalytics/containerproxy/test/helpers/NotInternalOnlyTestStrategy.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public boolean testProxy(Proxy proxy) {
5353
}
5454
log.warn(proxy, "Error during test strategy test: status code: " + responseCode);
5555
} catch (Exception e) {
56-
log.warn(proxy, e, "Exception during test strategy");
5756
return false;
5857
}
5958
return false;

src/test/java/eu/openanalytics/containerproxy/test/helpers/ShinyProxyClient.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ public ShinyProxyClient(String usernameAndPassword, int port) {
5959
}
6060

6161
public String startProxy(String specId) {
62-
return startProxy(specId, null);
62+
return startProxy(specId, null, true);
6363
}
6464

6565
public String startProxy(String specId, Map<String, String> parameters) {
66+
return startProxy(specId, parameters, true);
67+
}
68+
69+
public String startProxy(String specId, Map<String, String> parameters, boolean wait) {
6670
RequestBody body = RequestBody.create("", null);
6771
if (parameters != null) {
6872
ObjectMapper objectMapper = new ObjectMapper();
@@ -82,9 +86,11 @@ public String startProxy(String specId, Map<String, String> parameters) {
8286

8387
JsonObject response = call(request, 201);
8488
String id = response.getJsonObject("data").getString("id");
85-
ProxyStatus proxyStatus = waitForProxyStatus(id);
86-
if (proxyStatus != ProxyStatus.Up) {
87-
throw new TestHelperException(String.format("Proxy with id %s failed to reach Up status", id));
89+
if (wait) {
90+
ProxyStatus proxyStatus = waitForProxyStatus(id);
91+
if (proxyStatus != ProxyStatus.Up) {
92+
throw new TestHelperException(String.format("Proxy with id %s failed to reach Up status", id));
93+
}
8894
}
8995
return id;
9096
}

src/test/java/eu/openanalytics/containerproxy/test/helpers/TestProxySharingScaler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ public ISeatStore getSeatStore() {
5656
return seatStore;
5757
}
5858

59+
public ProxySharingScaler.ReconcileStatus getLastReconcileStatus() {
60+
return lastReconcileStatus;
61+
}
62+
5963
}

0 commit comments

Comments
 (0)