org.neo4j.kernel.configuration.Config.updateDynamicSetting()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中org.neo4j.kernel.configuration.Config.updateDynamicSetting()方法的一些代码示例,展示了Config.updateDynamicSetting()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.updateDynamicSetting()方法的具体详情如下:
包路径:org.neo4j.kernel.configuration.Config
类名称:Config
方法名:updateDynamicSetting

Config.updateDynamicSetting介绍

[英]Updates a provided setting to a given value. This method is intended to be used for changing settings during runtime. If you want to change settings at startup, use Config#augment.
[中]将提供的设置更新为给定值。此方法用于在运行时更改设置。如果要在启动时更改设置,请使用Config#augment。

代码示例

代码示例来源:origin: neo4j/neo4j

@Test
public void updateDynamicShouldLogChanges()
{
  String settingName = MyDynamicSettings.boolSetting.name();
  String changedMessage = "Setting changed: '%s' changed from '%s' to '%s' via '%s'";
  Config config = Config.builder().withConfigClasses( singletonList( new MyDynamicSettings() ) ).build();
  Log log = mock( Log.class );
  config.setLogger( log );
  config.updateDynamicSetting( settingName, "false", ORIGIN );
  config.updateDynamicSetting( settingName, "true", ORIGIN );
  config.updateDynamicSetting( settingName, "", ORIGIN );
  InOrder order = inOrder( log );
  order.verify( log ).info( changedMessage, settingName, "default (true)", "false", "test" );
  order.verify( log ).info( changedMessage, settingName, "false", "true", "test" );
  order.verify( log ).info( changedMessage, settingName, "true", "default (true)", "test" );
  verifyNoMoreInteractions( log );
}

代码示例来源:origin: neo4j/neo4j

config.updateDynamicSetting( settingName, "another", ORIGIN );
config.updateDynamicSetting( settingName, "secret2", ORIGIN );
config.updateDynamicSetting( settingName, "", ORIGIN );

代码示例来源:origin: neo4j/neo4j

@Test
public void updateDynamicShouldInformRegisteredListeners()
{
  Config config = Config.builder().withConfigClasses( singletonList( new MyDynamicSettings() ) ).build();
  AtomicInteger counter = new AtomicInteger( 0 );
  config.registerDynamicUpdateListener( MyDynamicSettings.boolSetting, ( previous, update ) ->
  {
    counter.getAndIncrement();
    assertTrue( previous );
    assertFalse( update );
  } );
  config.updateDynamicSetting( MyDynamicSettings.boolSetting.name(), "false", ORIGIN );
  assertThat( counter.get(), is( 1 ) );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void updateDynamicShouldLogExceptionsFromUpdateListeners()
{
  Config config = Config.builder().withConfigClasses( singletonList( new MyDynamicSettings() ) ).build();
  IllegalStateException exception = new IllegalStateException( "Boo" );
  config.registerDynamicUpdateListener( MyDynamicSettings.boolSetting, ( a, b ) ->
  {
    throw exception;
  } );
  Log log = mock( Log.class );
  config.setLogger( log );
  String settingName = MyDynamicSettings.boolSetting.name();
  config.updateDynamicSetting( settingName, "", ORIGIN );
  verify( log ).error( "Failure when notifying listeners after dynamic setting change; " +
             "new setting might not have taken effect: Boo", exception );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void updateDynamicShouldThrowIfSettingIsNotDynamic()
{
  Config config = Config.builder().withConfigClasses( singletonList( mySettingsWithDefaults ) ).build();
  expect.expect( IllegalArgumentException.class );
  config.updateDynamicSetting( MySettingsWithDefaults.hello.name(), "hello", ORIGIN );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void updateDynamicShouldNotAllowInvalidSettings()
{
  Config config = Config.builder().withConfigClasses( singletonList( new MyDynamicSettings() ) ).build();
  expect.expect( InvalidSettingException.class );
  config.updateDynamicSetting( MyDynamicSettings.boolSetting.name(), "this is not a boolean", ORIGIN );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void pruningStrategyShouldBeDynamic() throws IOException
{
  CheckPointer checkPointer = getInstanceFromDb( CheckPointer.class );
  Config config = getInstanceFromDb( Config.class );
  FileSystemAbstraction fs = getInstanceFromDb( FileSystemAbstraction.class );
  LogFiles logFiles = LogFilesBuilder.builder( db.databaseLayout(), fs )
      .withLogVersionRepository( new SimpleLogVersionRepository() )
      .withLastCommittedTransactionIdSupplier( () -> 1 )
      .withTransactionIdStore( new SimpleTransactionIdStore() ).build();
  // Force transaction log rotation
  writeTransactionsAndRotateTwice();
  // Checkpoint to make sure strategy is evaluated
  checkPointer.forceCheckPoint( triggerInfo );
  // Make sure file is still there since we have disable pruning
  assertThat( countTransactionLogs( logFiles ), is( 3 ) );
  // Change pruning to true
  config.updateDynamicSetting( keep_logical_logs.name(), "false", "test" );
  // Checkpoint to make sure strategy is evaluated
  checkPointer.forceCheckPoint( triggerInfo );
  // Make sure file is removed
  assertThat( countTransactionLogs( logFiles ), is( 2 ) );
}

代码示例来源:origin: org.neo4j/neo4j-enterprise-kernel

@Description( "Updates a given setting value. Passing an empty value will result in removing the configured value " +
    "and falling back to the default value. Changes will not persist and will be lost if the server is restarted." )
@Procedure( name = "dbms.setConfigValue", mode = DBMS )
public void setConfigValue( @Name( "setting" ) String setting, @Name( "value" ) String value )
{
  securityContext.assertCredentialsNotExpired();
  assertAdmin();
  Config config = resolver.resolveDependency( Config.class );
  config.updateDynamicSetting( setting, value, "dbms.setConfigValue" ); // throws if something goes wrong
}

相关文章