Search in sources :

Example 6 with SetDataBuilder

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)));
}
Also used : SetDataBuilder(org.apache.curator.framework.api.SetDataBuilder) Stat(org.apache.zookeeper.data.Stat) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Example 7 with SetDataBuilder

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<>()));
}
Also used : SetDataBuilder(org.apache.curator.framework.api.SetDataBuilder) Test(org.junit.jupiter.api.Test)

Example 8 with SetDataBuilder

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()));
}
Also used : SetDataBuilder(org.apache.curator.framework.api.SetDataBuilder) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig) Test(org.junit.jupiter.api.Test)

Example 9 with SetDataBuilder

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)));
}
Also used : SetDataBuilder(org.apache.curator.framework.api.SetDataBuilder) Stat(org.apache.zookeeper.data.Stat) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig) Test(org.junit.jupiter.api.Test)

Example 10 with SetDataBuilder

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")));
}
Also used : SetDataBuilder(org.apache.curator.framework.api.SetDataBuilder) Stat(org.apache.zookeeper.data.Stat) ExistsBuilder(org.apache.curator.framework.api.ExistsBuilder) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

SetDataBuilder (org.apache.curator.framework.api.SetDataBuilder)14 Test (org.junit.jupiter.api.Test)8 ExistsBuilder (org.apache.curator.framework.api.ExistsBuilder)6 Stat (org.apache.zookeeper.data.Stat)6 BeforeTest (org.testng.annotations.BeforeTest)6 Test (org.testng.annotations.Test)6 CreateBuilder (org.apache.curator.framework.api.CreateBuilder)4 HashMap (java.util.HashMap)2 SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)2 SensorEnrichmentConfig (org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig)2 ACL (org.apache.zookeeper.data.ACL)2 Id (org.apache.zookeeper.data.Id)2