Example usage for org.springframework.data.gemfire IndexFactoryBean DETAILED_INDEX_DEFINITION

List of usage examples for org.springframework.data.gemfire IndexFactoryBean DETAILED_INDEX_DEFINITION

Introduction

In this page you can find the example usage for org.springframework.data.gemfire IndexFactoryBean DETAILED_INDEX_DEFINITION.

Prototype

String DETAILED_INDEX_DEFINITION

To view the source code for org.springframework.data.gemfire IndexFactoryBean DETAILED_INDEX_DEFINITION.

Click Source Link

Usage

From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java

@Test(expected = GemfireIndexException.class)
public void createIndexThrowsIndexNameConflictException() throws Exception {

    Index mockIndex = mockIndexWithDefinition("TestIndex", "purchaseDate", "/Orders", IndexType.HASH);

    when(mockQueryService.getIndexes()).thenReturn(Collections.singletonList(mockIndex));

    IndexFactoryBean indexFactoryBean = newIndexFactoryBean();

    doThrow(new IndexNameConflictException("TEST")).when(indexFactoryBean)
            .createFunctionalIndex(eq(mockQueryService), anyString(), anyString(), anyString(), any());

    indexFactoryBean.setExpression("id");
    indexFactoryBean.setFrom("/Example");
    indexFactoryBean.setName("TestIndex");
    indexFactoryBean.setType(IndexType.FUNCTIONAL);

    assertThat(indexFactoryBean.isIgnoreIfExists()).isFalse();
    assertThat(indexFactoryBean.isOverride()).isFalse();

    try {/*from   ww w. j a  v a  2  s  .  c o m*/
        indexFactoryBean.createIndex(mockQueryService, "TestIndex");
    } catch (GemfireIndexException expected) {

        String existingIndexDefinition = String.format(IndexFactoryBean.DETAILED_INDEX_DEFINITION,
                mockIndex.getName(), mockIndex.getIndexedExpression(), mockIndex.getFromClause(), "unknown",
                IndexType.valueOf(mockIndex.getType()));

        assertThat(expected).hasMessageStartingWith(String.format(
                "An Index with the same name [TestIndex] having possibly a different definition already exists;"
                        + " you may choose to ignore this Index definition [%1$s] and use the existing Index"
                        + " definition [%2$s] by setting the 'ignoreIfExists' property to 'true'",
                indexFactoryBean.toDetailedIndexDefinition(), existingIndexDefinition));

        assertThat(expected).hasCauseInstanceOf(IndexNameConflictException.class);
        assertThat(expected.getCause()).hasMessage("TEST");
        assertThat(expected.getCause()).hasNoCause();

        throw expected;
    } finally {
        verify(indexFactoryBean, times(1)).createFunctionalIndex(eq(mockQueryService), eq("TestIndex"),
                eq("id"), eq("/Example"), eq(null));

        verifyZeroInteractions(mockLog);

        verify(mockQueryService, times(1)).getIndexes();
    }
}