org.apache.commons.configuration.SubsetConfiguration Java Examples
The following examples show how to use
org.apache.commons.configuration.SubsetConfiguration.
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: ConfigUtils.java From singer with Apache License 2.0 | 6 votes |
public static LoggingAuditEventSenderConfig parseSenderConfig(AbstractConfiguration conf) throws ConfigurationException { try { LoggingAuditEventSenderConfig senderConfig = new LoggingAuditEventSenderConfig(); SenderType senderType = SenderType.valueOf(conf.getString( LoggingAuditClientConfigDef.SENDER_TYPE).toUpperCase()); if (!senderType.equals(SenderType.KAFKA)) { throw new ConfigurationException("Only Kafka Sender is supported now."); } senderConfig.setSenderType(senderType); senderConfig.setKafkaSenderConfig(parseKafkaSenderConfig(new SubsetConfiguration(conf, LoggingAuditClientConfigDef.KAFKA_SENDER_PREFIX))); return senderConfig; } catch (Exception e) { throw new ConfigurationException( "LoggingAuditEventSenderConfig can't be properly parsed due to " + e.getMessage()); } }
Example #2
Source File: TestPatternFilter.java From hadoop with Apache License 2.0 | 6 votes |
/** * Filters should accepts unmatched item when both include and * exclude patterns are present. */ @Test public void shouldAcceptUnmatchedWhenBothAreConfigured() { SubsetConfiguration c = new ConfigBuilder() .add("p.include", "foo") .add("p.include.tags", "foo:f") .add("p.exclude", "bar") .add("p.exclude.tags", "bar:b").subset("p"); shouldAccept(c, "foo"); shouldAccept(c, Arrays.asList(tag("foo", "", "f"))); shouldAccept(c, mockMetricsRecord("foo", Arrays.asList( tag("foo", "", "f")))); shouldReject(c, "bar"); shouldReject(c, Arrays.asList(tag("bar", "", "b"))); shouldReject(c, mockMetricsRecord("bar", Arrays.asList( tag("foo", "", "f")))); shouldReject(c, mockMetricsRecord("foo", Arrays.asList( tag("bar", "", "b")))); shouldAccept(c, "foobar"); shouldAccept(c, Arrays.asList(tag("foobar", "", ""))); shouldAccept(c, mockMetricsRecord("foobar", Arrays.asList( tag("foobar", "", "")))); }
Example #3
Source File: TestPatternFilter.java From hadoop with Apache License 2.0 | 6 votes |
/** * Filters should handle black-listing correctly */ @Test public void excludeOnlyShouldOnlyExcludeMatched() { SubsetConfiguration bl = new ConfigBuilder() .add("p.exclude", "foo") .add("p.exclude.tags", "foo:f").subset("p"); shouldAccept(bl, "bar"); shouldAccept(bl, Arrays.asList(tag("bar", "", ""))); shouldAccept(bl, mockMetricsRecord("bar", Arrays.asList( tag("bar", "", "")))); shouldReject(bl, "foo"); shouldReject(bl, Arrays.asList(tag("bar", "", ""), tag("foo", "", "f")), new boolean[] {true, false}); shouldReject(bl, mockMetricsRecord("foo", Arrays.asList( tag("bar", "", "")))); shouldReject(bl, mockMetricsRecord("bar", Arrays.asList( tag("bar", "", ""), tag("foo", "", "f")))); }
Example #4
Source File: TestPatternFilter.java From hadoop with Apache License 2.0 | 6 votes |
/** * Filters should handle white-listing correctly */ @Test public void includeOnlyShouldOnlyIncludeMatched() { SubsetConfiguration wl = new ConfigBuilder() .add("p.include", "foo") .add("p.include.tags", "foo:f").subset("p"); shouldAccept(wl, "foo"); shouldAccept(wl, Arrays.asList(tag("bar", "", ""), tag("foo", "", "f")), new boolean[] {false, true}); shouldAccept(wl, mockMetricsRecord("foo", Arrays.asList( tag("bar", "", ""), tag("foo", "", "f")))); shouldReject(wl, "bar"); shouldReject(wl, Arrays.asList(tag("bar", "", ""))); shouldReject(wl, Arrays.asList(tag("foo", "", "boo"))); shouldReject(wl, mockMetricsRecord("bar", Arrays.asList( tag("foo", "", "f")))); shouldReject(wl, mockMetricsRecord("foo", Arrays.asList( tag("bar", "", "")))); }
Example #5
Source File: LogConfigUtils.java From singer with Apache License 2.0 | 6 votes |
private static LogStreamReaderConfig parseLogStreamReaderConfig(AbstractConfiguration readerConfiguration) throws ConfigurationException { readerConfiguration.setThrowExceptionOnMissing(true); String readerTypeString = readerConfiguration.getString("type"); ReaderType type = ReaderType.valueOf(readerTypeString.toUpperCase()); LogStreamReaderConfig readerConfig = new LogStreamReaderConfig(type); if (type.equals(ReaderType.THRIFT)) { ThriftReaderConfig thriftReaderConfig = parseThriftReaderConfig( new SubsetConfiguration(readerConfiguration, readerTypeString + ".")); readerConfig.setThriftReaderConfig(thriftReaderConfig); } else if (type.equals(ReaderType.TEXT)) { TextReaderConfig textReaderConfig = parseTextReaderConfig( new SubsetConfiguration(readerConfiguration, readerTypeString + ".")); readerConfig.setTextReaderConfig(textReaderConfig); } return readerConfig; }
Example #6
Source File: LogConfigUtils.java From singer with Apache License 2.0 | 6 votes |
private static PulsarProducerConfig parsePulsarProducerConfig(SubsetConfiguration subsetConfiguration) throws ConfigurationException { PulsarProducerConfig pulsarProducerConfig = new PulsarProducerConfig(); if (subsetConfiguration.containsKey(SingerConfigDef.COMPRESSION_TYPE)) { pulsarProducerConfig .setCompressionType(subsetConfiguration.getString(SingerConfigDef.COMPRESSION_TYPE)); } if (subsetConfiguration.containsKey(SingerConfigDef.PARTITIONER_CLASS)) { pulsarProducerConfig.setPartitionerClass(subsetConfiguration.getString(SingerConfigDef.PARTITIONER_CLASS)); } if (subsetConfiguration.containsKey(SingerConfigDef.PULSAR_SERVICE_URL)) { pulsarProducerConfig .setServiceUrl(subsetConfiguration.getString(SingerConfigDef.PULSAR_SERVICE_URL)); } else { throw new ConfigurationException( "Missing Pulsar service URL in producer config:" + SingerConfigDef.PULSAR_SERVICE_URL); } pulsarProducerConfig.setPulsarClusterSignature(pulsarProducerConfig.getServiceUrl()); return pulsarProducerConfig; }
Example #7
Source File: TestPatternFilter.java From big-c with Apache License 2.0 | 6 votes |
/** * Filters should handle white-listing correctly */ @Test public void includeOnlyShouldOnlyIncludeMatched() { SubsetConfiguration wl = new ConfigBuilder() .add("p.include", "foo") .add("p.include.tags", "foo:f").subset("p"); shouldAccept(wl, "foo"); shouldAccept(wl, Arrays.asList(tag("bar", "", ""), tag("foo", "", "f")), new boolean[] {false, true}); shouldAccept(wl, mockMetricsRecord("foo", Arrays.asList( tag("bar", "", ""), tag("foo", "", "f")))); shouldReject(wl, "bar"); shouldReject(wl, Arrays.asList(tag("bar", "", ""))); shouldReject(wl, Arrays.asList(tag("foo", "", "boo"))); shouldReject(wl, mockMetricsRecord("bar", Arrays.asList( tag("foo", "", "f")))); shouldReject(wl, mockMetricsRecord("foo", Arrays.asList( tag("bar", "", "")))); }
Example #8
Source File: TestPatternFilter.java From big-c with Apache License 2.0 | 6 votes |
/** * Filters should handle black-listing correctly */ @Test public void excludeOnlyShouldOnlyExcludeMatched() { SubsetConfiguration bl = new ConfigBuilder() .add("p.exclude", "foo") .add("p.exclude.tags", "foo:f").subset("p"); shouldAccept(bl, "bar"); shouldAccept(bl, Arrays.asList(tag("bar", "", ""))); shouldAccept(bl, mockMetricsRecord("bar", Arrays.asList( tag("bar", "", "")))); shouldReject(bl, "foo"); shouldReject(bl, Arrays.asList(tag("bar", "", ""), tag("foo", "", "f")), new boolean[] {true, false}); shouldReject(bl, mockMetricsRecord("foo", Arrays.asList( tag("bar", "", "")))); shouldReject(bl, mockMetricsRecord("bar", Arrays.asList( tag("bar", "", ""), tag("foo", "", "f")))); }
Example #9
Source File: TestPatternFilter.java From big-c with Apache License 2.0 | 6 votes |
/** * Filters should accepts unmatched item when both include and * exclude patterns are present. */ @Test public void shouldAcceptUnmatchedWhenBothAreConfigured() { SubsetConfiguration c = new ConfigBuilder() .add("p.include", "foo") .add("p.include.tags", "foo:f") .add("p.exclude", "bar") .add("p.exclude.tags", "bar:b").subset("p"); shouldAccept(c, "foo"); shouldAccept(c, Arrays.asList(tag("foo", "", "f"))); shouldAccept(c, mockMetricsRecord("foo", Arrays.asList( tag("foo", "", "f")))); shouldReject(c, "bar"); shouldReject(c, Arrays.asList(tag("bar", "", "b"))); shouldReject(c, mockMetricsRecord("bar", Arrays.asList( tag("foo", "", "f")))); shouldReject(c, mockMetricsRecord("foo", Arrays.asList( tag("bar", "", "b")))); shouldAccept(c, "foobar"); shouldAccept(c, Arrays.asList(tag("foobar", "", ""))); shouldAccept(c, mockMetricsRecord("foobar", Arrays.asList( tag("foobar", "", "")))); }
Example #10
Source File: LogConfigUtils.java From singer with Apache License 2.0 | 6 votes |
private static KubeConfig parseKubeConfig(PropertiesConfiguration configHeader) throws ConfigurationException { KubeConfig config = new KubeConfig(); AbstractConfiguration subsetConfig = new SubsetConfiguration(configHeader, SingerConfigDef.SINGER_KUBE_CONFIG_PREFIX); if (subsetConfig.containsKey(SingerConfigDef.KUBE_POLL_FREQUENCY_SECONDS)) { config.setPollFrequencyInSeconds( subsetConfig.getInt(SingerConfigDef.KUBE_POLL_FREQUENCY_SECONDS)); } if (subsetConfig.containsKey(SingerConfigDef.KUBE_POD_LOG_DIR)) { String logDirectory = subsetConfig.getString(SingerConfigDef.KUBE_POD_LOG_DIR); // normalize path before setting the property logDirectory = new File(logDirectory).toPath().normalize().toString() + "/"; if (!logDirectory.isEmpty() && !logDirectory.endsWith("/")) { logDirectory += "/"; } config.setPodLogDirectory(logDirectory); } if (subsetConfig.containsKey(SingerConfigDef.KUBE_DEFAULT_DELETION_TIMEOUT)) { config.setDefaultDeletionTimeoutInSeconds( subsetConfig.getInt(SingerConfigDef.KUBE_DEFAULT_DELETION_TIMEOUT)); } return config; }
Example #11
Source File: TestMetricsCollectorImpl.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void recordBuilderShouldNoOpIfFiltered() { SubsetConfiguration fc = new ConfigBuilder() .add("p.exclude", "foo").subset("p"); MetricsCollectorImpl mb = new MetricsCollectorImpl(); mb.setRecordFilter(newGlobFilter(fc)); MetricsRecordBuilderImpl rb = mb.addRecord("foo"); rb.tag(info("foo", ""), "value").addGauge(info("g0", ""), 1); assertEquals("no tags", 0, rb.tags().size()); assertEquals("no metrics", 0, rb.metrics().size()); assertNull("null record", rb.getRecord()); assertEquals("no records", 0, mb.getRecords().size()); }
Example #12
Source File: TestMetricsCollectorImpl.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testPerMetricFiltering() { SubsetConfiguration fc = new ConfigBuilder() .add("p.exclude", "foo").subset("p"); MetricsCollectorImpl mb = new MetricsCollectorImpl(); mb.setMetricFilter(newGlobFilter(fc)); MetricsRecordBuilderImpl rb = mb.addRecord("foo"); rb.tag(info("foo", ""), "").addCounter(info("c0", ""), 0) .addGauge(info("foo", ""), 1); assertEquals("1 tag", 1, rb.tags().size()); assertEquals("1 metric", 1, rb.metrics().size()); assertEquals("expect foo tag", "foo", rb.tags().get(0).name()); assertEquals("expect c0", "c0", rb.metrics().get(0).name()); }
Example #13
Source File: LogConfigUtils.java From singer with Apache License 2.0 | 5 votes |
public static SingerConfig parseFileBasedSingerConfig(String singerConfigFile) throws ConfigurationException { AbstractConfiguration singerConfiguration = new SubsetConfiguration( new PropertiesConfiguration(singerConfigFile), SingerConfigDef.SINGER_CONFIGURATION_PREFIX); singerConfiguration.setThrowExceptionOnMissing(true); SingerConfig result = parseCommonSingerConfigHeader(singerConfiguration); Set<String> logs = Sets.newHashSet(singerConfiguration.getStringArray("logs")); for (String log : logs) { AbstractConfiguration logConfiguration = new SubsetConfiguration(singerConfiguration, log + "."); result.addToLogConfigs(LogConfigUtils.parseLogConfig(log, logConfiguration)); } return result; }
Example #14
Source File: TestPatternFilter.java From hadoop with Apache License 2.0 | 5 votes |
/** * Filters should default to accept */ @Test public void emptyConfigShouldAccept() { SubsetConfiguration empty = new ConfigBuilder().subset(""); shouldAccept(empty, "anything"); shouldAccept(empty, Arrays.asList(tag("key", "desc", "value"))); shouldAccept(empty, mockMetricsRecord("anything", Arrays.asList( tag("key", "desc", "value")))); }
Example #15
Source File: TestPatternFilter.java From hadoop with Apache License 2.0 | 5 votes |
private static void shouldAcceptImpl(final boolean expectAcceptList, SubsetConfiguration conf, List<MetricsTag> tags, boolean[] expectedAcceptedSpec) { final MetricsFilter globFilter = newGlobFilter(conf); final MetricsFilter regexFilter = newRegexFilter(conf); // Test acceptance of the tag list: assertEquals("accepts "+ tags, expectAcceptList, globFilter.accepts(tags)); assertEquals("accepts "+ tags, expectAcceptList, regexFilter.accepts(tags)); // Test results on each of the individual tags: int acceptedCount = 0; for (int i=0; i<tags.size(); i++) { MetricsTag tag = tags.get(i); boolean actGlob = globFilter.accepts(tag); boolean actRegex = regexFilter.accepts(tag); assertEquals("accepts "+tag, expectedAcceptedSpec[i], actGlob); // Both the filters should give the same result: assertEquals(actGlob, actRegex); if (actGlob) { acceptedCount++; } } if (expectAcceptList) { // At least one individual tag should be accepted: assertTrue("No tag of the following accepted: " + tags, acceptedCount > 0); } else { // At least one individual tag should be rejected: assertTrue("No tag of the following rejected: " + tags, acceptedCount < tags.size()); } }
Example #16
Source File: GraphiteSink.java From hadoop with Apache License 2.0 | 5 votes |
@Override public void init(SubsetConfiguration conf) { // Get Graphite host configurations. final String serverHost = conf.getString(SERVER_HOST_KEY); final int serverPort = Integer.parseInt(conf.getString(SERVER_PORT_KEY)); // Get Graphite metrics graph prefix. metricsPrefix = conf.getString(METRICS_PREFIX); if (metricsPrefix == null) metricsPrefix = ""; graphite = new Graphite(serverHost, serverPort); graphite.connect(); }
Example #17
Source File: TestPatternFilter.java From hadoop with Apache License 2.0 | 5 votes |
/** * Include patterns should take precedence over exclude patterns */ @Test public void includeShouldOverrideExclude() { SubsetConfiguration c = new ConfigBuilder() .add("p.include", "foo") .add("p.include.tags", "foo:f") .add("p.exclude", "foo") .add("p.exclude.tags", "foo:f").subset("p"); shouldAccept(c, "foo"); shouldAccept(c, Arrays.asList(tag("foo", "", "f"))); shouldAccept(c, mockMetricsRecord("foo", Arrays.asList( tag("foo", "", "f")))); }
Example #18
Source File: ConfigUtils.java From singer with Apache License 2.0 | 5 votes |
public static Map<String, AuditConfig> parseAllAuditConfigs(AbstractConfiguration conf) { Map<String, AuditConfig> auditConfigs = new HashMap<>(); if (conf != null && conf.containsKey(LoggingAuditClientConfigDef.AUDITED_TOPIC_NAMES)) { for (String name : conf.getStringArray(LoggingAuditClientConfigDef.AUDITED_TOPIC_NAMES)) { try { auditConfigs.put(name, parseAuditConfig(new SubsetConfiguration(conf, name + "."))); } catch (ConfigurationException e) { LOG.error("Can't parse TopicAuditConfig for {}", name); } } } return auditConfigs; }
Example #19
Source File: GraphiteSink.java From big-c with Apache License 2.0 | 5 votes |
@Override public void init(SubsetConfiguration conf) { // Get Graphite host configurations. final String serverHost = conf.getString(SERVER_HOST_KEY); final int serverPort = Integer.parseInt(conf.getString(SERVER_PORT_KEY)); // Get Graphite metrics graph prefix. metricsPrefix = conf.getString(METRICS_PREFIX); if (metricsPrefix == null) metricsPrefix = ""; graphite = new Graphite(serverHost, serverPort); graphite.connect(); }
Example #20
Source File: FileSink.java From big-c with Apache License 2.0 | 5 votes |
@Override public void init(SubsetConfiguration conf) { String filename = conf.getString(FILENAME_KEY); try { writer = filename == null ? System.out : new PrintStream(new FileOutputStream(new File(filename)), true, "UTF-8"); } catch (Exception e) { throw new MetricsException("Error creating "+ filename, e); } }
Example #21
Source File: StandaloneExample.java From kylin with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { final MetricRegistry metrics = new MetricRegistry(); final HadoopMetrics2Reporter metrics2Reporter = HadoopMetrics2Reporter.forRegistry(metrics).build( DefaultMetricsSystem.initialize("StandaloneTest"), // The application-level name "Test", // Component name "Test", // Component description "Test"); // Name for each metric record final ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(metrics).build(); MetricsSystem metrics2 = DefaultMetricsSystem.instance(); // Writes to stdout without a filename configuration // Will be invoked every 10seconds by default FileSink sink = new FileSink(); metrics2.register("filesink", "filesink", sink); sink.init(new SubsetConfiguration(null, null) { public String getString(String key) { if (key.equals("filename")) { return null; } return super.getString(key); } }); // How often should the dropwizard reporter be invoked metrics2Reporter.start(500, TimeUnit.MILLISECONDS); // How often will the dropwziard metrics be logged to the console consoleReporter.start(2, TimeUnit.SECONDS); generateMetrics(metrics, 5000, 25, TimeUnit.MILLISECONDS, metrics2Reporter, 10); }
Example #22
Source File: GangliaSink30.java From big-c with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public void init(SubsetConfiguration conf) { super.init(conf); conf.setListDelimiter(','); Iterator<String> it = (Iterator<String>) conf.getKeys(); while (it.hasNext()) { String propertyName = it.next(); if (propertyName.startsWith(TAGS_FOR_PREFIX_PROPERTY_PREFIX)) { String contextName = propertyName.substring(TAGS_FOR_PREFIX_PROPERTY_PREFIX.length()); String[] tags = conf.getStringArray(propertyName); boolean useAllTags = false; Set<String> set = null; if (tags.length > 0) { set = new HashSet<String>(); for (String tag : tags) { tag = tag.trim(); useAllTags |= tag.equals("*"); if (tag.length() > 0) { set.add(tag); } } if (useAllTags) { set = null; } } useTagsMap.put(contextName, set); } } }
Example #23
Source File: TestGangliaSink.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testShouldCreateDatagramSocketByDefault() throws Exception { SubsetConfiguration conf = new ConfigBuilder() .subset("test.sink.ganglia"); GangliaSink30 gangliaSink = new GangliaSink30(); gangliaSink.init(conf); DatagramSocket socket = gangliaSink.getDatagramSocket(); assertFalse("Did not create DatagramSocket", socket == null || socket instanceof MulticastSocket); }
Example #24
Source File: TestGangliaSink.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testShouldCreateDatagramSocketIfMulticastIsDisabled() throws Exception { SubsetConfiguration conf = new ConfigBuilder() .add("test.sink.ganglia.multicast", false) .subset("test.sink.ganglia"); GangliaSink30 gangliaSink = new GangliaSink30(); gangliaSink.init(conf); DatagramSocket socket = gangliaSink.getDatagramSocket(); assertFalse("Did not create DatagramSocket", socket == null || socket instanceof MulticastSocket); }
Example #25
Source File: TestGangliaSink.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testShouldCreateMulticastSocket() throws Exception { SubsetConfiguration conf = new ConfigBuilder() .add("test.sink.ganglia.multicast", true) .subset("test.sink.ganglia"); GangliaSink30 gangliaSink = new GangliaSink30(); gangliaSink.init(conf); DatagramSocket socket = gangliaSink.getDatagramSocket(); assertTrue("Did not create MulticastSocket", socket != null && socket instanceof MulticastSocket); int ttl = ((MulticastSocket) socket).getTimeToLive(); assertEquals("Did not set default TTL", 1, ttl); }
Example #26
Source File: TestGangliaSink.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testShouldSetMulticastSocketTtl() throws Exception { SubsetConfiguration conf = new ConfigBuilder() .add("test.sink.ganglia.multicast", true) .add("test.sink.ganglia.multicast.ttl", 3) .subset("test.sink.ganglia"); GangliaSink30 gangliaSink = new GangliaSink30(); gangliaSink.init(conf); DatagramSocket socket = gangliaSink.getDatagramSocket(); assertTrue("Did not create MulticastSocket", socket != null && socket instanceof MulticastSocket); int ttl = ((MulticastSocket) socket).getTimeToLive(); assertEquals("Did not set TTL", 3, ttl); }
Example #27
Source File: TestMetricsCollectorImpl.java From big-c with Apache License 2.0 | 5 votes |
@Test public void recordBuilderShouldNoOpIfFiltered() { SubsetConfiguration fc = new ConfigBuilder() .add("p.exclude", "foo").subset("p"); MetricsCollectorImpl mb = new MetricsCollectorImpl(); mb.setRecordFilter(newGlobFilter(fc)); MetricsRecordBuilderImpl rb = mb.addRecord("foo"); rb.tag(info("foo", ""), "value").addGauge(info("g0", ""), 1); assertEquals("no tags", 0, rb.tags().size()); assertEquals("no metrics", 0, rb.metrics().size()); assertNull("null record", rb.getRecord()); assertEquals("no records", 0, mb.getRecords().size()); }
Example #28
Source File: TestPatternFilter.java From big-c with Apache License 2.0 | 5 votes |
/** * Filters should default to accept */ @Test public void emptyConfigShouldAccept() { SubsetConfiguration empty = new ConfigBuilder().subset(""); shouldAccept(empty, "anything"); shouldAccept(empty, Arrays.asList(tag("key", "desc", "value"))); shouldAccept(empty, mockMetricsRecord("anything", Arrays.asList( tag("key", "desc", "value")))); }
Example #29
Source File: TestPatternFilter.java From big-c with Apache License 2.0 | 5 votes |
/** * Include patterns should take precedence over exclude patterns */ @Test public void includeShouldOverrideExclude() { SubsetConfiguration c = new ConfigBuilder() .add("p.include", "foo") .add("p.include.tags", "foo:f") .add("p.exclude", "foo") .add("p.exclude.tags", "foo:f").subset("p"); shouldAccept(c, "foo"); shouldAccept(c, Arrays.asList(tag("foo", "", "f"))); shouldAccept(c, mockMetricsRecord("foo", Arrays.asList( tag("foo", "", "f")))); }
Example #30
Source File: TestPatternFilter.java From big-c with Apache License 2.0 | 5 votes |
private static void shouldAcceptImpl(final boolean expectAcceptList, SubsetConfiguration conf, List<MetricsTag> tags, boolean[] expectedAcceptedSpec) { final MetricsFilter globFilter = newGlobFilter(conf); final MetricsFilter regexFilter = newRegexFilter(conf); // Test acceptance of the tag list: assertEquals("accepts "+ tags, expectAcceptList, globFilter.accepts(tags)); assertEquals("accepts "+ tags, expectAcceptList, regexFilter.accepts(tags)); // Test results on each of the individual tags: int acceptedCount = 0; for (int i=0; i<tags.size(); i++) { MetricsTag tag = tags.get(i); boolean actGlob = globFilter.accepts(tag); boolean actRegex = regexFilter.accepts(tag); assertEquals("accepts "+tag, expectedAcceptedSpec[i], actGlob); // Both the filters should give the same result: assertEquals(actGlob, actRegex); if (actGlob) { acceptedCount++; } } if (expectAcceptList) { // At least one individual tag should be accepted: assertTrue("No tag of the following accepted: " + tags, acceptedCount > 0); } else { // At least one individual tag should be rejected: assertTrue("No tag of the following rejected: " + tags, acceptedCount < tags.size()); } }