Exemplo n.º 1
1
  @Test
  public void should_create_entity_dao() throws Exception {
    PropertyMeta idMeta =
        PropertyMetaTestBuilder //
            .completeBean(Void.class, Long.class)
            .field("id")
            .build();

    EntityMeta entityMeta = new EntityMeta();
    entityMeta.setClusteredEntity(false);
    entityMeta.setTableName("cf");
    entityMeta.setIdMeta(idMeta);
    entityMeta.setIdClass(Long.class);
    entityMeta.setPropertyMetas(new HashMap<String, PropertyMeta>());

    factory.createDaosForEntity(
        cluster, keyspace, configContext, entityMeta, entityDaosMap, wideRowDaosMap);

    ThriftGenericEntityDao entityDao = entityDaosMap.get("cf");

    assertThat(entityDao).isNotNull();
    assertThat(entityDao.getColumnFamily()).isEqualTo("cf");
    assertThat(Whitebox.getInternalState(entityDao, "policy")).isSameAs(consistencyPolicy);
    assertThat(Whitebox.getInternalState(entityDao, "cluster")).isSameAs(cluster);
    assertThat(Whitebox.getInternalState(entityDao, "keyspace")).isSameAs(keyspace);
    assertThat(Whitebox.getInternalState(entityDao, "columnNameSerializer"))
        .isSameAs(COMPOSITE_SRZ);

    Pair<Class<Long>, Class<String>> rowAndValueClases =
        Whitebox.getInternalState(entityDao, "rowkeyAndValueClasses");
    assertThat(rowAndValueClases.left).isSameAs(Long.class);
    assertThat(rowAndValueClases.right).isSameAs(String.class);
  }
Exemplo n.º 2
0
  @Test
  public void should_create_value_less_clustered_entity_dao() throws Exception {

    PropertyMeta idMeta =
        PropertyMetaTestBuilder.valueClass(CompoundKey.class)
            .compClasses(Integer.class, String.class, UUID.class)
            .field("id")
            .type(PropertyType.EMBEDDED_ID)
            .build();

    EntityMeta entityMeta = new EntityMeta();
    entityMeta.setClusteredEntity(true);
    entityMeta.setIdMeta(idMeta);
    entityMeta.setTableName("cf");
    entityMeta.setPropertyMetas(ImmutableMap.of("id", idMeta));

    factory.createClusteredEntityDao(cluster, keyspace, configContext, entityMeta, wideRowDaosMap);

    ThriftGenericWideRowDao clusteredEntityDao = wideRowDaosMap.get("cf");

    assertThat(clusteredEntityDao).isNotNull();
    assertThat(clusteredEntityDao.getColumnFamily()).isEqualTo("cf");
    assertThat(Whitebox.getInternalState(clusteredEntityDao, "policy")).isSameAs(consistencyPolicy);
    assertThat(Whitebox.getInternalState(clusteredEntityDao, "cluster")).isSameAs(cluster);
    assertThat(Whitebox.getInternalState(clusteredEntityDao, "keyspace")).isSameAs(keyspace);
    assertThat(Whitebox.getInternalState(clusteredEntityDao, "columnNameSerializer"))
        .isSameAs(COMPOSITE_SRZ);

    Pair<Class<Integer>, Class<String>> rowAndValueClasses =
        Whitebox.getInternalState(clusteredEntityDao, "rowkeyAndValueClasses");
    assertThat(rowAndValueClasses.left).isSameAs(Integer.class);
    assertThat(rowAndValueClasses.right).isSameAs(String.class);
  }
Exemplo n.º 3
0
  @Test
  public void should_create_object_type_clustered_entity_dao() throws Exception {

    PropertyMeta idMeta =
        PropertyMetaTestBuilder.valueClass(CompoundKey.class)
            .compClasses(Integer.class, String.class, UUID.class)
            .field("id")
            .type(PropertyType.EMBEDDED_ID)
            .build();

    PropertyMeta pm =
        PropertyMetaTestBuilder.valueClass(UserBean.class).type(PropertyType.SIMPLE).build();

    EntityMeta entityMeta = new EntityMeta();
    entityMeta.setClusteredEntity(true);
    entityMeta.setIdMeta(idMeta);
    entityMeta.setTableName("cf");
    entityMeta.setPropertyMetas(ImmutableMap.of("id", idMeta, "pm", pm));
    entityMeta.setAllMetasExceptIdMeta(Arrays.asList(pm));
    entityMeta.setFirstMeta(pm);

    factory.createClusteredEntityDao(cluster, keyspace, configContext, entityMeta, wideRowDaosMap);

    ThriftGenericWideRowDao clusteredEntityDao = wideRowDaosMap.get("cf");

    Pair<Class<Integer>, Class<String>> rowAndValueClases =
        Whitebox.getInternalState(clusteredEntityDao, "rowkeyAndValueClasses");
    assertThat(rowAndValueClases.left).isSameAs(Integer.class);
    assertThat(rowAndValueClases.right).isSameAs(String.class);
  }
Exemplo n.º 4
0
  @Test
  public void should_create_counter_dao() throws Exception {
    ThriftCounterDao thriftCounterDao = factory.createCounterDao(cluster, keyspace, configContext);

    assertThat(thriftCounterDao).isNotNull();
    assertThat(Whitebox.getInternalState(thriftCounterDao, "policy")).isSameAs(consistencyPolicy);
    assertThat(Whitebox.getInternalState(thriftCounterDao, "cluster")).isSameAs(cluster);
    assertThat(Whitebox.getInternalState(thriftCounterDao, "keyspace")).isSameAs(keyspace);
    assertThat(Whitebox.getInternalState(thriftCounterDao, "columnNameSerializer"))
        .isSameAs(COMPOSITE_SRZ);
    Pair<Class<Composite>, Class<Long>> rowAndValueClases =
        Whitebox.getInternalState(thriftCounterDao, "rowkeyAndValueClasses");
    assertThat(rowAndValueClases.left).isSameAs(Composite.class);
    assertThat(rowAndValueClases.right).isSameAs(Long.class);
  }