use of com.linkedin.d2.BoundedCostBackupRequests in project rest.li by linkedin.
the class TestBackupRequestsStrategyFactory method testBoundedCostBackupRequestsWithDefaultsDeser.
@Test
public void testBoundedCostBackupRequestsWithDefaultsDeser() throws IOException {
BackupRequestsConfiguration brc = new BackupRequestsConfiguration();
BoundedCostBackupRequests bcbr = new BoundedCostBackupRequests();
bcbr.setCost(3);
brc.setOperation("BATCH_GET");
brc.setStrategy(BackupRequestsConfiguration.Strategy.create(bcbr));
String json = new JacksonDataCodec().mapToString(brc.data());
@SuppressWarnings("unchecked") Map<String, Object> map = JacksonUtil.getObjectMapper().readValue(json, Map.class);
BackupRequestsStrategy strategy = BackupRequestsStrategyFactory.tryCreate(map);
assertNotNull(strategy);
assertTrue(strategy instanceof BoundedCostBackupRequestsStrategy);
BoundedCostBackupRequestsStrategy boundedCostStrategy = (BoundedCostBackupRequestsStrategy) strategy;
assertEquals(boundedCostStrategy.getHistoryLength(), (int) bcbr.getHistoryLength());
assertEquals(boundedCostStrategy.getMinBackupDelayNano(), (long) bcbr.getMinBackupDelayMs() * 1000L * 1000L);
assertEquals(boundedCostStrategy.getRequiredHistory(), (int) bcbr.getRequiredHistoryLength());
assertEquals(boundedCostStrategy.getPercent(), (double) bcbr.getCost());
}
use of com.linkedin.d2.BoundedCostBackupRequests in project rest.li by linkedin.
the class TestBackupRequestsStrategyFactory method testBoundedCostBackupRequestsDeser.
@Test
public void testBoundedCostBackupRequestsDeser() throws IOException {
BackupRequestsConfiguration brc = new BackupRequestsConfiguration();
BoundedCostBackupRequests bcbr = new BoundedCostBackupRequests();
bcbr.setCost(3);
bcbr.setHistoryLength(4096);
bcbr.setMaxBurst(16);
bcbr.setMinBackupDelayMs(5);
bcbr.setRequiredHistoryLength(65536);
brc.setOperation("BATCH_GET");
brc.setStrategy(BackupRequestsConfiguration.Strategy.create(bcbr));
String json = new JacksonDataCodec().mapToString(brc.data());
@SuppressWarnings("unchecked") Map<String, Object> map = JacksonUtil.getObjectMapper().readValue(json, Map.class);
BackupRequestsStrategy strategy = BackupRequestsStrategyFactory.tryCreate(map);
assertNotNull(strategy);
assertTrue(strategy instanceof BoundedCostBackupRequestsStrategy);
BoundedCostBackupRequestsStrategy boundedCostStrategy = (BoundedCostBackupRequestsStrategy) strategy;
assertEquals(boundedCostStrategy.getHistoryLength(), (int) bcbr.getHistoryLength());
assertEquals(boundedCostStrategy.getMinBackupDelayNano(), (long) bcbr.getMinBackupDelayMs() * 1000L * 1000L);
assertEquals(boundedCostStrategy.getRequiredHistory(), (int) bcbr.getRequiredHistoryLength());
assertEquals(boundedCostStrategy.getPercent(), (double) bcbr.getCost());
}
use of com.linkedin.d2.BoundedCostBackupRequests in project rest.li by linkedin.
the class BackupRequestsConverterTest method testBackupRequestsConverter.
@Test
public void testBackupRequestsConverter() {
BackupRequestsConfigurationArray configArray = new BackupRequestsConfigurationArray();
BackupRequestsConfiguration config = new BackupRequestsConfiguration();
config.setOperation("myOperation");
BoundedCostBackupRequests boundedCostBackupRequests = new BoundedCostBackupRequests();
boundedCostBackupRequests.setCost(5);
boundedCostBackupRequests.setHistoryLength(4096);
boundedCostBackupRequests.setMaxBurst(45);
boundedCostBackupRequests.setMinBackupDelayMs(50);
boundedCostBackupRequests.setRequiredHistoryLength(456);
config.setStrategy(Strategy.create(boundedCostBackupRequests));
// round trip conversion test
Assert.assertEquals(BackupRequestsConverter.toConfig(BackupRequestsConverter.toProperties(configArray)), configArray);
}
use of com.linkedin.d2.BoundedCostBackupRequests in project rest.li by linkedin.
the class TestBackupRequestsClient method createBackupRequestsConfiguration.
@SuppressWarnings("unchecked")
private final Map<String, Object> createBackupRequestsConfiguration(int cost, String operation) throws JsonParseException, JsonMappingException, IOException {
BackupRequestsConfiguration brc = new BackupRequestsConfiguration();
BoundedCostBackupRequests bcbr = new BoundedCostBackupRequests();
bcbr.setCost(cost);
brc.setOperation(operation);
brc.setStrategy(BackupRequestsConfiguration.Strategy.create(bcbr));
String json = new JacksonDataCodec().mapToString(brc.data());
return JacksonUtil.getObjectMapper().readValue(json, Map.class);
}
Aggregations