org.apache.curator.framework.api.SetDataBuilder Java Examples

The following examples show how to use org.apache.curator.framework.api.SetDataBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActiveInstanceStateTest.java    From atlas with Apache License 2.0 6 votes vote down vote up
@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")));
}
 
Example #2
Source File: ActiveInstanceStateTest.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@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")));
}
 
Example #3
Source File: CuratorManager.java    From Singularity with Apache License 2.0 6 votes vote down vote up
private void privateSet(String path, Optional<byte[]> data) throws Exception {
  final long start = System.currentTimeMillis();

  try {
    SetDataBuilder setDataBuilder = curator.setData();

    if (data.isPresent()) {
      setDataBuilder.forPath(path, data.get());
    } else {
      setDataBuilder.forPath(path);
    }
  } finally {
    log(
      OperationType.WRITE,
      Optional.<Integer>empty(),
      Optional.<Integer>of(data.orElse(EMPTY_BYTES).length),
      start,
      path
    );
  }
}
 
Example #4
Source File: ActiveInstanceStateTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testSharedPathIsCreatedIfNotExists() 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(null);

    CreateBuilder createBuilder = mock(CreateBuilder.class);
    when(curatorFramework.create()).thenReturn(createBuilder);
    when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder);
    when(createBuilder.withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE)).thenReturn(createBuilder);

    SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
    when(curatorFramework.setData()).thenReturn(setDataBuilder);

    ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
    activeInstanceState.update("id1");

    verify(createBuilder).forPath(getPath());
}
 
Example #5
Source File: ActiveInstanceStateTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
   public void testSharedPathIsCreatedWithRightACLIfNotExists() throws Exception {

       when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn(HOST_PORT);
       when(configuration.getString(HAConfiguration.HA_ZOOKEEPER_ACL)).thenReturn("sasl:[email protected]");
       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(null);

       CreateBuilder createBuilder = mock(CreateBuilder.class);
       when(curatorFramework.create()).thenReturn(createBuilder);
       when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder);
ACL expectedAcl = new ACL(ZooDefs.Perms.ALL, new Id("sasl", "[email protected]"));
ACL expectedAcl1 = new ACL(ZooDefs.Perms.READ, new Id("world", "anyone"));
       when(createBuilder.
               withACL(Arrays.asList(new ACL[]{expectedAcl,expectedAcl1}))).thenReturn(createBuilder);


       SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
       when(curatorFramework.setData()).thenReturn(setDataBuilder);

       ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
       activeInstanceState.update("id1");

       verify(createBuilder).forPath(getPath());
   }
 
Example #6
Source File: ActiveInstanceStateTest.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testSharedPathIsCreatedIfNotExists() 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(null);

    CreateBuilder createBuilder = mock(CreateBuilder.class);
    when(curatorFramework.create()).thenReturn(createBuilder);
    when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder);
    when(createBuilder.withACL(ZooDefs.Ids.OPEN_ACL_UNSAFE)).thenReturn(createBuilder);

    SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
    when(curatorFramework.setData()).thenReturn(setDataBuilder);

    ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
    activeInstanceState.update("id1");

    verify(createBuilder).forPath(getPath());
}
 
Example #7
Source File: ActiveInstanceStateTest.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testSharedPathIsCreatedWithRightACLIfNotExists() throws Exception {

    when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn(HOST_PORT);
    when(configuration.getString(HAConfiguration.HA_ZOOKEEPER_ACL)).thenReturn("sasl:[email protected]");
    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(null);

    CreateBuilder createBuilder = mock(CreateBuilder.class);
    when(curatorFramework.create()).thenReturn(createBuilder);
    when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder);
    ACL expectedAcl = new ACL(ZooDefs.Perms.ALL, new Id("sasl", "[email protected]"));
    when(createBuilder.
            withACL(Arrays.asList(new ACL[]{expectedAcl}))).thenReturn(createBuilder);

    SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
    when(curatorFramework.setData()).thenReturn(setDataBuilder);

    ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
    activeInstanceState.update("id1");

    verify(createBuilder).forPath(getPath());
}
 
Example #8
Source File: SensorIndexingConfigServiceImplTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@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<>()));
}
 
Example #9
Source File: SensorIndexingConfigServiceImplTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@Test
public void saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave() throws Exception {
  final Map<String, Object> sensorIndexingConfig = getTestSensorIndexingConfig();

  when(objectMapper.writeValueAsString(sensorIndexingConfig)).thenReturn(broJson);

  SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
  when(setDataBuilder.forPath(ConfigurationType.INDEXING.getZookeeperRoot() + "/bro", broJson.getBytes(StandardCharsets.UTF_8))).thenReturn(new Stat());
  when(curatorFramework.setData()).thenReturn(setDataBuilder);

  assertEquals(sensorIndexingConfig, sensorIndexingConfigService.save("bro", sensorIndexingConfig));
  verify(setDataBuilder).forPath(eq(ConfigurationType.INDEXING.getZookeeperRoot() + "/bro"), eq(broJson.getBytes(StandardCharsets.UTF_8)));
}
 
Example #10
Source File: GlobalConfigServiceImplTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@Test
public void saveShouldWrapExceptionInRestException() throws Exception {
  SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
  when(setDataBuilder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot(), "{ }".getBytes(
      StandardCharsets.UTF_8))).thenThrow(Exception.class);

  when(curatorFramework.setData()).thenReturn(setDataBuilder);

  assertThrows(RestException.class, () -> globalConfigService.save(new HashMap<>()));
}
 
Example #11
Source File: GlobalConfigServiceImplTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@Test
public void saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave() throws Exception {
  SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
  when(setDataBuilder.forPath(ConfigurationType.GLOBAL.getZookeeperRoot(), "{ }".getBytes(StandardCharsets.UTF_8))).thenReturn(new Stat());

  when(curatorFramework.setData()).thenReturn(setDataBuilder);

  assertEquals(new HashMap<>(), globalConfigService.save(new HashMap<>()));
  verify(setDataBuilder).forPath(eq(ConfigurationType.GLOBAL.getZookeeperRoot()), eq("{ }".getBytes(StandardCharsets.UTF_8)));
}
 
Example #12
Source File: SensorParserConfigServiceImplTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@Test
public void saveShouldWrapExceptionInRestException() throws Exception {
  SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
  when(setDataBuilder.forPath(ConfigurationType.PARSER.getZookeeperRoot() + "/bro", broJson.getBytes(StandardCharsets.UTF_8))).thenThrow(Exception.class);

  when(curatorFramework.setData()).thenReturn(setDataBuilder);

  final SensorParserConfig sensorParserConfig = new SensorParserConfig();
  sensorParserConfig.setSensorTopic("bro");
  assertThrows(RestException.class, () -> sensorParserConfigService.save("bro", sensorParserConfig));
}
 
Example #13
Source File: SensorParserConfigServiceImplTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@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)));
}
 
Example #14
Source File: SensorEnrichmentConfigServiceImplTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@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()));
}
 
Example #15
Source File: SensorEnrichmentConfigServiceImplTest.java    From metron with Apache License 2.0 5 votes vote down vote up
@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)));
}
 
Example #16
Source File: MockCurator.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public SetDataBuilder setData() {
    return new MockSetDataBuilder();
}