logstash-filter-java_filter_example icon indicating copy to clipboard operation
logstash-filter-java_filter_example copied to clipboard

JavaFilterExampleTest.java fails due to ContextImpl argument count

Open cameronkerrnz opened this issue 4 years ago • 0 comments

After managing to get tests to run with the PR in #20, I found that with Logstash 7.9 (not sure where this change actually came about), the tests fail to run:

> Task :compileTestJava FAILED
/workspaces/logstash-filter-java_filter_example/src/test/java/org/logstashplugins/JavaFilterExampleTest.java:22: error: constructor ContextImpl in class ContextImpl cannot be applied to given types;
        Context context = new ContextImpl(null);
                          ^
  required: DeadLetterQueueWriter,Metric
  found: <null>
  reason: actual and formal argument lists differ in length
1 error

The Javadocs (harvested from the Logstash source code) list only the following constructor:

ContextImpl(DeadLetterQueueWriter dlqWriter, Metric metric) 

The following diff resolves the issue, I guess either the DeadLetterWriter or the Metrics argument was added, perhaps at the time of GA.

[builder@e4261c43934e logstash-filter-java_filter_example]$ git diff
diff --git a/src/test/java/org/logstashplugins/JavaFilterExampleTest.java b/src/test/java/org/logstashplugins/JavaFilterExampleTest.java
index aee8e2a..99ce06d 100644
--- a/src/test/java/org/logstashplugins/JavaFilterExampleTest.java
+++ b/src/test/java/org/logstashplugins/JavaFilterExampleTest.java
@@ -19,7 +19,7 @@ public class JavaFilterExampleTest {
     public void testJavaExampleFilter() {
         String sourceField = "foo";
         Configuration config = new ConfigurationImpl(Collections.singletonMap("source", sourceField));
-        Context context = new ContextImpl(null);
+        Context context = new ContextImpl(null, null);
         JavaFilterExample filter = new JavaFilterExample("test-id", config, context);
 
         Event e = new org.logstash.Event();

cameronkerrnz avatar Sep 21 '20 09:09 cameronkerrnz