[NO ISSUE][TEST] Use reflection in ADMDataParserTest
Change-Id: I1f88684693230156f27327882f65f05ea3105a8e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2685
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
diff --git a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/parser/test/ADMDataParserTest.java b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/parser/test/ADMDataParserTest.java
index f06528e..1485f4f 100644
--- a/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/parser/test/ADMDataParserTest.java
+++ b/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/parser/test/ADMDataParserTest.java
@@ -22,21 +22,22 @@
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.asterix.external.parser.ADMDataParser;
+import org.apache.asterix.external.parser.AbstractDataParser;
import org.apache.asterix.om.base.AMutableDate;
import org.apache.asterix.om.base.AMutableDateTime;
import org.apache.asterix.om.base.AMutableTime;
import org.junit.Assert;
import org.junit.Test;
-import junit.extensions.PA;
-
public class ADMDataParserTest {
@Test
- public void test() throws IOException {
+ public void test() throws IOException, NoSuchMethodException, SecurityException, NoSuchFieldException {
String[] dates = { "-9537-08-04", "9656-06-03", "-9537-04-04", "9656-06-04", "-9537-10-04", "9626-09-05" };
AMutableDate[] parsedDates =
new AMutableDate[] { new AMutableDate(-4202630), new AMutableDate(2807408), new AMutableDate(-4202752),
@@ -55,6 +56,27 @@
new AMutableDateTime(-45286270768513L), new AMutableDateTime(151729886421653L),
new AMutableDateTime(5047449515758L), new AMutableDateTime(210721439419691L) };
+ Method parseDateMethod =
+ AbstractDataParser.class.getDeclaredMethod("parseDate", String.class, DataOutput.class);
+ parseDateMethod.setAccessible(true);
+
+ Field aDateField = AbstractDataParser.class.getDeclaredField("aDate");
+ aDateField.setAccessible(true);
+
+ Method parseTimeMethod =
+ AbstractDataParser.class.getDeclaredMethod("parseTime", String.class, DataOutput.class);
+ parseTimeMethod.setAccessible(true);
+
+ Field aTimeField = AbstractDataParser.class.getDeclaredField("aTime");
+ aTimeField.setAccessible(true);
+
+ Method parseDateTimeMethod =
+ AbstractDataParser.class.getDeclaredMethod("parseDateTime", String.class, DataOutput.class);
+ parseDateTimeMethod.setAccessible(true);
+
+ Field aDateTimeField = AbstractDataParser.class.getDeclaredField("aDateTime");
+ aDateTimeField.setAccessible(true);
+
Thread[] threads = new Thread[16];
AtomicInteger errorCount = new AtomicInteger(0);
for (int i = 0; i < threads.length; ++i) {
@@ -70,25 +92,22 @@
while (round++ < 10000) {
// Test parseDate.
for (int index = 0; index < dates.length; ++index) {
- PA.invokeMethod(parser, "parseDate(java.lang.String, java.io.DataOutput)", dates[index],
- dos);
- AMutableDate aDate = (AMutableDate) PA.getValue(parser, "aDate");
+ parseDateMethod.invoke(parser, dates[index], dos);
+ AMutableDate aDate = (AMutableDate) aDateField.get(parser);
Assert.assertTrue(aDate.equals(parsedDates[index]));
}
// Tests parseTime.
for (int index = 0; index < times.length; ++index) {
- PA.invokeMethod(parser, "parseTime(java.lang.String, java.io.DataOutput)", times[index],
- dos);
- AMutableTime aTime = (AMutableTime) PA.getValue(parser, "aTime");
+ parseTimeMethod.invoke(parser, times[index], dos);
+ AMutableTime aTime = (AMutableTime) aTimeField.get(parser);
Assert.assertTrue(aTime.equals(parsedTimes[index]));
}
// Tests parseDateTime.
for (int index = 0; index < dateTimes.length; ++index) {
- PA.invokeMethod(parser, "parseDateTime(java.lang.String, java.io.DataOutput)",
- dateTimes[index], dos);
- AMutableDateTime aDateTime = (AMutableDateTime) PA.getValue(parser, "aDateTime");
+ parseDateTimeMethod.invoke(parser, dateTimes[index], dos);
+ AMutableDateTime aDateTime = (AMutableDateTime) aDateTimeField.get(parser);
Assert.assertTrue(aDateTime.equals(parsedDateTimes[index]));
}
}
@@ -113,4 +132,4 @@
// Asserts no failure.
Assert.assertTrue(errorCount.get() == 0);
}
-}
+}
\ No newline at end of file