DriverRemoteAcceptor implements RemoteAcceptor { @Override public Object connect(final List<String> args) throws RemoteException { if (args.size() < 1) throw new RemoteException("Expects the location of a configuration file or variable name for a Cluster object as an argument"); try { final String fileOrVar = args.get(0); if (new File(fileOrVar).isFile()) this.currentCluster = Cluster.open(fileOrVar); else if (shellEnvironment.getVariable(fileOrVar) != null) { final Object o = shellEnvironment.getVariable(fileOrVar); if (o instanceof Cluster) { this.currentCluster = (Cluster) o; } } if (null == currentCluster) throw new RemoteException("Expects the location of a configuration file or variable name for a Cluster object as an argument"); final boolean useSession = args.size() >= 2 && (args.get(1).equals(TOKEN_SESSION) || args.get(1).equals(TOKEN_SESSION_MANAGED)); if (useSession) { final String sessionName = args.size() == 3 ? args.get(2) : UUID.randomUUID().toString(); session = Optional.of(sessionName); final boolean managed = args.get(1).equals(TOKEN_SESSION_MANAGED); this.currentClient = this.currentCluster.connect(sessionName, managed); } else { this.currentClient = this.currentCluster.connect(); } this.currentClient.init(); return String.format("Configured %s", this.currentCluster) + getSessionStringSegment(); } catch (final FileNotFoundException ignored) { throw new RemoteException("The 'connect' option must be accompanied by a valid configuration file"); } catch (final Exception ex) { throw new RemoteException("Error during 'connect' - " + ex.getMessage(), ex); } } DriverRemoteAcceptor(final GremlinShellEnvironment shellEnvironment); @Override Object connect(final List<String> args); @Override Object configure(final List<String> args); @Override Object submit(final List<String> args); @Override void close(); int getTimeout(); @Override boolean allowRemoteConsole(); @Override String toString(); static String getScript(final String submittedScript, final GremlinShellEnvironment shellEnvironment); static final int NO_TIMEOUT; static final String USER_AGENT; }
@Test(expected = RemoteException.class) public void shouldNotConnectWithEmptyArgs() throws Exception { acceptor.connect(new ArrayList<>()); }
@Test(expected = RemoteException.class) public void shouldNotConnectWithTooManyArgs() throws Exception { acceptor.connect(Arrays.asList("two", "too", "many")); }
@Test(expected = RemoteException.class) public void shouldNotConnectWithInvalidConfigFile() throws Exception { acceptor.connect(Arrays.asList("this-isnt-real.yaml")); }