Schema { static KeyspaceMetadata ensureKeyspaceMetadata(Session session, String keyspace) { KeyspaceMetadata keyspaceMetadata = getKeyspaceMetadata(session, keyspace); if (keyspaceMetadata == null) { throw new IllegalStateException( String.format( "Cannot read keyspace metadata for keyspace: %s and cluster: %s", keyspace, session.getCluster().getClusterName())); } return keyspaceMetadata; } Schema();   }
@Test public void ensureKeyspaceMetadata_failsWhenKeyspaceMetadataIsNotNull() { Session session = mock(Session.class); Cluster cluster = mock(Cluster.class); Metadata metadata = mock(Metadata.class); Host host = mock(Host.class); when(session.getCluster()).thenReturn(cluster); when(cluster.getMetadata()).thenReturn(metadata); when(metadata.getAllHosts()).thenReturn(Collections.singleton(host)); when(host.getCassandraVersion()).thenReturn(VersionNumber.parse("3.11.3")); assertThatThrownBy(() -> Schema.ensureKeyspaceMetadata(session, "zipkin2")) .isInstanceOf(RuntimeException.class) .hasMessageStartingWith("Cannot read keyspace metadata for keyspace"); }