Exemplo n.º 1
0
  @Test
  public void should_not_add_counter_field_if_non_clustered_counter_entity() throws Exception {
    PropertyMeta idMeta = valueClass(Long.class).type(PARTITION_KEY).propertyName("id").build();
    PropertyMeta counterPM = valueClass(Counter.class).type(COUNTER).propertyName("count").build();

    when(meta.getAllMetasExceptId()).thenReturn(asList(counterPM));
    when(meta.getIdMeta()).thenReturn(idMeta);
    when(tableMeta.getColumns()).thenReturn(Arrays.<ColumnMetadata>asList());
    when(meta.structure().isClusteredCounter()).thenReturn(false);

    // When
    updater.updateTableForEntity(session, meta, tableMeta);

    // Then
    verifyZeroInteractions(session);
  }
Exemplo n.º 2
0
  @Test
  public void should_update_table_with_new_clustered_counter_field() throws Exception {
    // Given
    PropertyMeta idMeta = valueClass(Long.class).type(PARTITION_KEY).cqlColumnName("id").build();
    PropertyMeta counterPM = valueClass(Counter.class).type(COUNTER).cqlColumnName("count").build();

    when(meta.getAllMetasExceptId()).thenReturn(asList(counterPM));
    when(meta.getIdMeta()).thenReturn(idMeta);
    when(tableMeta.getColumns()).thenReturn(Arrays.<ColumnMetadata>asList());
    when(meta.structure().isClusteredCounter()).thenReturn(true);

    // When
    updater.updateTableForEntity(session, meta, tableMeta);

    // Then
    verify(session).execute(stringCaptor.capture());
    assertThat(stringCaptor.getValue()).isEqualTo("\n\tALTER TABLE tableName ADD count counter");
  }
Exemplo n.º 3
0
  @Test
  public void should_update_table_with_new_list_field() throws Exception {
    // Given
    PropertyMeta idMeta = valueClass(Long.class).type(PARTITION_KEY).cqlColumnName("id").build();
    PropertyMeta listStringPM =
        valueClass(String.class).type(LIST).cqlColumnName("list_string").build();

    when(meta.getAllMetasExceptId()).thenReturn(asList(listStringPM));
    when(meta.getIdMeta()).thenReturn(idMeta);
    when(tableMeta.getColumns()).thenReturn(Arrays.<ColumnMetadata>asList());

    // When
    updater.updateTableForEntity(session, meta, tableMeta);

    // Then
    verify(session).execute(stringCaptor.capture());
    assertThat(stringCaptor.getValue())
        .isEqualTo("\n\tALTER TABLE tableName ADD list_string list<text>");
  }
Exemplo n.º 4
0
  @Test
  public void should_update_table_with_new_map_field() throws Exception {
    // Given
    PropertyMeta idMeta = valueClass(Long.class).type(PARTITION_KEY).cqlColumnName("id").build();
    PropertyMeta mapStringPM =
        completeBean(Integer.class, String.class).type(MAP).cqlColumnName("preferences").build();

    when(meta.getAllMetasExceptId()).thenReturn(asList(mapStringPM));
    when(meta.getIdMeta()).thenReturn(idMeta);
    when(tableMeta.getColumns()).thenReturn(Arrays.<ColumnMetadata>asList());

    // When
    updater.updateTableForEntity(session, meta, tableMeta);

    // Then
    verify(session).execute(stringCaptor.capture());
    assertThat(stringCaptor.getValue())
        .isEqualTo("\n\tALTER TABLE tableName ADD preferences map<int, text>");
  }
Exemplo n.º 5
0
  @Test
  public void should_update_table_with_new_indexed_simple_field() throws Exception {
    // Given
    PropertyMeta idMeta = valueClass(Long.class).type(PARTITION_KEY).cqlColumnName("id").build();
    PropertyMeta longColPM = valueClass(Long.class).type(SIMPLE).cqlColumnName("longcol").build();
    longColPM.setIndexProperties(new IndexProperties("long_index", "longCol"));

    when(meta.getAllMetasExceptId()).thenReturn(asList(longColPM));
    when(meta.getIdMeta()).thenReturn(idMeta);
    when(tableMeta.getColumns()).thenReturn(Arrays.<ColumnMetadata>asList());

    // When
    updater.updateTableForEntity(session, meta, tableMeta);

    // Then
    verify(session, Mockito.times(2)).execute(stringCaptor.capture());
    final List<String> updates = stringCaptor.getAllValues();
    assertThat(updates.get(0)).isEqualTo("\n\tALTER TABLE tableName ADD longcol bigint");
    assertThat(updates.get(1)).isEqualTo("\n\tCREATE INDEX long_index ON tableName(longcol)");
  }