Example #1
0
 private void validateRowOfDecimal(VoltTable vt, BigDecimal[] expected) {
   int len = expected.length;
   assertTrue(vt.advanceRow());
   for (int i = 0; i < len; i++) {
     BigDecimal actual = null;
     try {
       actual = vt.getDecimalAsBigDecimal(i);
     } catch (IllegalArgumentException ex) {
       ex.printStackTrace();
       fail();
     }
     if (expected[i] != null) {
       assertNotSame(null, actual);
       assertEquals(expected[i], actual);
     } else {
       if (isHSQL()) {
         // We don't actually use this with
         // HSQL.  So, just assert failure here.
         fail("HSQL is not used to test the Volt DECIMAL type.");
       } else {
         assertTrue(vt.wasNull());
       }
     }
   }
 }
Example #2
0
  protected static void validateTableColumnOfScalarDecimal(
      VoltTable vt, int col, BigDecimal[] expected) {
    assertNotNull(expected);
    assertEquals(expected.length, vt.getRowCount());
    int len = expected.length;
    for (int i = 0; i < len; i++) {
      assertTrue(vt.advanceRow());
      BigDecimal actual = vt.getDecimalAsBigDecimal(col);

      if (expected[i] == null) {
        assertTrue(vt.wasNull());
        assertEquals(null, actual);
      } else {
        BigDecimal rounded =
            expected[i].setScale(m_defaultScale, RoundingMode.valueOf(m_defaultRoundingMode));
        assertEquals(rounded, actual);
      }
    }
  }
Example #3
0
  protected static void validateRowOfLongs(String messagePrefix, VoltTable vt, long[] expected) {
    int len = expected.length;
    assertTrue(vt.advanceRow());
    for (int i = 0; i < len; i++) {
      String message = messagePrefix + "at column " + i + ", ";

      long actual = -10000000;
      // ENG-4295: hsql bug: HSQLBackend sometimes returns wrong column type.
      try {
        actual = vt.getLong(i);
      } catch (IllegalArgumentException ex) {
        try {
          actual = (long) vt.getDouble(i);
        } catch (IllegalArgumentException newEx) {
          try {
            actual = vt.getTimestampAsLong(i);
          } catch (IllegalArgumentException exTm) {
            try {
              actual = vt.getDecimalAsBigDecimal(i).longValueExact();
            } catch (IllegalArgumentException newerEx) {
              newerEx.printStackTrace();
              fail(message);
            }
          } catch (ArithmeticException newestEx) {
            newestEx.printStackTrace();
            fail(message);
          }
        }
      }

      // Long.MIN_VALUE is like a NULL
      if (expected[i] != Long.MIN_VALUE) {
        assertEquals(message, expected[i], actual);
      } else {
        VoltType type = vt.getColumnType(i);
        assertEquals(
            message + "expected null: ", Long.parseLong(type.getNullValue().toString()), actual);
      }
    }
  }