You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2018/06/03 18:24:20 UTC

asterixdb git commit: [NO ISSUE][TEST] Use reflection in ADMDataParserTest

Repository: asterixdb
Updated Branches:
  refs/heads/release-0.9.4-pre-rc e2a536e98 -> 2a182c495


[NO ISSUE][TEST] Use reflection in ADMDataParserTest

Change-Id: I1f88684693230156f27327882f65f05ea3105a8e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2685
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mb...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/2a182c49
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/2a182c49
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/2a182c49

Branch: refs/heads/release-0.9.4-pre-rc
Commit: 2a182c495d311757f1aa9291ca407c8068f00ff2
Parents: e2a536e
Author: Abdullah Alamoudi <ba...@gmail.com>
Authored: Sun Jun 3 03:19:00 2018 +0300
Committer: Michael Blow <mb...@apache.org>
Committed: Sun Jun 3 11:23:40 2018 -0700

----------------------------------------------------------------------
 .../external/parser/test/ADMDataParserTest.java | 45 ++++++++++++++------
 1 file changed, 32 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/2a182c49/asterixdb/asterix-external-data/src/test/java/org/apache/asterix/external/parser/test/ADMDataParserTest.java
----------------------------------------------------------------------
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.ByteArrayOutputStream;
 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 @@ public class ADMDataParserTest {
                         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 @@ public class ADMDataParserTest {
                         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 @@ public class ADMDataParserTest {
         // Asserts no failure.
         Assert.assertTrue(errorCount.get() == 0);
     }
-}
+}
\ No newline at end of file