Github user fhueske commented on a diff in the pull request:
https://github.com/apache/incubator-flink/pull/247#discussion_r21404017
--- Diff:
flink-core/src/test/java/org/apache/flink/types/parser/ParserTestBase.java ---
@@ -307,4 +310,75 @@ public void testStaticParseMethodWithInvalidValues() {
return result;
}
+
+
+ private static byte[] concatenateMulti(String[] values, char[]
delimiter, boolean delimiterAtEnd) {
+ int len = 0;
+ for (String s : values) {
+ len += s.length() + delimiter.length;
+ }
+
+ if (!delimiterAtEnd) {
+ len -= delimiter.length;
+ }
+
+ int currPos = 0;
+ byte[] result = new byte[len];
+
+ for (int i = 0; i < values.length; i++) {
+ String s = values[i];
+
+ byte[] bytes = s.getBytes();
+ int numBytes = bytes.length;
+ System.arraycopy(bytes, 0, result, currPos, numBytes);
+ currPos += numBytes;
+
+ if (delimiterAtEnd || i < values.length-1) {
+ for(int k=0; k< delimiter.length; k++)
+ result[currPos++] = (byte) delimiter[k];
+ }
+ }
+ return result;
+ }
+
+
+ @Test
+ public void testConcatenatedMultiCharDelim() {
+ try {
+ String[] testValues = getValidTestValues();
+ T[] results = getValidTestResults();
+
+ byte[] allBytesWithDelimiter =
concatenateMulti(testValues, new char[] {'|','*','|'}, true);
+ byte[] allBytesNoDelimiterEnd =
concatenateMulti(testValues, new char[] {'|','*','|'}, false);
+
+ FieldParser<T> parser1 = getParser();
+ FieldParser<T> parser2 = getParser();
+
+ T val1 = parser1.createValue();
+ T val2 = parser2.createValue();
+
+ int pos1 = 0;
+ int pos2 = 0;
+
+ for (int i = 0; i < results.length; i++) {
+ pos1 =
parser1.parseField(allBytesWithDelimiter, pos1, allBytesWithDelimiter.length,
new char[] {'|','*','|'}, val1);
+
System.out.println(parser1.getLastResult().toString());
+ assertTrue("1. Parser declared the valid value
" + testValues[i] + " as invalid.", pos1 != -1);
+ T result1 = parser1.getLastResult();
+ assertEquals("1. Parser parsed wrong.",
results[i], result1);
+
+ pos2 =
parser2.parseField(allBytesNoDelimiterEnd, pos2, allBytesNoDelimiterEnd.length,
new char[] {'|','*','|'}, val2);
+
System.out.println(parser2.getLastResult().toString());
--- End diff --
Please remove print statement.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---