List of usage examples for org.springframework.data.gemfire IndexFactoryBean BASIC_INDEX_DEFINITION
String BASIC_INDEX_DEFINITION
To view the source code for org.springframework.data.gemfire IndexFactoryBean BASIC_INDEX_DEFINITION.
Click Source Link
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);// w w w . j a va 2 s.co 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);//from w ww . j a v a 2 s.com 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(expected = GemfireIndexException.class) public void createIndexThrowsIndexNameConflictExceptionAndOverrideThrowsRuntimeException() throws Exception { Index mockIndex = mockIndexWithDefinition("MockIndex", "purchaseDate", "/Example", IndexType.HASH); when(mockLog.isWarnEnabled()).thenReturn(true); when(mockQueryService.getIndexes()).thenReturn(Collections.singletonList(mockIndex)) .thenReturn(Collections.emptyList()); IndexFactoryBean indexFactoryBean = newIndexFactoryBean(); doThrow(new IndexNameConflictException("TEST")).doThrow(new RuntimeException("RETRY")) .when(indexFactoryBean)/*from ww w . j av a 2 s . c om*/ .createKeyIndex(any(QueryService.class), anyString(), anyString(), anyString()); indexFactoryBean.setExpression("id"); indexFactoryBean.setFrom("/Example"); indexFactoryBean.setIgnoreIfExists(false); indexFactoryBean.setName("MockIndex"); indexFactoryBean.setOverride(true); indexFactoryBean.setType(IndexType.PRIMARY_KEY); assertThat(indexFactoryBean.isIgnoreIfExists()).isFalse(); assertThat(indexFactoryBean.isOverride()).isTrue(); try { indexFactoryBean.createIndex(mockQueryService, "MockIndex"); } catch (GemfireIndexException expected) { assertThat(expected).hasMessageStartingWith( "Attempt to 'override' existing Index [MockIndex] with the Index that would be created by this" + " IndexFactoryBean [MockIndex] failed; you should verify the state of your system" + " and make sure the previously existing Index [MockIndex] still exits"); assertThat(expected).hasCauseInstanceOf(GemfireIndexException.class); assertThat(expected.getCause()).hasMessageStartingWith( String.format("Failed to create Index [%s]", indexFactoryBean.toDetailedIndexDefinition())); assertThat(expected.getCause()).hasCauseInstanceOf(RuntimeException.class); assertThat(expected.getCause().getCause()).hasMessageStartingWith("RETRY"); assertThat(expected.getCause().getCause()).hasNoCause(); throw expected; } finally { String existingIndexDefinition = String.format(IndexFactoryBean.BASIC_INDEX_DEFINITION, mockIndex.getIndexedExpression(), mockIndex.getFromClause(), IndexType.valueOf(mockIndex.getType())); verify(indexFactoryBean, times(2)).createKeyIndex(eq(mockQueryService), eq("MockIndex"), eq("id"), eq("/Example")); verify(mockLog, times(1)).warn(eq(String.format( "WARNING! Overriding existing Index [MockIndex] having a definition [%1$s] that does not match" + " the Index defined [%2$s] by this IndexFactoryBean [MockIndex]", existingIndexDefinition, indexFactoryBean.toBasicIndexDefinition()))); verify(mockQueryService, times(1)).getIndexes(); } }