Skip to content

Commit

Permalink
chore: refactor DeviceConfiguration to remove kernel as a class varia…
Browse files Browse the repository at this point in the history
…ble (#1609)
  • Loading branch information
tiancishen authored Apr 25, 2024
1 parent 33e688a commit 54207c3
Show file tree
Hide file tree
Showing 16 changed files with 494 additions and 553 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public static void setDefaultRunWithUser(Kernel kernel) {
if (Platform.getInstance() instanceof DarwinPlatform) {
user = System.getProperty("user.name");
}
new DeviceConfiguration(kernel).getRunWithDefaultPosixUser().dflt(user);
new DeviceConfiguration(kernel.getConfig(), kernel.getKernelCommandLine()).getRunWithDefaultPosixUser().dflt(user);
}

protected void initKernel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void afterEach() {
@Test
void GIVEN_one_component_errored_and_recovered_THEN_fss_should_send_recovery_message() throws Exception {
statusChange = new CountDownLatch(2);
deviceConfiguration = new DeviceConfiguration(kernel, "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com",
deviceConfiguration = new DeviceConfiguration(kernel.getConfig(), kernel.getKernelCommandLine(), "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com",
"xxxxxx.credentials.iot.us-east-1.amazonaws.com", "privKeyFilePath", "certFilePath", "caFilePath",
"us-east-1", "roleAliasName");
kernel.getContext().put(DeviceConfiguration.class, deviceConfiguration);
Expand Down Expand Up @@ -122,7 +122,7 @@ void GIVEN_one_component_errored_and_recovered_THEN_fss_should_send_recovery_mes
@Test
void GIVEN_two_components_errored_and_recovered_THEN_fss_should_send_only_one_recovery_message() throws Exception {
statusChange = new CountDownLatch(3);
deviceConfiguration = new DeviceConfiguration(kernel, "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com",
deviceConfiguration = new DeviceConfiguration(kernel.getConfig(), kernel.getKernelCommandLine(), "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com",
"xxxxxx.credentials.iot.us-east-1.amazonaws.com", "privKeyFilePath", "certFilePath", "caFilePath",
"us-east-1", "roleAliasName");
kernel.getContext().put(DeviceConfiguration.class, deviceConfiguration);
Expand Down Expand Up @@ -161,7 +161,7 @@ void GIVEN_two_components_errored_and_recovered_THEN_fss_should_send_only_one_re
@Test
void GIVEN_three_components_errored_and_recovered_THEN_fss_should_send_only_one_recovery_message_and_one_errored_message_should_contain_recovery_message() throws Exception {
statusChange = new CountDownLatch(4);
deviceConfiguration = new DeviceConfiguration(kernel, "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com",
deviceConfiguration = new DeviceConfiguration(kernel.getConfig(), kernel.getKernelCommandLine(), "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com",
"xxxxxx.credentials.iot.us-east-1.amazonaws.com", "privKeyFilePath", "certFilePath", "caFilePath",
"us-east-1", "roleAliasName");
kernel.getContext().put(DeviceConfiguration.class, deviceConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void setupKernel(ExtensionContext context) throws Exception {
});
// set required instances from context
deviceConfiguration =
new DeviceConfiguration(kernel, "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com", "xxxxxx.credentials.iot.us-east-1.amazonaws.com", "privKeyFilePath",
new DeviceConfiguration(kernel.getConfig(), kernel.getKernelCommandLine(), "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com", "xxxxxx.credentials.iot.us-east-1.amazonaws.com", "privKeyFilePath",
"certFilePath", "caFilePath", "us-east-1", "roleAliasName");
kernel.getContext().put(DeviceConfiguration.class, deviceConfiguration);
// pre-load contents to package store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void afterEach() {
@Test
void GIVEN_kernel_launches_THEN_thing_details_and_components_terminal_states_uploaded_to_cloud_3s_after_launch_message()
throws Exception {
deviceConfiguration = new DeviceConfiguration(kernel, "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com",
deviceConfiguration = new DeviceConfiguration(kernel.getConfig(), kernel.getKernelCommandLine(), "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com",
"xxxxxx.credentials.iot.us-east-1.amazonaws.com", "privKeyFilePath", "certFilePath", "caFilePath",
"us-east-1", "roleAliasName");
kernel.getContext().put(DeviceConfiguration.class, deviceConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void setupKernel(ExtensionContext context) throws Exception {
});
// set required instances from context
deviceConfiguration =
new DeviceConfiguration(kernel, "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com", "xxxxxx.credentials.iot.us-east-1.amazonaws.com", "privKeyFilePath",
new DeviceConfiguration(kernel.getConfig(), kernel.getKernelCommandLine(), "ThingName", "xxxxxx-ats.iot.us-east-1.amazonaws.com", "xxxxxx.credentials.iot.us-east-1.amazonaws.com", "privKeyFilePath",
"certFilePath", "caFilePath", "us-east-1", "roleAliasName");
kernel.getContext().put(DeviceConfiguration.class, deviceConfiguration);
kernel.launch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void GIVEN_kernel_running_with_telemetry_config_WHEN_launch_THEN_metrics_are_pub
ConfigPlatformResolver.initKernelWithMultiPlatformConfig(kernel, this.getClass().getResource("config.yaml"));
kernel.getContext().put(MqttClient.class, mqttClient);
kernel.getContext().put(DeviceConfiguration.class,
new DeviceConfiguration(kernel, MOCK_THING_NAME, "us-east-1", "us-east-1", "mock", "mock", "mock", "us-east-1",
new DeviceConfiguration(kernel.getConfig(), kernel.getKernelCommandLine(), MOCK_THING_NAME, "us-east-1", "us-east-1", "mock", "mock", "mock", "us-east-1",
"mock"));

//WHEN
Expand Down
Loading

0 comments on commit 54207c3

Please sign in to comment.