Ejemplo n.º 1
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);
  }
Ejemplo 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);
  }