ZEPPELIN-189: Close previous connection before opening new one

This commit is contained in:
tzolov 2015-08-06 08:45:17 +02:00
parent ab404e3713
commit c5eef90474
2 changed files with 29 additions and 3 deletions

View file

@ -86,9 +86,9 @@ public class GeodeOqlInterpreter extends Interpreter {
private Logger logger = LoggerFactory.getLogger(GeodeOqlInterpreter.class);
private static final String DEFAULT_PORT = "10334";
private static final String DEFAULT_HOST = "localhost";
private static final String DEFAULT_MAX_RESULT = "1000";
public static final String DEFAULT_PORT = "10334";
public static final String DEFAULT_HOST = "localhost";
public static final String DEFAULT_MAX_RESULT = "1000";
private static final char NEWLINE = '\n';
private static final char TAB = '\t';
@ -134,6 +134,9 @@ public class GeodeOqlInterpreter extends Interpreter {
public void open() {
logger.info("Geode open connection called!");
// Close the previous open connections.
close();
try {
maxResult = Integer.valueOf(getProperty(MAX_RESULT));

View file

@ -14,12 +14,16 @@
*/
package org.apache.zeppelin.geode;
import static org.apache.zeppelin.geode.GeodeOqlInterpreter.*;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
@ -50,6 +54,25 @@ public class GeodeOqlInterpreterTest {
return new ArrayList<Object>(Arrays.asList(items)).iterator();
}
@Test
public void testOpenCommandIndempotency() {
Properties properties = new Properties();
properties.put(LOCATOR_HOST, DEFAULT_HOST);
properties.put(LOCATOR_PORT, DEFAULT_PORT);
properties.put(MAX_RESULT, DEFAULT_MAX_RESULT);
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();
}
@Test
public void oqlNumberResponse() throws Exception {
testOql(asIterator(66, 67), "Result\n66\n67\n", 10);