@Test(groups = "unit") public void should_create_proper_already_exists_exception_for_tables() { AlreadyExistsException e = new AlreadyExistsException(address1, "keyspace1", "table1"); assertThat(e.getMessage()).isEqualTo("Table keyspace1.table1 already exists"); assertThat(e.getKeyspace()).isEqualTo("keyspace1"); assertThat(e.getTable()).isEqualTo("table1"); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); e = e.copy(address2); assertThat(e.getMessage()).isEqualTo("Table keyspace1.table1 already exists"); assertThat(e.getKeyspace()).isEqualTo("keyspace1"); assertThat(e.getTable()).isEqualTo("table1"); assertThat(e.getAddress()).isEqualTo(address2); assertThat(e.getHost()).isEqualTo(address2.getAddress()); }
public AlreadyExistsException(InetSocketAddress address, String keyspace, String table) { super(makeMsg(keyspace, table)); this.address = address; this.keyspace = keyspace; this.table = table; }
@Override public DriverException copy() { return new AlreadyExistsException(getAddress(), getMessage(), this, keyspace, table); }
/** * Create a copy of this exception with a nicer stack trace, and including the coordinator address * that caused this exception to be raised. * * <p>This method is mainly intended for internal use by the driver and exists mainly because: * * <ol> * <li>the original exception was decoded from a response frame and at that time, the * coordinator address was not available; and * <li>the newly-created exception will refer to the current thread in its stack trace, which * generally yields a more user-friendly stack trace that the original one. * </ol> * * @param address The full address of the host that caused this exception to be thrown. * @return a copy/clone of this exception, but with the given host address instead of the original * one. */ public AlreadyExistsException copy(InetSocketAddress address) { return new AlreadyExistsException(address, getMessage(), this, keyspace, table); } }
} catch (AlreadyExistsException e) { String expected = String.format("Keyspace %s already exists", keyspace.toLowerCase()); assertEquals(e.getMessage(), expected); assertEquals(e.getKeyspace(), keyspace.toLowerCase()); assertEquals(e.getTable(), null); assertEquals(e.wasTableCreation(), false); assertEquals(e.getHost(), ccm().addressOfNode(1).getAddress()); assertEquals(e.getAddress(), ccm().addressOfNode(1)); } catch (AlreadyExistsException e) { assertEquals(e.getKeyspace(), keyspace.toLowerCase()); assertEquals(e.getTable(), table.toLowerCase()); assertEquals(e.wasTableCreation(), true); assertEquals(e.getHost(), ccm().addressOfNode(1).getAddress()); assertEquals(e.getAddress(), ccm().addressOfNode(1));
return aex.wasTableCreation() ? new CassandraTableExistsException(aex.getTable(), exception.getMessage(), exception) : new CassandraKeyspaceExistsException(aex.getKeyspace(), exception.getMessage(), exception);
return new InvalidConfigurationInQueryException(host, message); case ALREADY_EXISTS: return ((AlreadyExistsException) infos).copy(host); case UNPREPARED: return new UnpreparedException(host, message);
/** * Convert the given Cassandra driver exception to a corresponding ConnectorException if possible, otherwise * return a generic ConnectorException. * * @param de The Cassandra driver exception * @param name The fully qualified name of the resource which was attempting to be accessed or modified at time of * error * @return A connector exception wrapping the DriverException */ public ConnectorException toConnectorException( @Nonnull @NonNull final DriverException de, @Nonnull @NonNull final QualifiedName name ) { if (de instanceof AlreadyExistsException) { final AlreadyExistsException ae = (AlreadyExistsException) de; if (ae.wasTableCreation()) { return new TableAlreadyExistsException(name, ae); } else { return new DatabaseAlreadyExistsException(name, ae); } } else { return new ConnectorException(de.getMessage(), de); } } }
} catch (AlreadyExistsException e) { String expected = String.format("Keyspace %s already exists", keyspace.toLowerCase()); assertEquals(e.getMessage(), expected); assertEquals(e.getKeyspace(), keyspace.toLowerCase()); assertEquals(e.getTable(), null); assertEquals(e.wasTableCreation(), false); assertEquals(e.getHost(), ccm().addressOfNode(1).getAddress()); assertEquals(e.getAddress(), ccm().addressOfNode(1)); } catch (AlreadyExistsException e) { assertEquals(e.getKeyspace(), keyspace.toLowerCase()); assertEquals(e.getTable(), table.toLowerCase()); assertEquals(e.wasTableCreation(), true); assertEquals(e.getHost(), ccm().addressOfNode(1).getAddress()); assertEquals(e.getAddress(), ccm().addressOfNode(1));
@Override public DriverException copy() { return new AlreadyExistsException(getAddress(), getMessage(), this, keyspace, table); }
@Override public DriverException copy() { return new AlreadyExistsException(getMessage(), this, keyspace, table); } }
return aex.wasTableCreation() ? new CassandraTableExistsException(aex.getTable(), message, exception) : new CassandraKeyspaceExistsException(aex.getKeyspace(), message, exception);
public DriverException asException(InetSocketAddress host) { switch (code) { case SERVER_ERROR: return new DriverInternalError(String.format("An unexpected error occurred server side on %s: %s", host, message)); case PROTOCOL_ERROR: return new DriverInternalError("An unexpected protocol error occurred. This is a bug in this library, please report: " + message); case BAD_CREDENTIALS: return new AuthenticationException(host, message); case UNAVAILABLE: return ((UnavailableException)infos).copy(); // We copy to have a nice stack trace case OVERLOADED: return new DriverInternalError(String.format("Queried host (%s) was overloaded; this shouldn't happen, another node should have been tried", host)); case IS_BOOTSTRAPPING: return new DriverInternalError(String.format("Queried host (%s) was bootstrapping; this shouldn't happen, another node should have been tried", host)); case TRUNCATE_ERROR: return new TruncateException(message); case WRITE_TIMEOUT: return ((WriteTimeoutException)infos).copy(); case READ_TIMEOUT: return ((ReadTimeoutException)infos).copy(); case SYNTAX_ERROR: return new SyntaxError(message); case UNAUTHORIZED: return new UnauthorizedException(message); case INVALID: return new InvalidQueryException(message); case CONFIG_ERROR: return new InvalidConfigurationInQueryException(message); case ALREADY_EXISTS: return ((AlreadyExistsException)infos).copy(); case UNPREPARED: return new DriverInternalError(String.format("A prepared query was submitted on %s but was not known of that node; this shouldn't happen, the query should have been re-prepared", host)); default: return new DriverInternalError(String.format("Unknown protocol error code %s returned by %s. The error message was: %s", code, host, message)); } }
/** * Convert the given Cassandra driver exception to a corresponding ConnectorException if possible, otherwise * return a generic ConnectorException. * * @param de The Cassandra driver exception * @param name The fully qualified name of the resource which was attempting to be accessed or modified at time of * error * @return A connector exception wrapping the DriverException */ public ConnectorException toConnectorException( @Nonnull @NonNull final DriverException de, @Nonnull @NonNull final QualifiedName name ) { if (de instanceof AlreadyExistsException) { final AlreadyExistsException ae = (AlreadyExistsException) de; if (ae.wasTableCreation()) { return new TableAlreadyExistsException(name, ae); } else { return new DatabaseAlreadyExistsException(name, ae); } } else { return new ConnectorException(de.getMessage(), de); } } }
@Test(groups = "unit") public void should_create_proper_already_exists_exception_for_keyspaces() { AlreadyExistsException e = new AlreadyExistsException(address1, "keyspace1", ""); assertThat(e.getMessage()).isEqualTo("Keyspace keyspace1 already exists"); assertThat(e.getKeyspace()).isEqualTo("keyspace1"); assertThat(e.getTable()).isNull(); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); e = e.copy(address2); assertThat(e.getMessage()).isEqualTo("Keyspace keyspace1 already exists"); assertThat(e.getKeyspace()).isEqualTo("keyspace1"); assertThat(e.getTable()).isNull(); assertThat(e.getAddress()).isEqualTo(address2); assertThat(e.getHost()).isEqualTo(address2.getAddress()); }
@Override public DriverException copy() { return new AlreadyExistsException(getAddress(), getMessage(), this, keyspace, table); }
/** * Create a copy of this exception with a nicer stack trace, and including the coordinator * address that caused this exception to be raised. * <p/> * This method is mainly intended for internal use by the driver and exists mainly because: * <ol> * <li>the original exception was decoded from a response frame * and at that time, the coordinator address was not available; and</li> * <li>the newly-created exception will refer to the current thread in its stack trace, * which generally yields a more user-friendly stack trace that the original one.</li> * </ol> * * @param address The full address of the host that caused this exception to be thrown. * @return a copy/clone of this exception, but with the given host address instead of the original one. */ public AlreadyExistsException copy(InetSocketAddress address) { return new AlreadyExistsException(address, getMessage(), this, keyspace, table); }
return new InvalidConfigurationInQueryException(host, message); case ALREADY_EXISTS: return ((AlreadyExistsException) infos).copy(host); case UNPREPARED: return new UnpreparedException(host, message);
public AlreadyExistsException(String keyspace, String table) { super(makeMsg(keyspace, table)); this.keyspace = keyspace; this.table = table; }
@Test(groups = "unit") public void should_create_proper_already_exists_exception_for_tables() { AlreadyExistsException e = new AlreadyExistsException(address1, "keyspace1", "table1"); assertThat(e.getMessage()).isEqualTo("Table keyspace1.table1 already exists"); assertThat(e.getKeyspace()).isEqualTo("keyspace1"); assertThat(e.getTable()).isEqualTo("table1"); assertThat(e.getAddress()).isEqualTo(address1); assertThat(e.getHost()).isEqualTo(address1.getAddress()); e = e.copy(address2); assertThat(e.getMessage()).isEqualTo("Table keyspace1.table1 already exists"); assertThat(e.getKeyspace()).isEqualTo("keyspace1"); assertThat(e.getTable()).isEqualTo("table1"); assertThat(e.getAddress()).isEqualTo(address2); assertThat(e.getHost()).isEqualTo(address2.getAddress()); }