This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nathan Ziebart
committed
Nov 15, 2017
1 parent
dd55403
commit 2318f69
Showing
14 changed files
with
250 additions
and
49 deletions.
There are no files selected for viewing
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
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
47 changes: 47 additions & 0 deletions
47
qos-service-impl/src/main/java/com/palantir/atlasdb/qos/config/QosClientConfig.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,47 @@ | ||
/* | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the BSD-3 License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.atlasdb.qos.config; | ||
|
||
import java.util.Optional; | ||
|
||
import org.immutables.value.Value; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import com.palantir.remoting.api.config.service.HumanReadableDuration; | ||
import com.palantir.remoting.api.config.service.ServiceConfiguration; | ||
|
||
@Value.Immutable | ||
@JsonDeserialize(as = ImmutableQosClientConfig.class) | ||
@JsonSerialize(as = ImmutableQosClientConfig.class) | ||
public abstract class QosClientConfig { | ||
|
||
public static final QosClientConfig DEFAULT = ImmutableQosClientConfig.builder().build(); | ||
|
||
public abstract Optional<ServiceConfiguration> qosService(); | ||
|
||
@Value.Default | ||
public HumanReadableDuration maxBackoffSleepTime() { | ||
return HumanReadableDuration.seconds(10); | ||
} | ||
|
||
@Value.Default | ||
public QosLimitsConfig limits() { | ||
return QosLimitsConfig.DEFAULT_NO_LIMITS; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
qos-service-impl/src/main/java/com/palantir/atlasdb/qos/config/QosLimitsConfig.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,41 @@ | ||
/* | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the BSD-3 License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.atlasdb.qos.config; | ||
|
||
import org.immutables.value.Value; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
|
||
@Value.Immutable | ||
@JsonDeserialize(as = ImmutableQosLimitsConfig.class) | ||
@JsonSerialize(as = ImmutableQosLimitsConfig.class) | ||
public abstract class QosLimitsConfig { | ||
|
||
public static final QosLimitsConfig DEFAULT_NO_LIMITS = ImmutableQosLimitsConfig.builder().build(); | ||
|
||
@Value.Default | ||
public int readBytesPerSecond() { | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
@Value.Default | ||
public int writeBytesPerSecond() { | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
} |
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
43 changes: 43 additions & 0 deletions
43
qos-service-impl/src/main/java/com/palantir/atlasdb/qos/ratelimit/QosRateLimiters.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,43 @@ | ||
/* | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the BSD-3 License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.atlasdb.qos.ratelimit; | ||
|
||
import org.immutables.value.Value; | ||
|
||
import com.palantir.atlasdb.qos.config.QosLimitsConfig; | ||
|
||
@Value.Immutable | ||
public interface QosRateLimiters { | ||
|
||
static QosRateLimiters create(QosLimitsConfig config) { | ||
QosRateLimiter readLimiter = QosRateLimiter.create(); | ||
readLimiter.updateRate(config.readBytesPerSecond()); | ||
|
||
QosRateLimiter writeLimiter = QosRateLimiter.create(); | ||
writeLimiter.updateRate(config.writeBytesPerSecond()); | ||
|
||
return ImmutableQosRateLimiters.builder() | ||
.read(readLimiter) | ||
.write(writeLimiter) | ||
.build(); | ||
} | ||
|
||
QosRateLimiter read(); | ||
|
||
QosRateLimiter write(); | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
...rvice-impl/src/test/java/com/palantir/atlasdb/qos/QosClientConfigDeserializationTest.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,68 @@ | ||
/* | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the BSD-3 License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.palantir.atlasdb.qos; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
|
||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import com.fasterxml.jackson.datatype.guava.GuavaModule; | ||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; | ||
import com.palantir.atlasdb.qos.config.ImmutableQosClientConfig; | ||
import com.palantir.atlasdb.qos.config.ImmutableQosLimitsConfig; | ||
import com.palantir.atlasdb.qos.config.QosClientConfig; | ||
import com.palantir.atlasdb.qos.config.QosServiceRuntimeConfig; | ||
import com.palantir.remoting.api.config.service.HumanReadableDuration; | ||
import com.palantir.remoting.api.config.service.ServiceConfiguration; | ||
import com.palantir.remoting.api.config.ssl.SslConfiguration; | ||
import com.palantir.remoting3.ext.jackson.ShimJdk7Module; | ||
|
||
public class QosClientConfigDeserializationTest { | ||
|
||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(new YAMLFactory()) | ||
.registerModule(new GuavaModule()) | ||
.registerModule(new ShimJdk7Module()) | ||
.registerModule(new Jdk8Module()); | ||
|
||
@Test | ||
public void canDeserializeFromYaml() throws IOException { | ||
QosClientConfig expected = ImmutableQosClientConfig.builder() | ||
.qosService( | ||
ServiceConfiguration.builder() | ||
.addUris("http://localhost:8080") | ||
.security(SslConfiguration.of(Paths.get("trustStore.jks"))) | ||
.build()) | ||
.maxBackoffSleepTime(HumanReadableDuration.seconds(20)) | ||
.limits(ImmutableQosLimitsConfig.builder() | ||
.readBytesPerSecond(123) | ||
.writeBytesPerSecond(456) | ||
.build()) | ||
.build(); | ||
|
||
File configFile = new File(QosServiceRuntimeConfig.class.getResource("/qos-client.yml").getPath()); | ||
QosClientConfig config = OBJECT_MAPPER.readValue(configFile, QosClientConfig.class); | ||
|
||
assertThat(config).isEqualTo(expected); | ||
} | ||
|
||
} |
Oops, something went wrong.