You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/08/10 07:19:02 UTC
[camel] branch main updated: camel-flatpack - Fix flaky test and run tests in parallel to make it faster
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 0396c7d9090 camel-flatpack - Fix flaky test and run tests in parallel to make it faster
0396c7d9090 is described below
commit 0396c7d9090785e5c1b628f47b14ddc517bc6739
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 10 09:18:48 2023 +0200
camel-flatpack - Fix flaky test and run tests in parallel to make it faster
---
components/camel-flatpack/pom.xml | 1 +
.../flatpack/FlatpackConverterLoader.java | 2 ++
.../camel/component/flatpack/DataSetList.java | 32 ++++++++++++++--------
.../component/flatpack/FlatpackConverter.java | 20 ++++++++++++++
.../dataformat/flatpack/FlatpackDataFormat.java | 11 --------
.../flatpack/DelimitedAllowLongTest-context.xml | 1 +
.../DelimitedAllowShortAndLongTest-context.xml | 1 +
.../flatpack/DelimitedAllowShortTest-context.xml | 1 +
.../flatpack/FixedLengthAllowLongTest-context.xml | 1 +
.../FixedLengthAllowShortAndLongTest-context.xml | 1 +
.../flatpack/FixedLengthAllowShortTest-context.xml | 1 +
11 files changed, 50 insertions(+), 22 deletions(-)
diff --git a/components/camel-flatpack/pom.xml b/components/camel-flatpack/pom.xml
index 2eba5fd62e9..c8d02778bdd 100644
--- a/components/camel-flatpack/pom.xml
+++ b/components/camel-flatpack/pom.xml
@@ -32,6 +32,7 @@
<description>Camel FlatPack support</description>
<properties>
+ <camel.surefire.parallel>true</camel.surefire.parallel>
</properties>
<dependencies>
diff --git a/components/camel-flatpack/src/generated/java/org/apache/camel/component/flatpack/FlatpackConverterLoader.java b/components/camel-flatpack/src/generated/java/org/apache/camel/component/flatpack/FlatpackConverterLoader.java
index 292c83bd137..82c920463e1 100644
--- a/components/camel-flatpack/src/generated/java/org/apache/camel/component/flatpack/FlatpackConverterLoader.java
+++ b/components/camel-flatpack/src/generated/java/org/apache/camel/component/flatpack/FlatpackConverterLoader.java
@@ -47,6 +47,8 @@ public final class FlatpackConverterLoader implements TypeConverterLoader, Camel
(type, exchange, value) -> org.apache.camel.component.flatpack.FlatpackConverter.toList((net.sf.flatpack.DataSet) value));
addTypeConverter(registry, java.util.Map.class, net.sf.flatpack.DataSet.class, false,
(type, exchange, value) -> org.apache.camel.component.flatpack.FlatpackConverter.toMap((net.sf.flatpack.DataSet) value));
+ addTypeConverter(registry, java.util.Map.class, net.sf.flatpack.Record.class, false,
+ (type, exchange, value) -> org.apache.camel.component.flatpack.FlatpackConverter.toMap((net.sf.flatpack.Record) value));
addTypeConverter(registry, org.w3c.dom.Document.class, net.sf.flatpack.DataSet.class, false,
(type, exchange, value) -> org.apache.camel.component.flatpack.FlatpackConverter.toDocument((net.sf.flatpack.DataSet) value));
}
diff --git a/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java b/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java
index 6834036317b..b78d484f946 100644
--- a/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java
+++ b/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/DataSetList.java
@@ -26,6 +26,7 @@ import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Properties;
import java.util.function.DoubleSupplier;
@@ -62,23 +63,32 @@ public class DataSetList extends AbstractList<Map<String, Object>> implements Da
@Override
public Iterator<Map<String, Object>> iterator() {
- dataSet.goTop();
-
return new Iterator<Map<String, Object>>() {
- private int pos = 0;
+ Optional<Record> nextData = Optional.empty();
+ @Override
public boolean hasNext() {
- return pos < size();
- }
-
- public Map<String, Object> next() {
- dataSet.absolute(pos++);
- return FlatpackConverter.toMap(dataSet);
+ if (nextData.isPresent()) {
+ return true;
+ } else {
+ if (DataSetList.this.next()) {
+ nextData = dataSet.getRecord();
+ } else {
+ nextData = Optional.empty();
+ }
+ return nextData.isPresent();
+ }
}
@Override
- public void remove() {
- throw new UnsupportedOperationException("remove() not supported");
+ public Map<String, Object> next() {
+ if (nextData.isPresent() || hasNext()) {
+ final Record line = nextData.orElse(null);
+ nextData = Optional.empty();
+ return FlatpackConverter.toMap(line);
+ } else {
+ throw new NoSuchElementException();
+ }
}
};
}
diff --git a/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackConverter.java b/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackConverter.java
index d42b4bb90a2..30409ce029c 100644
--- a/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackConverter.java
+++ b/components/camel-flatpack/src/main/java/org/apache/camel/component/flatpack/FlatpackConverter.java
@@ -29,6 +29,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import net.sf.flatpack.DataSet;
+import net.sf.flatpack.Record;
import org.apache.camel.Converter;
@Converter(generateLoader = true)
@@ -45,6 +46,13 @@ public final class FlatpackConverter {
return map;
}
+ @Converter
+ public static Map<String, Object> toMap(Record record) {
+ Map<String, Object> map = new HashMap<>();
+ putValues(map, record);
+ return map;
+ }
+
@Converter
public static List<Map<String, Object>> toList(DataSet dataSet) {
List<Map<String, Object>> answer = new ArrayList<>();
@@ -101,6 +109,18 @@ public final class FlatpackConverter {
}
}
+ /**
+ * Puts the values of the record into the map
+ */
+ private static void putValues(Map<String, Object> map, Record record) {
+ String[] columns = record.getColumns();
+
+ for (String column : columns) {
+ String value = record.getString(column);
+ map.put(column, value);
+ }
+ }
+
private static Element createDatasetRecord(DataSet dataSet, Document doc) {
Element record;
if (dataSet.isRecordID(FlatpackComponent.HEADER_ID)) {
diff --git a/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java b/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java
index 3bff9204dfe..c575e22cc34 100644
--- a/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java
+++ b/components/camel-flatpack/src/main/java/org/apache/camel/dataformat/flatpack/FlatpackDataFormat.java
@@ -120,17 +120,6 @@ public class FlatpackDataFormat extends ServiceSupport implements DataFormat, Da
}
}
- @Override
- protected void doStart() throws Exception {
- // noop
- }
-
- @Override
- protected void doStop() throws Exception {
- // noop
-
- }
-
// Properties
//-------------------------------------------------------------------------
diff --git a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/DelimitedAllowLongTest-context.xml b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/DelimitedAllowLongTest-context.xml
index 72e8da2ac99..837c92401ec 100644
--- a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/DelimitedAllowLongTest-context.xml
+++ b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/DelimitedAllowLongTest-context.xml
@@ -32,6 +32,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file://src/test/data/delimLong?noop=true"/>
+ <convertBodyTo type="String"/>
<multicast>
<to uri="flatpack:delim:INVENTORY-Delimited.pzmap.xml?ignoreExtraColumns=true"/>
<to uri="direct:df"/>
diff --git a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/DelimitedAllowShortAndLongTest-context.xml b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/DelimitedAllowShortAndLongTest-context.xml
index d12a4ea7416..eabd2121071 100644
--- a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/DelimitedAllowShortAndLongTest-context.xml
+++ b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/DelimitedAllowShortAndLongTest-context.xml
@@ -33,6 +33,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file://src/test/data/delimMixed?noop=true"/>
+ <convertBodyTo type="String"/>
<multicast>
<to uri="flatpack:delim:INVENTORY-Delimited.pzmap.xml?ignoreExtraColumns=true&allowShortLines=true"/>
<to uri="direct:df"/>
diff --git a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/DelimitedAllowShortTest-context.xml b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/DelimitedAllowShortTest-context.xml
index 7ff0d495be4..214c8ac721b 100644
--- a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/DelimitedAllowShortTest-context.xml
+++ b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/DelimitedAllowShortTest-context.xml
@@ -32,6 +32,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file://src/test/data/delimShort?noop=true"/>
+ <convertBodyTo type="String"/>
<multicast>
<to uri="flatpack:delim:INVENTORY-Delimited.pzmap.xml?allowShortLines=true"/>
<to uri="direct:df"/>
diff --git a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowLongTest-context.xml b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowLongTest-context.xml
index 6058603587c..2549823423a 100644
--- a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowLongTest-context.xml
+++ b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowLongTest-context.xml
@@ -34,6 +34,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file://src/test/data/fixedLong?noop=true"/>
+ <convertBodyTo type="String"/>
<multicast>
<to uri="flatpack:fixed:PEOPLE-FixedLength.pzmap.xml?ignoreExtraColumns=true"/>
<to uri="direct:df"/>
diff --git a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowShortAndLongTest-context.xml b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowShortAndLongTest-context.xml
index 3ece958717a..3c93e0e1f3c 100644
--- a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowShortAndLongTest-context.xml
+++ b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowShortAndLongTest-context.xml
@@ -35,6 +35,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file://src/test/data/fixedMixed?noop=true"/>
+ <convertBodyTo type="String"/>
<multicast>
<to uri="flatpack:fixed:PEOPLE-FixedLength.pzmap.xml?ignoreExtraColumns=true&allowShortLines=true"/>
<to uri="direct:df"/>
diff --git a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowShortTest-context.xml b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowShortTest-context.xml
index ac8d4a6f7dd..9da73ec8ea5 100644
--- a/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowShortTest-context.xml
+++ b/components/camel-flatpack/src/test/resources/org/apache/camel/component/flatpack/FixedLengthAllowShortTest-context.xml
@@ -34,6 +34,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring" trace="true">
<route>
<from uri="file://src/test/data/fixedShort?noop=true"/>
+ <convertBodyTo type="String"/>
<multicast>
<to uri="flatpack:fixed:PEOPLE-FixedLength.pzmap.xml?allowShortLines=true"/>
<to uri="direct:df"/>