Search in sources :

Example 11 with Configuration

use of org.apache.commons.configuration2.Configuration in project graylog2-server by Graylog2.

the class ExposedConfigurationTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    final Configuration configuration = new Configuration();
    final ExposedConfiguration c = ExposedConfiguration.create(configuration);
    final String json = objectMapper.writeValueAsString(c);
    assertThat((int) JsonPath.read(json, "$.inputbuffer_processors")).isEqualTo(c.inputBufferProcessors());
    assertThat((int) JsonPath.read(json, "$.processbuffer_processors")).isEqualTo(c.processBufferProcessors());
    assertThat((int) JsonPath.read(json, "$.outputbuffer_processors")).isEqualTo(c.outputBufferProcessors());
    assertThat((String) JsonPath.read(json, "$.processor_wait_strategy")).isEqualTo(c.processorWaitStrategy());
    assertThat((String) JsonPath.read(json, "$.inputbuffer_wait_strategy")).isEqualTo(c.inputBufferWaitStrategy());
    assertThat((int) JsonPath.read(json, "$.inputbuffer_ring_size")).isEqualTo(c.inputBufferRingSize());
    assertThat((int) JsonPath.read(json, "$.ring_size")).isEqualTo(c.ringSize());
    assertThat((String) JsonPath.read(json, "$.plugin_dir")).isEqualTo(c.pluginDir());
    assertThat((String) JsonPath.read(json, "$.node_id_file")).isEqualTo(c.nodeIdFile());
    assertThat((boolean) JsonPath.read(json, "$.allow_highlighting")).isEqualTo(c.allowHighlighting());
    assertThat((boolean) JsonPath.read(json, "$.allow_leading_wildcard_searches")).isEqualTo(c.allowLeadingWildcardSearches());
    assertThat((int) JsonPath.read(json, "$.stream_processing_timeout")).isEqualTo((int) c.streamProcessingTimeout());
    assertThat((int) JsonPath.read(json, "$.stream_processing_max_faults")).isEqualTo(c.streamProcessingMaxFaults());
    assertThat((int) JsonPath.read(json, "$.output_module_timeout")).isEqualTo((int) c.outputModuleTimeout());
    assertThat((int) JsonPath.read(json, "$.stale_master_timeout")).isEqualTo(c.staleMasterTimeout());
    assertThat((String) JsonPath.read(json, "$.gc_warning_threshold")).isEqualTo(c.gcWarningThreshold());
}
Also used : Configuration(org.graylog2.Configuration) Test(org.junit.Test)

Example 12 with Configuration

use of org.apache.commons.configuration2.Configuration in project graylog2-server by Graylog2.

the class FieldContentValueAlertConditionTest method testCorrectUsageOfRelativeRange.

@Test
public void testCorrectUsageOfRelativeRange() throws Exception {
    final Stream stream = mock(Stream.class);
    final Searches searches = mock(Searches.class);
    final Configuration configuration = mock(Configuration.class);
    final SearchResult searchResult = mock(SearchResult.class);
    final int alertCheckInterval = 42;
    final RelativeRange relativeRange = RelativeRange.create(alertCheckInterval);
    when(configuration.getAlertCheckInterval()).thenReturn(alertCheckInterval);
    when(searches.search(anyString(), anyString(), eq(relativeRange), anyInt(), anyInt(), any(Sorting.class))).thenReturn(searchResult);
    final FieldContentValueAlertCondition alertCondition = new FieldContentValueAlertCondition(searches, configuration, stream, null, DateTime.now(DateTimeZone.UTC), "mockuser", ImmutableMap.<String, Object>of("field", "test", "value", "test"), "Field Content Value Test COndition");
    final AbstractAlertCondition.CheckResult result = alertCondition.runCheck();
}
Also used : Searches(org.graylog2.indexer.searches.Searches) Configuration(org.graylog2.Configuration) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) Stream(org.graylog2.plugin.streams.Stream) SearchResult(org.graylog2.indexer.results.SearchResult) AbstractAlertCondition(org.graylog2.alerts.AbstractAlertCondition) Sorting(org.graylog2.indexer.searches.Sorting) Test(org.junit.Test) AlertConditionTest(org.graylog2.alerts.AlertConditionTest)

Example 13 with Configuration

use of org.apache.commons.configuration2.Configuration in project graylog2-server by Graylog2.

the class UserServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    this.mongoConnection = mongoRule.getMongoConnection();
    this.configuration = new Configuration();
    this.userFactory = new UserImplFactory(configuration);
    this.permissions = new Permissions(ImmutableSet.of(new RestPermissions()));
    this.userService = new UserServiceImpl(mongoConnection, configuration, roleService, userFactory, permissionsResolver);
    when(roleService.getAdminRoleObjectId()).thenReturn("deadbeef");
}
Also used : RestPermissions(org.graylog2.shared.security.RestPermissions) Configuration(org.graylog2.Configuration) RestPermissions(org.graylog2.shared.security.RestPermissions) Permissions(org.graylog2.shared.security.Permissions) Before(org.junit.Before)

Example 14 with Configuration

use of org.apache.commons.configuration2.Configuration in project hadoop by apache.

the class RollingFileSystemSinkTestBase method preCreateLogFile.

/**
   * Create files at the target path with some known data in them.  Each file
   * will have the same content: &quot;Extra stuff&quot;.
   *
   * If the test run is happening within 20 seconds of the top of the hour,
   * this method will sleep until the top of the hour.
   *
   * @param path the target path under which to create the directory for the
   * current hour that will contain the log files.
   * @param numFiles the number of log files to create
   * @throws IOException thrown if the file creation fails
   * @throws InterruptedException thrown if interrupted while waiting for the
   * top of the hour.
   * @throws URISyntaxException thrown if the path isn't a valid URI
   */
protected void preCreateLogFile(String path, int numFiles) throws IOException, InterruptedException, URISyntaxException {
    Calendar now = getNowNotTopOfHour();
    FileSystem fs = FileSystem.get(new URI(path), new Configuration());
    Path dir = new Path(path, DATE_FORMAT.format(now.getTime()) + "00");
    fs.mkdirs(dir);
    Path file = new Path(dir, getLogFilename());
    // Create the log file to force the sink to append
    try (FSDataOutputStream out = fs.create(file)) {
        out.write("Extra stuff\n".getBytes());
        out.flush();
    }
    if (numFiles > 1) {
        int count = 1;
        while (count < numFiles) {
            file = new Path(dir, getLogFilename() + "." + count);
            // Create the log file to force the sink to append
            try (FSDataOutputStream out = fs.create(file)) {
                out.write("Extra stuff\n".getBytes());
                out.flush();
            }
            count += 1;
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Calendar(java.util.Calendar) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) URI(java.net.URI)

Example 15 with Configuration

use of org.apache.commons.configuration2.Configuration in project hadoop by apache.

the class MetricsConfig method toString.

static String toString(Configuration c) {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    try {
        PrintWriter pw = new PrintWriter(buffer, false);
        PropertiesConfiguration tmp = new PropertiesConfiguration();
        tmp.copy(c);
        tmp.write(pw);
        return buffer.toString("UTF-8");
    } catch (Exception e) {
        throw new MetricsConfigException(e);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) PrintWriter(java.io.PrintWriter)

Aggregations

SubsetConfiguration (org.apache.commons.configuration2.SubsetConfiguration)10 Configuration (org.graylog2.Configuration)10 Test (org.junit.Test)9 Configuration (org.apache.hadoop.conf.Configuration)8 URI (java.net.URI)7 Configuration (org.apache.commons.configuration2.Configuration)5 Before (org.junit.Before)5 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)4 MetricRegistry (com.codahale.metrics.MetricRegistry)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)2 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 Role (org.graylog2.shared.users.Role)2 UserService (org.graylog2.shared.users.UserService)2 EventBus (com.google.common.eventbus.EventBus)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1