use of org.apache.curator.framework.api.SetDataBuilder in project metron by apache.
the class SensorParserConfigServiceImplTest method saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave.
@Test
public void saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave() throws Exception {
final SensorParserConfig sensorParserConfig = getTestBroSensorParserConfig();
when(objectMapper.writeValueAsString(sensorParserConfig)).thenReturn(broJson);
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(setDataBuilder.forPath(ConfigurationType.PARSER.getZookeeperRoot() + "/bro", broJson.getBytes(StandardCharsets.UTF_8))).thenReturn(new Stat());
when(curatorFramework.setData()).thenReturn(setDataBuilder);
assertEquals(getTestBroSensorParserConfig(), sensorParserConfigService.save("bro", sensorParserConfig));
verify(setDataBuilder).forPath(eq(ConfigurationType.PARSER.getZookeeperRoot() + "/bro"), eq(broJson.getBytes(StandardCharsets.UTF_8)));
}
use of org.apache.curator.framework.api.SetDataBuilder in project metron by apache.
the class SensorIndexingConfigServiceImplTest method saveShouldWrapExceptionInRestException.
@Test
public void saveShouldWrapExceptionInRestException() throws Exception {
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(setDataBuilder.forPath(ConfigurationType.INDEXING.getZookeeperRoot() + "/bro", broJson.getBytes(StandardCharsets.UTF_8))).thenThrow(Exception.class);
when(curatorFramework.setData()).thenReturn(setDataBuilder);
assertThrows(RestException.class, () -> sensorIndexingConfigService.save("bro", new HashMap<>()));
}
use of org.apache.curator.framework.api.SetDataBuilder in project metron by apache.
the class SensorEnrichmentConfigServiceImplTest method saveShouldWrapExceptionInRestException.
@Test
public void saveShouldWrapExceptionInRestException() throws Exception {
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(setDataBuilder.forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro", broJson.getBytes(StandardCharsets.UTF_8))).thenThrow(Exception.class);
when(curatorFramework.setData()).thenReturn(setDataBuilder);
assertThrows(RestException.class, () -> sensorEnrichmentConfigService.save("bro", new SensorEnrichmentConfig()));
}
use of org.apache.curator.framework.api.SetDataBuilder in project metron by apache.
the class SensorEnrichmentConfigServiceImplTest method saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave.
@Test
public void saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave() throws Exception {
final SensorEnrichmentConfig sensorEnrichmentConfig = getTestSensorEnrichmentConfig();
when(objectMapper.writeValueAsString(sensorEnrichmentConfig)).thenReturn(broJson);
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(setDataBuilder.forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro", broJson.getBytes(StandardCharsets.UTF_8))).thenReturn(new Stat());
when(curatorFramework.setData()).thenReturn(setDataBuilder);
assertEquals(sensorEnrichmentConfig, sensorEnrichmentConfigService.save("bro", sensorEnrichmentConfig));
verify(setDataBuilder).forPath(eq(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro"), eq(broJson.getBytes(StandardCharsets.UTF_8)));
}
use of org.apache.curator.framework.api.SetDataBuilder in project atlas by apache.
the class ActiveInstanceStateTest method testDataIsUpdatedWithAtlasServerAddress.
@Test
public void testDataIsUpdatedWithAtlasServerAddress() throws Exception {
when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX + "id1")).thenReturn(HOST_PORT);
when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
when(curatorFactory.clientInstance()).thenReturn(curatorFramework);
ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
when(curatorFramework.checkExists()).thenReturn(existsBuilder);
when(existsBuilder.forPath(getPath())).thenReturn(new Stat());
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(curatorFramework.setData()).thenReturn(setDataBuilder);
ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
activeInstanceState.update("id1");
verify(setDataBuilder).forPath(getPath(), SERVER_ADDRESS.getBytes(Charset.forName("UTF-8")));
}
Aggregations