Example usage for org.springframework.data.gemfire.config.support DefinedIndexesApplicationListener onApplicationEvent

List of usage examples for org.springframework.data.gemfire.config.support DefinedIndexesApplicationListener onApplicationEvent

Introduction

In this page you can find the example usage for org.springframework.data.gemfire.config.support DefinedIndexesApplicationListener onApplicationEvent.

Prototype

@Override
@SuppressWarnings("all")
public void onApplicationEvent(ContextRefreshedEvent event) 

Source Link

Document

Attempts to create all defined org.apache.geode.cache.query.Index Indexes using the QueryService , defineXxxIndex(..) API once the Spring ApplicationContext has been refreshed.

Usage

From source file:org.springframework.data.gemfire.config.support.DefinedIndexesApplicationListenerUnitTests.java

@Test
public void createDefinedIndexesThrowingAnExceptionIsLogged() throws Exception {
    when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(true);
    when(mockApplicationContext.getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class)))
            .thenReturn(mockQueryService);
    when(mockQueryService.createDefinedIndexes())
            .thenThrow(newMultiIndexCreationException("TestKey", new RuntimeException("TEST")));

    final Log mockLog = mock(Log.class);

    DefinedIndexesApplicationListener listener = new DefinedIndexesApplicationListener() {
        @Override/*from w w  w. j av a  2 s.  co m*/
        Log initLogger() {
            return mockLog;
        }
    };

    listener.onApplicationEvent(mockEvent);

    verify(mockEvent, times(1)).getApplicationContext();
    verify(mockApplicationContext, times(1)).containsBean(eq(QUERY_SERVICE_BEAN_NAME));
    verify(mockApplicationContext, times(1)).getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class));
    verify(mockQueryService, times(1)).createDefinedIndexes();
    verify(mockLog, times(1)).warn(startsWith("Failed to create pre-defined Indexes:"),
            isA(MultiIndexCreationException.class));
}