Skip to content

Commit

Permalink
refactor: move remaining config out of service
Browse files Browse the repository at this point in the history
  • Loading branch information
jbutler committed Sep 22, 2022
1 parent f5fe618 commit d264ae1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ public class ClientDevicesAuthService extends PluginService {

// TODO: Move configuration related constants to appropriate configuration class
public static final String DEVICE_GROUPS_TOPICS = "deviceGroups";
public static final String PERFORMANCE_TOPIC = "performance";
public static final String MAX_ACTIVE_AUTH_TOKENS_TOPIC = "maxActiveAuthTokens";
public static final String CLOUD_REQUEST_QUEUE_SIZE_TOPIC = "cloudRequestQueueSize";
public static final String MAX_CONCURRENT_CLOUD_REQUESTS_TOPIC = "maxConcurrentCloudRequests";
public static final int DEFAULT_MAX_ACTIVE_AUTH_TOKENS = 2500;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@

import java.util.concurrent.atomic.AtomicInteger;

import static com.aws.greengrass.clientdevices.auth.ClientDevicesAuthService.DEFAULT_MAX_ACTIVE_AUTH_TOKENS;
import static com.aws.greengrass.clientdevices.auth.ClientDevicesAuthService.MAX_ACTIVE_AUTH_TOKENS_TOPIC;
import static com.aws.greengrass.clientdevices.auth.ClientDevicesAuthService.PERFORMANCE_TOPIC;

@SuppressWarnings("PMD.DataClass")
public class SessionConfig {
private static final Logger LOGGER = LogManager.getLogger(SessionConfig.class);
public static final int DEFAULT_SESSION_CAPACITY = DEFAULT_MAX_ACTIVE_AUTH_TOKENS;
public static final int DEFAULT_SESSION_CAPACITY = 2500;
// valid session capacity should be within range [1, Integer.MAX_VALUE)
// to be able to initialize and perform appropriate eviction check in LRU session cache
public static final int MIN_SESSION_CAPACITY = 1;
public static final int MAX_SESSION_CAPACITY = Integer.MAX_VALUE - 1;

public static final String PERFORMANCE_TOPIC = "performance";
public static final String MAX_ACTIVE_AUTH_TOKENS_TOPIC = "maxActiveAuthTokens";

private final AtomicInteger sessionCapacity = new AtomicInteger(DEFAULT_SESSION_CAPACITY);

private final Topics configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static com.aws.greengrass.clientdevices.auth.ClientDevicesAuthService.MAX_ACTIVE_AUTH_TOKENS_TOPIC;
import static com.aws.greengrass.clientdevices.auth.ClientDevicesAuthService.PERFORMANCE_TOPIC;
import static com.aws.greengrass.lifecyclemanager.GreengrassService.RUNTIME_STORE_NAMESPACE_TOPIC;
import static com.aws.greengrass.testcommons.testutilities.ExceptionLogProtector.ignoreExceptionOfType;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -393,13 +391,6 @@ void GIVEN_certificateAuthorityConfiguration_WHEN_itChanges_THEN_CAisConfigured(
kernel.getContext().waitForPublishQueueToClear();
verify(managedCAUseCase, times(1)).apply(configurationCaptor.capture());
verify(customCAUseCase, times(2)).apply(configurationCaptor.capture());

topics.lookup(KernelConfigResolver.CONFIGURATION_CONFIG_KEY,PERFORMANCE_TOPIC, MAX_ACTIVE_AUTH_TOKENS_TOPIC)
.withValue(2);

kernel.getContext().waitForPublishQueueToClear();
verify(managedCAUseCase, times(1)).apply(configurationCaptor.capture());
verify(customCAUseCase, times(2)).apply(configurationCaptor.capture());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import java.io.IOException;

import static com.aws.greengrass.componentmanager.KernelConfigResolver.CONFIGURATION_CONFIG_KEY;
import static com.aws.greengrass.clientdevices.auth.ClientDevicesAuthService.DEFAULT_MAX_ACTIVE_AUTH_TOKENS;
import static com.aws.greengrass.clientdevices.auth.ClientDevicesAuthService.MAX_ACTIVE_AUTH_TOKENS_TOPIC;
import static com.aws.greengrass.clientdevices.auth.ClientDevicesAuthService.PERFORMANCE_TOPIC;
import static com.aws.greengrass.clientdevices.auth.session.SessionConfig.DEFAULT_SESSION_CAPACITY;
import static com.aws.greengrass.clientdevices.auth.session.SessionConfig.PERFORMANCE_TOPIC;
import static com.aws.greengrass.clientdevices.auth.session.SessionConfig.MAX_ACTIVE_AUTH_TOKENS_TOPIC;
import static com.aws.greengrass.clientdevices.auth.session.SessionConfig.MAX_SESSION_CAPACITY;
import static com.aws.greengrass.clientdevices.auth.session.SessionConfig.MIN_SESSION_CAPACITY;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -44,12 +44,12 @@ void afterEach() throws IOException {

@Test
public void GIVEN_no_configured_capacity_WHEN_getSessionCapacity_THEN_returns_default_capacity() {
assertThat(sessionConfig.getSessionCapacity(), is(equalTo(DEFAULT_MAX_ACTIVE_AUTH_TOKENS)));
assertThat(sessionConfig.getSessionCapacity(), is(equalTo(DEFAULT_SESSION_CAPACITY)));
}

@Test
public void GIVEN_default_session_capacity_WHEN_update_configuration_THEN_returns_updated_capacity() {
assertThat(sessionConfig.getSessionCapacity(), is(equalTo(DEFAULT_MAX_ACTIVE_AUTH_TOKENS)));
assertThat(sessionConfig.getSessionCapacity(), is(equalTo(DEFAULT_SESSION_CAPACITY)));
int newCapacity = 1;
configurationTopics.lookup(PERFORMANCE_TOPIC, MAX_ACTIVE_AUTH_TOKENS_TOPIC)
.withValue(newCapacity);
Expand Down

0 comments on commit d264ae1

Please sign in to comment.