@Test
public void testWriteHttp1DeterministicRuleEngineConfig() throws Exception {
try (TestingServer server = new TestingServer()) {
server.start();
Http1DeterministicRuleEngineConfig config = new Http1DeterministicRuleEngineConfig();
HashMultimap<String, String> headers = HashMultimap.create();
headers.put("User-Agent", "Bad-actor: 1.0");
Http1DeterministicRuleEngineConfig.Rule bad =
new Http1DeterministicRuleEngineConfig.Rule(
HttpMethod.GET, "/path/to/failure", HttpVersion.HTTP_1_0, headers);
Http1DeterministicRuleEngineConfig.Rule good =
new Http1DeterministicRuleEngineConfig.Rule(null, null, null, null);
config.blacklistRule(bad);
config.whitelistRule(good);
ThriftMarshaller marshaller = new ThriftMarshaller();
RetryPolicy retryPolicy = new RetryOneTime(1);
try (CuratorFramework client =
CuratorFrameworkFactory.newClient(server.getConnectString(), retryPolicy)) {
client.start();
String path = "/some/path/to/nodes/http1Rules";
ZooKeeperWriteProvider provider = new ZooKeeperWriteProvider(marshaller, client);
provider.write(path, config);
byte[] data = client.getData().forPath(path);
ThriftUnmarshaller unmarshaller = new ThriftUnmarshaller();
Http1DeterministicRuleEngineConfig read = new Http1DeterministicRuleEngineConfig();
unmarshaller.unmarshall(read, data);
assertEquals(config, read);
}
}
}