Skip to content

Commit 363b89b

Browse files
committed
Fixed compilation error due to libraries incompatibilities
- usage of `data.convertToString().split(context, delimiter, MINUS_ONE);` instead of `data.convertToString().split(delimiter, -1);` - avoid to extend BuffererdTokenir test cases from `org.logstash.RubyTestBase` which was introduced in #13159 - JDK 8 compatibilities: - `Arrays.asList` vs `List.of` - `assertThrows` method from JUnit5 not available in JUnit4 so reimplemented in the test
1 parent 5b864ab commit 363b89b

3 files changed

Lines changed: 29 additions & 21 deletions

File tree

logstash-core/src/test/java/org/logstash/common/BufferedTokenizerExtTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@
2525
import org.jruby.runtime.builtin.IRubyObject;
2626
import org.junit.Before;
2727
import org.junit.Test;
28-
import org.logstash.RubyTestBase;
2928
import org.logstash.RubyUtil;
3029

31-
import java.util.List;
30+
import java.util.Arrays;
3231

3332
import static org.junit.Assert.assertEquals;
3433
import static org.junit.Assert.assertTrue;
3534
import static org.logstash.RubyUtil.RUBY;
3635

3736
@SuppressWarnings("unchecked")
38-
public final class BufferedTokenizerExtTest extends RubyTestBase {
37+
public final class BufferedTokenizerExtTest {
3938

4039
private BufferedTokenizerExt sut;
4140
private ThreadContext context;
@@ -52,7 +51,7 @@ public void setUp() {
5251
public void shouldTokenizeASingleToken() {
5352
RubyArray<RubyString> tokens = (RubyArray<RubyString>) sut.extract(context, RubyUtil.RUBY.newString("foo\n"));
5453

55-
assertEquals(List.of("foo"), tokens);
54+
assertEquals(Arrays.asList("foo"), tokens);
5655
}
5756

5857
@Test
@@ -61,14 +60,14 @@ public void shouldMergeMultipleToken() {
6160
assertTrue(tokens.isEmpty());
6261

6362
tokens = (RubyArray<RubyString>) sut.extract(context, RubyUtil.RUBY.newString("bar\n"));
64-
assertEquals(List.of("foobar"), tokens);
63+
assertEquals(Arrays.asList("foobar"), tokens);
6564
}
6665

6766
@Test
6867
public void shouldTokenizeMultipleToken() {
6968
RubyArray<RubyString> tokens = (RubyArray<RubyString>) sut.extract(context, RubyUtil.RUBY.newString("foo\nbar\n"));
7069

71-
assertEquals(List.of("foo", "bar"), tokens);
70+
assertEquals(Arrays.asList("foo", "bar"), tokens);
7271
}
7372

7473
@Test
@@ -77,15 +76,15 @@ public void shouldIgnoreEmptyPayload() {
7776
assertTrue(tokens.isEmpty());
7877

7978
tokens = (RubyArray<RubyString>) sut.extract(context, RubyUtil.RUBY.newString("foo\nbar"));
80-
assertEquals(List.of("foo"), tokens);
79+
assertEquals(Arrays.asList("foo"), tokens);
8180
}
8281

8382
@Test
8483
public void shouldTokenizeEmptyPayloadWithNewline() {
8584
RubyArray<RubyString> tokens = (RubyArray<RubyString>) sut.extract(context, RubyUtil.RUBY.newString("\n"));
86-
assertEquals(List.of(""), tokens);
85+
assertEquals(Arrays.asList(""), tokens);
8786

8887
tokens = (RubyArray<RubyString>) sut.extract(context, RubyUtil.RUBY.newString("\n\n\n"));
89-
assertEquals(List.of("", "", ""), tokens);
88+
assertEquals(Arrays.asList("", "", ""), tokens);
9089
}
9190
}

logstash-core/src/test/java/org/logstash/common/BufferedTokenizerExtWithDelimiterTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@
2525
import org.jruby.runtime.builtin.IRubyObject;
2626
import org.junit.Before;
2727
import org.junit.Test;
28-
import org.logstash.RubyTestBase;
2928
import org.logstash.RubyUtil;
3029

31-
import java.util.List;
30+
import java.util.Arrays;
3231

3332
import static org.junit.Assert.assertEquals;
3433
import static org.junit.Assert.assertTrue;
3534
import static org.logstash.RubyUtil.RUBY;
3635

3736
@SuppressWarnings("unchecked")
38-
public final class BufferedTokenizerExtWithDelimiterTest extends RubyTestBase {
37+
public final class BufferedTokenizerExtWithDelimiterTest {
3938

4039
private BufferedTokenizerExt sut;
4140
private ThreadContext context;
@@ -52,7 +51,7 @@ public void setUp() {
5251
public void shouldTokenizeMultipleToken() {
5352
RubyArray<RubyString> tokens = (RubyArray<RubyString>) sut.extract(context, RubyUtil.RUBY.newString("foo||b|r||"));
5453

55-
assertEquals(List.of("foo", "b|r"), tokens);
54+
assertEquals(Arrays.asList("foo", "b|r"), tokens);
5655
}
5756

5857
@Test
@@ -61,6 +60,6 @@ public void shouldIgnoreEmptyPayload() {
6160
assertTrue(tokens.isEmpty());
6261

6362
tokens = (RubyArray<RubyString>) sut.extract(context, RubyUtil.RUBY.newString("foo||bar"));
64-
assertEquals(List.of("foo"), tokens);
63+
assertEquals(Arrays.asList("foo"), tokens);
6564
}
6665
}

logstash-core/src/test/java/org/logstash/common/BufferedTokenizerExtWithSizeLimitTest.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@
2424
import org.jruby.runtime.builtin.IRubyObject;
2525
import org.junit.Before;
2626
import org.junit.Test;
27-
import org.logstash.RubyTestBase;
2827
import org.logstash.RubyUtil;
2928

30-
import java.util.List;
29+
import java.util.Arrays;
3130

3231
import static org.hamcrest.MatcherAssert.assertThat;
3332
import static org.hamcrest.Matchers.containsString;
3433
import static org.junit.Assert.*;
3534
import static org.logstash.RubyUtil.RUBY;
3635

3736
@SuppressWarnings("unchecked")
38-
public final class BufferedTokenizerExtWithSizeLimitTest extends RubyTestBase {
37+
public final class BufferedTokenizerExtWithSizeLimitTest {
3938

4039
private BufferedTokenizerExt sut;
4140
private ThreadContext context;
@@ -52,7 +51,7 @@ public void setUp() {
5251
public void givenTokenWithinSizeLimitWhenExtractedThenReturnTokens() {
5352
RubyArray<RubyString> tokens = (RubyArray<RubyString>) sut.extract(context, RubyUtil.RUBY.newString("foo\nbar\n"));
5453

55-
assertEquals(List.of("foo", "bar"), tokens);
54+
assertEquals(Arrays.asList("foo", "bar"), tokens);
5655
}
5756

5857
@Test
@@ -71,7 +70,7 @@ public void givenExtractedThrownLimitErrorWhenFeedFreshDataThenReturnTokenStarti
7170
assertThat(thrownException.getMessage(), containsString("input buffer full"));
7271

7372
RubyArray<RubyString> tokens = (RubyArray<RubyString>) sut.extract(context, RubyUtil.RUBY.newString("\nanother"));
74-
assertEquals("After buffer full error should resume from the end of line", List.of("kaboom"), tokens);
73+
assertEquals("After buffer full error should resume from the end of line", Arrays.asList("kaboom"), tokens);
7574
}
7675

7776
@Test
@@ -84,7 +83,7 @@ public void givenExtractInvokedWithDifferentFramingAfterBufferFullErrorTWhenFeed
8483
assertThat(thrownException.getMessage(), containsString("input buffer full"));
8584

8685
RubyArray<RubyString> tokens = (RubyArray<RubyString>) sut.extract(context, RubyUtil.RUBY.newString("aa\nbbbb\nccc"));
87-
assertEquals(List.of("bbbb"), tokens);
86+
assertEquals(Arrays.asList("bbbb"), tokens);
8887
}
8988

9089
@Test
@@ -105,6 +104,17 @@ public void giveMultipleSegmentsThatGeneratesMultipleBufferFullErrorsThenIsAbleT
105104

106105
// now should resemble processing on c and d
107106
RubyArray<RubyString> tokens = (RubyArray<RubyString>) sut.extract(context, RubyUtil.RUBY.newString("ccc\nddd\n"));
108-
assertEquals(List.of("ccccc", "ddd"), tokens);
107+
assertEquals(Arrays.asList("ccccc", "ddd"), tokens);
108+
}
109+
110+
private static <T extends Throwable> Exception assertThrows(Class<T> excpClass, Runnable action) {
111+
try {
112+
action.run();
113+
fail("Expected an exception");
114+
return new IllegalStateException("Can't be reached");
115+
} catch (Exception t) {
116+
assertTrue(excpClass.isAssignableFrom(t.getClass()));
117+
return t;
118+
}
109119
}
110120
}

0 commit comments

Comments
 (0)