Search in sources :

Example 1 with GeodeOqlInterpreter

use of org.apache.zeppelin.geode.GeodeOqlInterpreter in project zeppelin by apache.

the class GeodeOqlInterpreterTest method testOql.

private void testOql(Iterator<Object> queryResponseIterator, String expectedOutput, int maxResult) throws Exception {
    GeodeOqlInterpreter spyGeodeOqlInterpreter = spy(new GeodeOqlInterpreter(new Properties()));
    QueryService mockQueryService = mock(QueryService.class, RETURNS_DEEP_STUBS);
    when(spyGeodeOqlInterpreter.getQueryService()).thenReturn(mockQueryService);
    when(spyGeodeOqlInterpreter.getMaxResult()).thenReturn(maxResult);
    @SuppressWarnings("unchecked") SelectResults<Object> mockResults = mock(SelectResults.class);
    when(mockQueryService.newQuery(eq(OQL_QUERY)).execute()).thenReturn(mockResults);
    when(mockResults.iterator()).thenReturn(queryResponseIterator);
    InterpreterResult interpreterResult = spyGeodeOqlInterpreter.interpret(OQL_QUERY, null);
    assertEquals(Code.SUCCESS, interpreterResult.code());
    assertEquals(expectedOutput, interpreterResult.message().get(0).getData());
}
Also used : QueryService(com.gemstone.gemfire.cache.query.QueryService) GeodeOqlInterpreter(org.apache.zeppelin.geode.GeodeOqlInterpreter) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Properties(java.util.Properties)

Example 2 with GeodeOqlInterpreter

use of org.apache.zeppelin.geode.GeodeOqlInterpreter in project zeppelin by apache.

the class GeodeOqlInterpreterTest method oqlWithQueryException.

@Test
public void oqlWithQueryException() throws Exception {
    GeodeOqlInterpreter spyGeodeOqlInterpreter = spy(new GeodeOqlInterpreter(new Properties()));
    when(spyGeodeOqlInterpreter.getExceptionOnConnect()).thenReturn(new RuntimeException("Test Exception On Connect"));
    InterpreterResult interpreterResult = spyGeodeOqlInterpreter.interpret(OQL_QUERY, null);
    assertEquals(Code.ERROR, interpreterResult.code());
    assertEquals("Test Exception On Connect", interpreterResult.message().get(0).getData());
}
Also used : GeodeOqlInterpreter(org.apache.zeppelin.geode.GeodeOqlInterpreter) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with GeodeOqlInterpreter

use of org.apache.zeppelin.geode.GeodeOqlInterpreter in project zeppelin by apache.

the class GeodeOqlInterpreterTest method oqlWithExceptionOnConnect.

@Test
public void oqlWithExceptionOnConnect() throws Exception {
    GeodeOqlInterpreter spyGeodeOqlInterpreter = spy(new GeodeOqlInterpreter(new Properties()));
    when(spyGeodeOqlInterpreter.getQueryService()).thenThrow(new RuntimeException("Expected Test Exception!"));
    InterpreterResult interpreterResult = spyGeodeOqlInterpreter.interpret(OQL_QUERY, null);
    assertEquals(Code.ERROR, interpreterResult.code());
    assertEquals("Expected Test Exception!", interpreterResult.message().get(0).getData());
}
Also used : GeodeOqlInterpreter(org.apache.zeppelin.geode.GeodeOqlInterpreter) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with GeodeOqlInterpreter

use of org.apache.zeppelin.geode.GeodeOqlInterpreter in project zeppelin by apache.

the class GeodeOqlInterpreterTest method testOpenCommandIndempotency.

@Test
public void testOpenCommandIndempotency() {
    Properties properties = new Properties();
    properties.put("geode.locator.host", "localhost");
    properties.put("geode.locator.port", "10334");
    properties.put("geode.max.result", "1000");
    GeodeOqlInterpreter spyGeodeOqlInterpreter = spy(new GeodeOqlInterpreter(properties));
    // Ensure that an attempt to open new connection will clean any remaining connections
    spyGeodeOqlInterpreter.open();
    spyGeodeOqlInterpreter.open();
    spyGeodeOqlInterpreter.open();
    verify(spyGeodeOqlInterpreter, times(3)).open();
    verify(spyGeodeOqlInterpreter, times(3)).close();
}
Also used : GeodeOqlInterpreter(org.apache.zeppelin.geode.GeodeOqlInterpreter) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)4 GeodeOqlInterpreter (org.apache.zeppelin.geode.GeodeOqlInterpreter)4 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)3 Test (org.junit.Test)3 QueryService (com.gemstone.gemfire.cache.query.QueryService)1