List of usage examples for org.springframework.data.gemfire IndexType FUNCTIONAL
IndexType FUNCTIONAL
To view the source code for org.springframework.data.gemfire IndexType FUNCTIONAL.
Click Source Link
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 {//w ww . ja v a 2 s. com 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(); } }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test(expected = GemfireIndexException.class) public void createIndexThrowsIndexNameConflictExceptionAndCannotFindExistingIndexByName() throws Exception { when(mockQueryService.getIndexes()).thenReturn(Collections.emptyList()); IndexFactoryBean indexFactoryBean = newIndexFactoryBean(); doThrow(new IndexNameConflictException("TEST")).when(indexFactoryBean) .createFunctionalIndex(eq(mockQueryService), anyString(), anyString(), anyString(), any()); indexFactoryBean.setExpression("id"); indexFactoryBean.setFrom("/Example"); indexFactoryBean.setIgnoreIfExists(true); indexFactoryBean.setName("TestIndex"); indexFactoryBean.setOverride(true);/*from www . j a v a2s . c o m*/ indexFactoryBean.setType(IndexType.FUNCTIONAL); assertThat(indexFactoryBean.isIgnoreIfExists()).isTrue(); assertThat(indexFactoryBean.isOverride()).isTrue(); try { indexFactoryBean.createIndex(mockQueryService, "TestIndex"); } catch (GemfireIndexException expected) { 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 [%s] and use the existing Index" + " definition [unknown] by setting the 'ignoreIfExists' property to 'true'", indexFactoryBean.toDetailedIndexDefinition())); 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(); } }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test public void createIndexThrowsIndexNameConflictExceptionAndIgnoresThisIndex() throws Exception { Index mockIndex = mockIndexWithDefinition("TestIndex", "price", "/Orders", IndexType.FUNCTIONAL); 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("price"); indexFactoryBean.setFrom("/Orders"); indexFactoryBean.setIgnoreIfExists(true); indexFactoryBean.setName("TestIndex"); indexFactoryBean.setOverride(true);/*from w ww.jav a2 s . co m*/ indexFactoryBean.setType(IndexType.FUNCTIONAL); assertThat(indexFactoryBean.isIgnoreIfExists()).isTrue(); assertThat(indexFactoryBean.isOverride()).isTrue(); assertThat(indexFactoryBean.createIndex(mockQueryService, "TestIndex")).isEqualTo(mockIndex); verify(indexFactoryBean, times(1)).createFunctionalIndex(eq(mockQueryService), eq("TestIndex"), eq("price"), eq("/Orders"), eq(null)); verifyZeroInteractions(mockLog); verify(mockQueryService, times(1)).getIndexes(); }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test public void createIndexThrowsIndexNameConflictExceptionAndIgnoresThisIndexWithWarning() throws Exception { Index mockIndex = mockIndexWithDefinition("TestIndex", "id", "/Orders", IndexType.PRIMARY_KEY); when(mockLog.isWarnEnabled()).thenReturn(true); 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("price"); indexFactoryBean.setFrom("/Orders"); indexFactoryBean.setIgnoreIfExists(true); indexFactoryBean.setName("TestIndex"); indexFactoryBean.setOverride(true);//from w w w . j ava 2 s.c o m indexFactoryBean.setType(IndexType.FUNCTIONAL); assertThat(indexFactoryBean.isIgnoreIfExists()).isTrue(); assertThat(indexFactoryBean.isOverride()).isTrue(); assertThat(indexFactoryBean.createIndex(mockQueryService, "TestIndex")).isEqualTo(mockIndex); String existingIndexDefinition = String.format(IndexFactoryBean.BASIC_INDEX_DEFINITION, "id", "/Orders", IndexType.PRIMARY_KEY); verify(indexFactoryBean, times(1)).createFunctionalIndex(eq(mockQueryService), eq("TestIndex"), eq("price"), eq("/Orders"), eq(null)); verify(mockLog, times(1)).warn(String.format( "WARNING! Returning existing Index [TestIndex] having a definition [%1$s] that does not match" + " the Index defined [%2$s] by this IndexFactoryBean [TestIndex]", existingIndexDefinition, indexFactoryBean.toBasicIndexDefinition())); verify(mockQueryService, times(1)).getIndexes(); }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test public void createIndexThrowsIndexNameConflictExceptionAndOverridesExistingIndexWithWarning() throws Exception { Index mockIndex = mockIndexWithDefinition("TestIndex", "price", "/Orders", IndexType.FUNCTIONAL); Index testIndex = mockIndexWithDefinition("TestIndex", "purchaseDate", "/Orders", IndexType.HASH); assertThat(mockIndex).isNotSameAs(testIndex); when(mockLog.isWarnEnabled()).thenReturn(true); when(mockQueryService.getIndexes()).thenReturn(Collections.singletonList(mockIndex)); IndexFactoryBean indexFactoryBean = newIndexFactoryBean(); doThrow(new IndexNameConflictException("TEST")).doReturn(testIndex).when(indexFactoryBean) .createHashIndex(any(QueryService.class), anyString(), anyString(), anyString(), any()); indexFactoryBean.setExpression("purchaseDate"); indexFactoryBean.setFrom("/Orders"); indexFactoryBean.setIgnoreIfExists(false); indexFactoryBean.setName("TestIndex"); indexFactoryBean.setOverride(true);/* www.j a v a 2s .co m*/ indexFactoryBean.setType(IndexType.HASH); assertThat(indexFactoryBean.isIgnoreIfExists()).isFalse(); assertThat(indexFactoryBean.isOverride()).isTrue(); assertThat(indexFactoryBean.createIndex(mockQueryService, "TestIndex")).isEqualTo(testIndex); String existingIndexDefinition = String.format(IndexFactoryBean.BASIC_INDEX_DEFINITION, mockIndex.getIndexedExpression(), mockIndex.getFromClause(), IndexType.valueOf(mockIndex.getType())); verify(indexFactoryBean, times(2)).createHashIndex(eq(mockQueryService), eq("TestIndex"), eq("purchaseDate"), eq("/Orders"), eq(null)); verify(mockLog, times(1)).warn(eq(String.format( "WARNING! Overriding existing Index [TestIndex] having a definition [%1$s] that does not match" + " the Index defined [%2$s] by this IndexFactoryBean [TestIndex]", existingIndexDefinition, indexFactoryBean.toBasicIndexDefinition()))); verify(mockQueryService, times(1)).getIndexes(); }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test public void tryToFindExistingIndexByDefinitionReturnsIndex() { Index mockIndexOne = mockIndexWithDefinition("PrimaryIndex", "id", "/People", IndexType.HASH); Index mockIndexTwo = mockIndexWithDefinition("SecondaryIndex", "id", "/People", IndexType.PRIMARY_KEY); Index mockIndexThree = mockIndexWithDefinition("TernaryIndex", "purchaseDate", "/Orders", IndexType.FUNCTIONAL); when(mockQueryService.getIndexes()).thenReturn(Arrays.asList(mockIndexOne, mockIndexTwo, mockIndexThree)); assertThat(indexFactoryBean//from w w w .jav a2s . c o m .tryToFindExistingIndexByDefinition(mockQueryService, "id", "/People", IndexType.PRIMARY_KEY) .orElse(null)).isSameAs(mockIndexTwo); assertThat(indexFactoryBean.tryToFindExistingIndexByDefinition(mockQueryService, "purchaseDate", "/Orders", IndexType.FUNCTIONAL).orElse(null)).isSameAs(mockIndexThree); assertThat(indexFactoryBean .tryToFindExistingIndexByDefinition(mockQueryService, "id", "/People", IndexType.HASH).orElse(null)) .isSameAs(mockIndexOne); verify(mockQueryService, times(3)).getIndexes(); }