Ejemplo n.º 1
0
  /** Generates the select statements that will be used in testing */
  private static HashMap<DataType, String> getPrimitiveSelectStatements() {
    HashMap<DataType, String> selectStatements = new HashMap<DataType, String>();

    for (DataType dataType : SAMPLE_DATA.keySet()) {
      selectStatements.put(dataType, String.format(BASIC_SELECT_FORMAT, dataType));
    }

    return selectStatements;
  }
Ejemplo n.º 2
0
  /** Generates the select statements that will be used in testing */
  private static HashMap<DataType, String> getCollectionSelectStatements() {
    HashMap<DataType, String> selectStatements = new HashMap<DataType, String>();

    String tableName;
    for (DataType dataType : SAMPLE_COLLECTIONS.keySet()) {
      tableName = helperGenerateTableName(dataType);
      selectStatements.put(dataType, String.format(BASIC_SELECT_FORMAT, tableName));
    }

    return selectStatements;
  }
Ejemplo n.º 3
0
  /** Generates the sample collections that will be used in testing */
  private static HashMap<DataType, Object> getSampleCollections() {
    HashMap<DataType, Object> sampleCollections = new HashMap<DataType, Object>();
    HashMap<DataType, Object> setAndListCollection;
    HashMap<DataType, HashMap<DataType, Object>> mapCollection;

    for (DataType.Name dataTypeName : DATA_TYPE_NON_PRIMITIVE_NAMES) {
      switch (dataTypeName) {
        case LIST:
          for (DataType typeArgument : DATA_TYPE_PRIMITIVES) {
            if (exclude(typeArgument)) continue;

            List<Object> list = new ArrayList<Object>();
            for (int i = 0; i < 5; i++) {
              list.add(SAMPLE_DATA.get(typeArgument));
            }

            setAndListCollection = new HashMap<DataType, Object>();
            setAndListCollection.put(typeArgument, list);
            sampleCollections.put(DataType.list(typeArgument), setAndListCollection);
          }
          break;
        case SET:
          for (DataType typeArgument : DATA_TYPE_PRIMITIVES) {
            if (exclude(typeArgument)) continue;

            Set<Object> set = new HashSet<Object>();
            for (int i = 0; i < 5; i++) {
              set.add(SAMPLE_DATA.get(typeArgument));
            }

            setAndListCollection = new HashMap<DataType, Object>();
            setAndListCollection.put(typeArgument, set);
            sampleCollections.put(DataType.set(typeArgument), setAndListCollection);
          }
          break;
        case MAP:
          for (DataType typeArgument1 : DATA_TYPE_PRIMITIVES) {
            if (exclude(typeArgument1)) continue;

            for (DataType typeArgument2 : DATA_TYPE_PRIMITIVES) {
              if (exclude(typeArgument2)) continue;

              HashMap<DataType, Object> map = new HashMap<DataType, Object>();
              map.put(typeArgument1, SAMPLE_DATA.get(typeArgument2));

              mapCollection = new HashMap<DataType, HashMap<DataType, Object>>();
              mapCollection.put(typeArgument1, map);
              sampleCollections.put(DataType.map(typeArgument1, typeArgument2), mapCollection);
            }
          }
          break;
        default:
          throw new RuntimeException("Missing handling of " + dataTypeName);
      }
    }

    return sampleCollections;
  }
Ejemplo n.º 4
0
  /** Test simple statement selects for all collection data types */
  @SuppressWarnings("unchecked")
  public void collectionSelectTest() throws Throwable {
    HashMap<DataType, Object> sampleValueMap;
    String execute_string;
    DataType typeArgument1;
    DataType typeArgument2;
    Row row;
    for (DataType dataType : COLLECTION_SELECT_STATEMENTS.keySet()) {
      execute_string = COLLECTION_SELECT_STATEMENTS.get(dataType);
      row = session.execute(execute_string).one();

      sampleValueMap = (HashMap<DataType, Object>) SAMPLE_COLLECTIONS.get(dataType);
      typeArgument1 = dataType.getTypeArguments().get(0);
      if (dataType.getName() == DataType.Name.MAP) {
        typeArgument2 = dataType.getTypeArguments().get(1);

        // Create a copy of the map that is being expected
        HashMap<DataType, Object> sampleMap =
            (HashMap<DataType, Object>) sampleValueMap.get(typeArgument1);
        Object mapKey = SAMPLE_DATA.get(sampleMap.keySet().iterator().next());
        Object mapValue = sampleMap.values().iterator().next();
        HashMap<Object, Object> expectedMap = new HashMap<Object, Object>();
        expectedMap.put(mapKey, mapValue);

        assertEquals(TestUtils.getValue(row, "k", typeArgument2), SAMPLE_DATA.get(typeArgument2));
        assertEquals(TestUtils.getValue(row, "v", dataType), expectedMap);
      } else {
        Object expectedValue = sampleValueMap.get(typeArgument1);

        assertEquals(TestUtils.getValue(row, "k", typeArgument1), SAMPLE_DATA.get(typeArgument1));
        assertEquals(TestUtils.getValue(row, "v", dataType), expectedValue);
      }
    }
    assertEquals(SAMPLE_COLLECTIONS.size(), 255);
    assertEquals(COLLECTION_SELECT_STATEMENTS.keySet().size(), SAMPLE_COLLECTIONS.size());
  }
Ejemplo n.º 5
0
  /** Generates the sample data that will be used in testing */
  private static HashMap<DataType, Object> getSampleData() {
    HashMap<DataType, Object> sampleData = new HashMap<DataType, Object>();

    for (DataType dataType : DATA_TYPE_PRIMITIVES) {
      switch (dataType.getName()) {
        case ASCII:
          sampleData.put(dataType, new String("ascii"));
          break;
        case BIGINT:
          sampleData.put(dataType, Long.MAX_VALUE);
          break;
        case BLOB:
          ByteBuffer bb = ByteBuffer.allocate(58);
          bb.putShort((short) 0xCAFE);
          bb.flip();
          sampleData.put(dataType, bb);
          break;
        case BOOLEAN:
          sampleData.put(dataType, Boolean.TRUE);
          break;
        case COUNTER:
          // Not supported in an insert statement
          break;
        case DECIMAL:
          sampleData.put(dataType, new BigDecimal("12.3E+7"));
          break;
        case DOUBLE:
          sampleData.put(dataType, Double.MAX_VALUE);
          break;
        case FLOAT:
          sampleData.put(dataType, Float.MAX_VALUE);
          break;
        case INET:
          try {
            sampleData.put(dataType, InetAddress.getByName("123.123.123.123"));
          } catch (java.net.UnknownHostException e) {
          }
          break;
        case INT:
          sampleData.put(dataType, Integer.MAX_VALUE);
          break;
        case TEXT:
          sampleData.put(dataType, new String("text"));
          break;
        case TIMESTAMP:
          sampleData.put(dataType, new Date(872835240000L));
          break;
        case TIMEUUID:
          sampleData.put(dataType, UUID.fromString("FE2B4360-28C6-11E2-81C1-0800200C9A66"));
          break;
        case UUID:
          sampleData.put(dataType, UUID.fromString("067e6162-3b6f-4ae2-a171-2470b63dff00"));
          break;
        case VARCHAR:
          sampleData.put(dataType, new String("varchar"));
          break;
        case VARINT:
          sampleData.put(dataType, new BigInteger(Integer.toString(Integer.MAX_VALUE) + "000"));
          break;
        default:
          throw new RuntimeException("Missing handling of " + dataType);
      }
    }

    return sampleData;
  }