-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enforcer actor ack time out handled in atomic thing create context (#…
…1598) enforcer actor ack time out handled in atomic thing create context * Create thing is rollbacked if enforcer ask times out * logging and refactor fixes * logs cleanup * supervisor configurable local ask timeout * CachingPolicyEnforcerProvider is able to force cache invalidation * update ConnectivitySupervisorActor ask timeout config Signed-off-by: Stanchev Aleksandar <aleksandar.stanchev@bosch.io>
- Loading branch information
Aleksandar Stanchev
authored
Mar 29, 2023
1 parent
5e6442e
commit 8bb7cd5
Showing
19 changed files
with
449 additions
and
65 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
.../java/org/eclipse/ditto/base/service/config/supervision/DefaultLocalAskTimeoutConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
package org.eclipse.ditto.base.service.config.supervision; | ||
|
||
import java.time.Duration; | ||
import java.util.Objects; | ||
|
||
import javax.annotation.concurrent.Immutable; | ||
|
||
import org.eclipse.ditto.internal.utils.config.ConfigWithFallback; | ||
import org.eclipse.ditto.internal.utils.config.ScopedConfig; | ||
|
||
import com.typesafe.config.Config; | ||
|
||
/** | ||
* This class is the default implementation of the local ACK timeout config. | ||
*/ | ||
@Immutable | ||
public class DefaultLocalAskTimeoutConfig implements LocalAskTimeoutConfig { | ||
|
||
private static final String CONFIG_PATH = "local-ask"; | ||
private final Duration askTimeout; | ||
|
||
private DefaultLocalAskTimeoutConfig(final ScopedConfig config) { | ||
askTimeout = config.getNonNegativeAndNonZeroDurationOrThrow(LocalAskTimeoutConfigValue.ASK_TIMEOUT); | ||
} | ||
|
||
/** | ||
* Returns an instance of {@code DefaultLocalAskTimeoutConfig} based on the settings of the specified Config. | ||
* | ||
* @param config is supposed to provide the settings of the local ASK timeout config at {@value #CONFIG_PATH}. | ||
* @return the instance. | ||
* @throws org.eclipse.ditto.internal.utils.config.DittoConfigError if {@code config} is invalid. | ||
*/ | ||
public static DefaultLocalAskTimeoutConfig of(final Config config) { | ||
return new DefaultLocalAskTimeoutConfig(ConfigWithFallback.newInstance(config, CONFIG_PATH, | ||
LocalAskTimeoutConfig.LocalAskTimeoutConfigValue.values())); | ||
} | ||
|
||
@Override | ||
public Duration getLocalAckTimeout() { | ||
return askTimeout; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
final DefaultLocalAskTimeoutConfig that = (DefaultLocalAskTimeoutConfig) o; | ||
return Objects.equals(askTimeout, that.askTimeout); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(askTimeout); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "[" + | ||
"askTimeout=" + askTimeout + | ||
']'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...rc/main/java/org/eclipse/ditto/base/service/config/supervision/LocalAskTimeoutConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
package org.eclipse.ditto.base.service.config.supervision; | ||
|
||
import java.time.Duration; | ||
|
||
import javax.annotation.concurrent.Immutable; | ||
|
||
import org.eclipse.ditto.internal.utils.config.KnownConfigValue; | ||
|
||
/** | ||
* Provides configuration settings for the local ACK timeout. | ||
*/ | ||
@Immutable | ||
public interface LocalAskTimeoutConfig { | ||
|
||
/** | ||
* Timeout for local actor invocations - a small timeout should be more than sufficient as those are just method | ||
* calls. | ||
* @return the duration for a local ACK timeout calls. | ||
*/ | ||
Duration getLocalAckTimeout(); | ||
|
||
|
||
/** | ||
* An enumeration of the known config path expressions and their associated default values for | ||
* {@code LocalAskTimeoutConfigValue}. | ||
*/ | ||
enum LocalAskTimeoutConfigValue implements KnownConfigValue { | ||
|
||
/** | ||
* The local ACK timeout duration. | ||
*/ | ||
ASK_TIMEOUT("timeout", Duration.ofSeconds(5L)); | ||
|
||
private final String path; | ||
private final Duration defaultValue; | ||
|
||
LocalAskTimeoutConfigValue(final String thePath, final Duration theDefaultValue) { | ||
|
||
this.path = thePath; | ||
this.defaultValue = theDefaultValue; | ||
} | ||
|
||
@Override | ||
public Object getDefaultValue() { | ||
return defaultValue; | ||
} | ||
|
||
@Override | ||
public String getConfigPath() { | ||
return path; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...a/org/eclipse/ditto/base/service/config/supervision/DefaultLocalAskTimeoutConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
package org.eclipse.ditto.base.service.config.supervision; | ||
|
||
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf; | ||
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable; | ||
|
||
import java.time.Duration; | ||
|
||
import org.assertj.core.api.JUnitSoftAssertions; | ||
import org.junit.BeforeClass; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import com.typesafe.config.Config; | ||
import com.typesafe.config.ConfigFactory; | ||
|
||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
|
||
/** | ||
* Unit test for {@link DefaultLocalAskTimeoutConfigTest}. | ||
*/ | ||
public class DefaultLocalAskTimeoutConfigTest { | ||
|
||
private static Config supervisorLocalAskTimeoutConfig; | ||
|
||
@Rule | ||
public final JUnitSoftAssertions softly = new JUnitSoftAssertions(); | ||
|
||
@BeforeClass | ||
public static void initTestFixture() { | ||
supervisorLocalAskTimeoutConfig = ConfigFactory.load("local-ask-timout-test"); | ||
} | ||
|
||
@Test | ||
public void assertImmutability() { | ||
assertInstancesOf(DefaultLocalAskTimeoutConfig.class, | ||
areImmutable()); | ||
} | ||
|
||
@Test | ||
public void testHashCodeAndEquals() { | ||
EqualsVerifier.forClass(DefaultLocalAskTimeoutConfig.class) | ||
.usingGetClass() | ||
.verify(); | ||
} | ||
|
||
@Test | ||
public void underTestReturnsDefaultValuesIfBaseConfigWasEmpty() { | ||
final DefaultLocalAskTimeoutConfig underTest = DefaultLocalAskTimeoutConfig.of(ConfigFactory.empty()); | ||
|
||
softly.assertThat(underTest.getLocalAckTimeout()) | ||
.as(LocalAskTimeoutConfig.LocalAskTimeoutConfigValue.ASK_TIMEOUT.getConfigPath()) | ||
.isEqualTo(LocalAskTimeoutConfig.LocalAskTimeoutConfigValue.ASK_TIMEOUT.getDefaultValue()); | ||
} | ||
|
||
@Test | ||
public void underTestReturnsValuesOfConfigFile() { | ||
final DefaultLocalAskTimeoutConfig underTest = DefaultLocalAskTimeoutConfig.of(supervisorLocalAskTimeoutConfig); | ||
|
||
softly.assertThat(underTest.getLocalAckTimeout()) | ||
.as(LocalAskTimeoutConfig.LocalAskTimeoutConfigValue.ASK_TIMEOUT.getConfigPath()) | ||
.isEqualTo(Duration.ofSeconds(10L)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
local-ask { | ||
timeout = 10s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.