예제 #1
0
  // The two following tests a really unit tests, but since the whole uses
  // CCMBridge.PerClassSingleNodeCluster, they'll still spawn a cluster even
  // you execute only them, so we keep them in the "long" group. We could
  // move them in another class but not sure where honestly (one could argue
  // that it would make more sense to move all the *other* tests to some
  // DataTypeIntegrationTest class).
  @Test(groups = "long")
  public void serializeDeserializeTest() {

    for (DataType dt : DataType.allPrimitiveTypes()) {
      if (exclude(dt)) continue;

      Object value = TestUtils.getFixedValue(dt);
      assertEquals(dt.deserialize(dt.serialize(value)), value);
    }

    try {
      DataType.bigint().serialize(4);
      fail("This should not have worked");
    } catch (InvalidTypeException e) {
      /* That's what we want */
    }

    try {
      ByteBuffer badValue = ByteBuffer.allocate(4);
      DataType.bigint().deserialize(badValue);
      fail("This should not have worked");
    } catch (InvalidTypeException e) {
      /* That's what we want */
    }
  }
예제 #2
0
  protected void discoverBeanMethods() {
    // break this off?
    Class<?> ft = field.getType();
    if (String.class.equals(ft)) {
      type = DataType.text();
    } else if (int.class.equals(ft)) {
      type = DataType.cint();
    } else if (Integer.class.equals(ft)) {
      type = DataType.cint();
    } else if (int.class.equals(ft)) {
      type = DataType.cint();
    } else if (Long.class.equals(ft)) {
      type = DataType.bigint();
    } else if (long.class.equals(ft)) {
      type = DataType.bigint();
    } else if (Date.class.equals(ft)) {
      type = DataType.timestamp();
    } else if (ByteBuffer.class.equals(ft)) {
      type = DataType.blob();
    } else if (Double.class.equals(ft)) {
      type = DataType.cdouble();
    } else if (double.class.equals(ft)) {
      type = DataType.cdouble();
    } else if (Float.class.equals(ft)) {
      type = DataType.cfloat();
    } else if (float.class.equals(ft)) {
      type = DataType.cfloat();
    } else if (Boolean.class.equals(ft)) {
      type = DataType.cboolean();
    }
    // how to differentiate type tuuid and uuid
    else if (UUID.class.equals(ft)) {
      type = DataType.uuid();
    }
    // java.sql.timestamp is not directly supported
    // remove it for now
    /*else if (Timestamp.class.equals(ft)) {
    	type = DataType.timestamp();
    }*/ else if (Map.class.isAssignableFrom(ft)) {
      type = DataType.map(DataType.text(), DataType.text());
    }

    // getter and setter find
    try {
      String getMeth =
          "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
      String setMeth =
          "set" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
      getter = field.getDeclaringClass().getDeclaredMethod(getMeth);
      setter = field.getDeclaringClass().getDeclaredMethod(setMeth, field.getType());
    } catch (Exception e) {
      // TODO some useful stuff: warning of non-conformance to java bean conventions
    }
  }
예제 #3
0
  private Object getValue(Row row, ColumnMapping mapping, Definition def) {
    Object value = null;

    if (DataType.text().equals(mapping.type)) {
      value = row.getString(def.getName());

    } else if (DataType.blob().equals(mapping.type)) {
      value = row.getBytes(def.getName());

    } else if (DataType.map(DataType.text(), DataType.text()).equals(mapping.type)) {
      value = row.getMap(def.getName(), String.class, String.class);

    } else if (DataType.cint().equals(mapping.type)) {
      value = row.getInt(def.getName());
    } else if (DataType.bigint().equals(mapping.type)) {
      value = row.getLong(def.getName());
    } else if (DataType.timestamp().equals(mapping.type)) {
      value = row.getDate(def.getName());
    } else if (DataType.blob().equals(mapping.type)) {
      value = row.getBytes(def.getName());
    } else if (DataType.cdouble().equals(mapping.type)) {
      value = row.getBytes(def.getName());
    } else if (DataType.cfloat().equals(mapping.type)) {
      value = row.getFloat(def.getName());
    } else if (DataType.inet().equals(mapping.type)) {
      value = row.getInet(def.getName());
    } else if (DataType.cboolean().equals(mapping.type)) {
      value = row.getBool(def.getName());
    } else if (DataType.uuid().equals(mapping.type)) {
      value = row.getUUID(def.getName());
    }
    // what if value is null? primitives won't like this
    return value;
  }
예제 #4
0
 public HecubaClientManager<Long> getHecubaClientManagerWithLongKeys(
     CassandraParamsBean parameters,
     HecubaConstants.CassandraClientImplementation cassandraManagerType) {
   switch (cassandraManagerType) {
     case ASTYANAX:
       return new AstyanaxBasedHecubaClientManager<>(
           parameters, com.netflix.astyanax.serializers.LongSerializer.get());
     case HECTOR:
       return new HectorBasedHecubaClientManager<>(
           parameters, me.prettyprint.cassandra.serializers.LongSerializer.get());
     case DATASTAX:
       return new DataStaxBasedHecubaClientManager<>(parameters, DataType.bigint());
     case DATASTAX_SHARED:
       return new DataStaxBasedSharedHecubaClientManager<>(parameters, DataType.bigint());
     default:
       throw new RuntimeException("Unhandled CassandraManagerType: " + cassandraManagerType);
   }
 }
  @Test
  public void should_notify_listener_on_cas_error() throws Exception {
    // Given
    wrapper =
        new RegularStatementWrapper(
            CompleteBean.class, rs, new Object[] {1}, ONE, NO_LISTENER, NO_SERIAL_CONSISTENCY);
    wrapper.invoker = invoker;
    when(rs.getQueryString()).thenReturn("INSERT INTO table IF NOT EXISTS");
    when(session.execute(rs)).thenReturn(resultSet);
    when(resultSet.one()).thenReturn(row);
    when(row.getBool(CAS_RESULT_COLUMN)).thenReturn(false);
    when(row.getColumnDefinitions()).thenReturn(columnDefinitions);

    when(columnDefinitions.iterator().hasNext()).thenReturn(true, true, false);
    Definition col1 = buildColumnDef("keyspace", "table", "[applied]", DataType.cboolean());
    Definition col2 = buildColumnDef("keyspace", "table", "id", DataType.bigint());
    when(columnDefinitions.iterator().next()).thenReturn(col1, col2);

    when(invoker.invokeOnRowForType(row, DataType.cboolean().asJavaClass(), "[applied]"))
        .thenReturn(false);
    when(invoker.invokeOnRowForType(row, DataType.bigint().asJavaClass(), "id")).thenReturn(10L);

    AchillesLightWeightTransactionException caughtEx = null;
    // When
    try {
      wrapper.execute(session);
    } catch (AchillesLightWeightTransactionException ace) {
      caughtEx = ace;
    }

    // Then
    verify(session).execute(rs);
    assertThat(caughtEx).isNotNull();
    assertThat(caughtEx.operation()).isEqualTo(INSERT);
    assertThat(caughtEx.currentValues())
        .contains(MapEntry.entry("[applied]", false), MapEntry.entry("id", 10L));
  }
예제 #6
0
  @Test(groups = "long")
  public void serializeDeserializeCollectionsTest() {

    List<String> l = Arrays.asList("foo", "bar");

    DataType dt = DataType.list(DataType.text());
    assertEquals(dt.deserialize(dt.serialize(l)), l);

    try {
      DataType.list(DataType.bigint()).serialize(l);
      fail("This should not have worked");
    } catch (InvalidTypeException e) {
      /* That's what we want */
    }
  }