mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
improve repo tests
This commit is contained in:
parent
2d27ec6711
commit
18ee802133
2 changed files with 25 additions and 28 deletions
|
|
@ -36,9 +36,9 @@ public class ZeppelinHubRepo implements NotebookRepo {
|
|||
private String token;
|
||||
private ZeppelinhubRestApiHandler zeppelinhubHandler;
|
||||
|
||||
public ZeppelinHubRepo(ZeppelinConfiguration conf) throws IOException {
|
||||
public ZeppelinHubRepo(ZeppelinConfiguration conf) {
|
||||
String zeppelinHubUrl = getZeppelinHubUrl(conf);
|
||||
LOG.info("Initializing ZeppelinHub integration module version ?");
|
||||
LOG.info("Initializing ZeppelinHub integration module");
|
||||
token = conf.getString("ZEPPELINHUB_API_TOKEN", ZEPPELIN_CONF_PROP_NAME_TOKEN, "");
|
||||
zeppelinhubHandler = ZeppelinhubRestApiHandler.newInstance(zeppelinHubUrl, token);
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ public class ZeppelinHubRepo implements NotebookRepo {
|
|||
websocketClient.start();
|
||||
}
|
||||
|
||||
String getZeppelinHubWsUri(URI api) throws IOException {
|
||||
private String getZeppelinHubWsUri(URI api) throws IOException {
|
||||
URI apiRoot = api;
|
||||
String scheme = apiRoot.getScheme();
|
||||
int port = apiRoot.getPort();
|
||||
|
|
@ -74,7 +74,7 @@ public class ZeppelinHubRepo implements NotebookRepo {
|
|||
return ws + apiRoot.getHost() + ":" + port + "/async";
|
||||
}
|
||||
|
||||
private String getZeppelinhubWebsocketUri(ZeppelinConfiguration conf) {
|
||||
String getZeppelinhubWebsocketUri(ZeppelinConfiguration conf) {
|
||||
String zeppelinHubUri = StringUtils.EMPTY;
|
||||
try {
|
||||
zeppelinHubUri = getZeppelinHubWsUri(new URI(conf.getString("ZEPPELINHUB_API_ADDRESS",
|
||||
|
|
@ -98,10 +98,10 @@ public class ZeppelinHubRepo implements NotebookRepo {
|
|||
zeppelinhubHandler = zeppelinhub;
|
||||
}
|
||||
|
||||
private String getZeppelinHubUrl(ZeppelinConfiguration conf) throws IOException {
|
||||
String getZeppelinHubUrl(ZeppelinConfiguration conf) {
|
||||
if (conf == null) {
|
||||
LOG.error("Invalid configuration, cannot be null");
|
||||
throw new IOException("Configuration is null");
|
||||
LOG.error("Invalid configuration, cannot be null. Using default address {}", DEFAULT_SERVER);
|
||||
return DEFAULT_SERVER;
|
||||
}
|
||||
URI apiRoot;
|
||||
String zeppelinhubUrl;
|
||||
|
|
@ -111,10 +111,10 @@ public class ZeppelinHubRepo implements NotebookRepo {
|
|||
DEFAULT_SERVER);
|
||||
apiRoot = new URI(url);
|
||||
} catch (URISyntaxException e) {
|
||||
LOG.error("Invalid zeppelinhub url", e);
|
||||
throw new IOException(e);
|
||||
LOG.error("Invalid zeppelinhub url, using default address {}", DEFAULT_SERVER, e);
|
||||
return DEFAULT_SERVER;
|
||||
}
|
||||
|
||||
|
||||
String scheme = apiRoot.getScheme();
|
||||
if (scheme == null) {
|
||||
LOG.info("{} is not a valid zeppelinhub server address. proceed with default address {}",
|
||||
|
|
|
|||
|
|
@ -46,84 +46,81 @@ public class ZeppelinHubRepoTest {
|
|||
response = Files.toByteArray(pathOfNotebook);
|
||||
when(mockedZeppelinhubHandler.asyncGet("AAAAA")).thenReturn(new String(response));
|
||||
|
||||
//when(mockedZeppelinhubHandler.asyncDel("AAAAA")).thenReturn(true);
|
||||
//when(mockedZeppelinhubHandler.asyncDel("BBBBB")).thenReturn(false);
|
||||
|
||||
return mockedZeppelinhubHandler;
|
||||
}
|
||||
/*
|
||||
|
||||
@Test
|
||||
public void testGetZeppelinUrl() throws IOException {
|
||||
public void testGetZeppelinhubUrl() {
|
||||
System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, testAddr);
|
||||
|
||||
ZeppelinConfiguration config = new ZeppelinConfiguration();
|
||||
ZeppelinHubRepo repository = new ZeppelinHubRepo(config);
|
||||
assertThat(repository.getZeppelinUrl(config)).isEqualTo("http://zeppelinhub.ltd");
|
||||
assertThat(repository.getZeppelinHubUrl(config)).isEqualTo("http://zeppelinhub.ltd");
|
||||
|
||||
System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "yolow");
|
||||
|
||||
config = new ZeppelinConfiguration();
|
||||
repository = new ZeppelinHubRepo(config);
|
||||
assertThat(repository.getZeppelinUrl(config)).isEqualTo("https://www.zeppelinhub.com");
|
||||
assertThat(repository.getZeppelinHubUrl(config)).isEqualTo("https://www.zeppelinhub.com");
|
||||
|
||||
System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "http://zeppelinhub.ltd:4242");
|
||||
|
||||
config = new ZeppelinConfiguration();
|
||||
repository = new ZeppelinHubRepo(config);
|
||||
assertThat(repository.getZeppelinUrl(config)).isEqualTo("http://zeppelinhub.ltd:4242");
|
||||
assertThat(repository.getZeppelinHubUrl(config)).isEqualTo("http://zeppelinhub.ltd:4242");
|
||||
|
||||
System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "http://zeppelinhub.ltd:0");
|
||||
|
||||
config = new ZeppelinConfiguration();
|
||||
repository = new ZeppelinHubRepo(config);
|
||||
assertThat(repository.getZeppelinUrl(config)).isEqualTo("http://zeppelinhub.ltd");
|
||||
assertThat(repository.getZeppelinHubUrl(config)).isEqualTo("http://zeppelinhub.ltd");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetZeppelinHubWsEndpoint() throws IOException, URISyntaxException {
|
||||
public void testGetZeppelinHubWsEndpoint() {
|
||||
System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, testAddr);
|
||||
|
||||
ZeppelinConfiguration config = new ZeppelinConfiguration();
|
||||
ZeppelinHubRepo repository = new ZeppelinHubRepo(config);
|
||||
assertThat(repository.getZeppelinHubWsUri()).isEqualTo("ws://zeppelinhub.ltd:80/async");
|
||||
assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("ws://zeppelinhub.ltd:80/async");
|
||||
|
||||
System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "https://zeppelinhub.ltd");
|
||||
|
||||
config = new ZeppelinConfiguration();
|
||||
repository = new ZeppelinHubRepo(config);
|
||||
assertThat(repository.getZeppelinHubWsUri()).isEqualTo("wss://zeppelinhub.ltd:443/async");
|
||||
assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("wss://zeppelinhub.ltd:443/async");
|
||||
|
||||
System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "yolow");
|
||||
|
||||
config = new ZeppelinConfiguration();
|
||||
repository = new ZeppelinHubRepo(config);
|
||||
assertThat(repository.getZeppelinHubWsUri()).isEqualTo("wss://www.zeppelinhub.com:443/async");
|
||||
assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("wss://www.zeppelinhub.com:443/async");
|
||||
|
||||
System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "http://zeppelinhub.ltd:4242");
|
||||
|
||||
config = new ZeppelinConfiguration();
|
||||
repository = new ZeppelinHubRepo(config);
|
||||
assertThat(repository.getZeppelinHubWsUri()).isEqualTo("ws://zeppelinhub.ltd:4242/async");
|
||||
assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("ws://zeppelinhub.ltd:4242/async");
|
||||
|
||||
System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "https://www.zeppelinhub.com");
|
||||
|
||||
config = new ZeppelinConfiguration();
|
||||
repository = new ZeppelinHubRepo(config);
|
||||
assertThat(repository.getZeppelinHubWsUri()).isEqualTo("wss://www.zeppelinhub.com:443/async");
|
||||
assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("wss://www.zeppelinhub.com:443/async");
|
||||
|
||||
System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "http://www.zeppelinhub.com");
|
||||
|
||||
config = new ZeppelinConfiguration();
|
||||
repository = new ZeppelinHubRepo(config);
|
||||
assertThat(repository.getZeppelinHubWsUri()).isEqualTo("ws://www.zeppelinhub.com:80/async");
|
||||
assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("ws://www.zeppelinhub.com:80/async");
|
||||
|
||||
System.setProperty(ZeppelinHubRepo.ZEPPELIN_CONF_PROP_NAME_SERVER, "https://www.zeppelinhub.com:4242");
|
||||
|
||||
config = new ZeppelinConfiguration();
|
||||
repository = new ZeppelinHubRepo(config);
|
||||
assertThat(repository.getZeppelinHubWsUri()).isEqualTo("wss://www.zeppelinhub.com:4242/async");
|
||||
assertThat(repository.getZeppelinhubWebsocketUri(config)).isEqualTo("wss://www.zeppelinhub.com:4242/async");
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testGetAllNotes() throws IOException {
|
||||
List<NoteInfo> notebooks = repo.list();
|
||||
|
|
|
|||
Loading…
Reference in a new issue