List of usage examples for org.springframework.data.gemfire IndexType KEY
IndexType KEY
To view the source code for org.springframework.data.gemfire IndexType KEY.
Click Source Link
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test(expected = GemfireIndexException.class) public void createIndexThrowsIndexExistsExceptionAndCannotFindExistingIndexByDefinition() throws Exception { when(mockQueryService.getIndexes()).thenReturn(Collections.emptyList()); IndexFactoryBean indexFactoryBean = newIndexFactoryBean(); doThrow(new IndexExistsException("TEST")).when(indexFactoryBean).createKeyIndex(any(QueryService.class), anyString(), anyString(), anyString()); indexFactoryBean.setExpression("id"); indexFactoryBean.setFrom("/Example"); indexFactoryBean.setIgnoreIfExists(true); indexFactoryBean.setName("TestIndex"); indexFactoryBean.setOverride(true);// ww w . j a v a 2 s . c o m indexFactoryBean.setType(IndexType.KEY); assertThat(indexFactoryBean.isIgnoreIfExists()).isTrue(); assertThat(indexFactoryBean.isOverride()).isTrue(); try { indexFactoryBean.createIndex(mockQueryService, "TestIndex"); } catch (GemfireIndexException expected) { assertThat(expected).hasMessageStartingWith(String.format( "An Index with a different name [unknown] having the same definition [%s] already exists;" + " You may attempt to override the existing Index [unknown] with the new name [TestIndex]" + " by setting the 'override' property to 'true'", indexFactoryBean.toBasicIndexDefinition())); assertThat(expected).hasCauseInstanceOf(IndexExistsException.class); assertThat(expected.getCause()).hasMessage("TEST"); assertThat(expected.getCause()).hasNoCause(); throw expected; } finally { verify(mockQueryService, times(1)).getIndexes(); verify(indexFactoryBean, times(1)).createKeyIndex(eq(mockQueryService), eq("TestIndex"), eq("id"), eq("/Example")); } }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test public void tryToFindExistingIndexByDefinitionReturnsNull() { Index mockIndex = mockIndexWithDefinition("PrimaryIndex", "id", "/People", IndexType.HASH); when(mockQueryService.getIndexes()).thenReturn(Collections.singletonList(mockIndex)); assertThat(indexFactoryBean/*from w w w . j av a 2s . c om*/ .tryToFindExistingIndexByDefinition(mockQueryService, "key", "/People", IndexType.HASH) .orElse(null)).isNull(); assertThat(indexFactoryBean .tryToFindExistingIndexByDefinition(mockQueryService, "id", "/Persons", IndexType.HASH) .orElse(null)).isNull(); assertThat(indexFactoryBean .tryToFindExistingIndexByDefinition(mockQueryService, "id", "/People", IndexType.KEY).orElse(null)) .isNull(); verify(mockQueryService, times(3)).getIndexes(); }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test public void tryToFindExistingIndexByDefinitionWithQueryServiceHavingNoIndexesReturnsNull() { when(mockQueryService.getIndexes()).thenReturn(Collections.emptyList()); assertThat(indexFactoryBean//from w w w . j a va2 s .c o m .tryToFindExistingIndexByDefinition(mockQueryService, "id", "/People", IndexType.KEY).orElse(null)) .isNull(); verify(mockQueryService, times(1)).getIndexes(); }
From source file:org.springframework.data.gemfire.IndexFactoryBeanTest.java
@Test public void tryToFindExistingIndexByDefinitionWithQueryServiceReturningNullIndexesReturnsNull() { when(mockQueryService.getIndexes()).thenReturn(null); assertThat(indexFactoryBean//from ww w .j a va2 s .c om .tryToFindExistingIndexByDefinition(mockQueryService, "id", "/People", IndexType.KEY).orElse(null)) .isNull(); verify(mockQueryService, times(1)).getIndexes(); }