首页 > 解决方案 > 如何从嵌入式 cassandra 获取描述性错误消息

问题描述

embedded cassandra用来运行单元测试。我注意到,如果任何cql语句失败,那么我看不到任何失败的描述性原因。例如。我正在运行以下两个失败的语句,因为我试图在不切换到键空间的情况下添加表

val statement1 =
        """
          |CREATE KEYSPACE test
          |  WITH REPLICATION = {
          |   'class' : 'SimpleStrategy',
          |   'replication_factor' : 1
          |  };
        """.stripMargin

      val statement3 =
        """
            |CREATE TABLE users (
            |    bucket int,
            |    email text,
            |    firstname text,
            |    lastname text,
            |    authprovider text,
            |    password text,
            |    confirmed boolean,
            |    id UUID,
            |    hasher text,
            |    salt text,
            |    PRIMARY KEY ((bucket, email), authprovider,firstname, lastname) )
        """.stripMargin

val cqlStatements:CqlStatements = new CqlStatements(statement1,statement3)

")
      val testCassandra = repoTestEnv.testCassandra


      try {
        testCassandra.start()
        testCassandra.executeScripts(cqlStatements)
      } finally testCassandra.stop()

但我没有看到正确的错误。我看到以下内容并不能准确说明问题所在

[info] c.g.n.e.c.l.WindowsCassandraNode - Apache Cassandra Node '7276' is started
[info] c.g.n.e.c.l.LocalCassandraDatabase - Apache Cassandra '3.11.1' is started (20811 ms)
[warn] c.d.d.c.Connection - /127.0.0.1:9042 did not send an authentication challenge; This is suspicious because the driver expects authentication (configured auth provider = com.datastax.driver.core.PlainTextAuthProvider)
[warn] c.d.d.c.Connection - /127.0.0.1:9042 did not send an authentication challenge; This is suspicious because the driver expects authentication (configured auth provider = com.datastax.driver.core.PlainTextAuthProvider)
[debug] c.g.n.e.c.t.u.CqlUtils - Executing Script: CqlStatements [
CREATE KEYSPACE test
  WITH REPLICATION = {
   'class' : 'SimpleStrategy',
   'replication_factor' : 1
  };
        ,
CREATE TABLE users (
    bucket int,
    email text,
    firstname text,
    lastname text,
    authprovider text,
    password text,
    confirmed boolean,
    id UUID,
    hasher text,
    salt text,
    PRIMARY KEY ((bucket, email), authprovider,firstname, lastname) )
        ]
[debug] c.g.n.e.c.t.u.CqlUtils - Executing Statement: 
CREATE KEYSPACE test
  WITH REPLICATION = {
   'class' : 'SimpleStrategy',
   'replication_factor' : 1
  };

[info] c.g.n.e.c.Cassandra - INFO  [Native-Transport-Requests-1] 2019-05-29 07:50:00,788 MigrationManager.java:310 - Create new Keyspace: KeyspaceMetadata{name=test, params=KeyspaceParams{durable_writes=true, replication=ReplicationParams{class=org.apache.cassandra.locator.SimpleStrategy, replication_factor=1}}, tables=[], views=[], functions=[], types=[]}
[debug] c.g.n.e.c.t.u.CqlUtils - Executing Statement: 
CREATE TABLE users (
    bucket int,
    email text,
    firstname text,
    lastname text,
    authprovider text,
    password text,
    confirmed boolean,
    id UUID,
    hasher text,
    salt text,
    PRIMARY KEY ((bucket, email), authprovider,firstname, lastname) )

[debug] c.g.n.e.c.t.TestCassandra - Stop TestCassandra 3.11.1
[info] c.g.n.e.c.l.LocalCassandraDatabase - Stop Apache Cassandra '3.11.1'
[debug] c.g.n.e.c.l.RunProcess - Execute 'powershell -ExecutionPolicy Unrestricted C:\Users\manu\AppData\Local\Temp\embedded-cassandra\3.11.1\0d155e04-97d5-4927-87ac-d46824a77c32\bin\stop-server.ps1 -p C:\Users\manu\AppData\Local\Temp\embedded-cassandra\3.11.1\0d155e04-97d5-4927-87ac-d46824a77c32\1da63488-2624-4141-a49e-174203b7edc4' within a directory 'C:\Users\manu\AppData\Local\Temp\embedded-cassandra\3.11.1\0d155e04-97d5-4927-87ac-d46824a77c32'
[info] c.g.n.e.c.Cassandra - INFO  [StorageServiceShutdownHook] 2019-05-29 07:50:03,926 HintsService.java:220 - Paused hints dispatch
[info] c.g.n.e.c.Cassandra - INFO  [StorageServiceShutdownHook] 2019-05-29 07:50:03,933 Server.java:176 - Stop listening for CQL clients
[info] c.g.n.e.c.Cassandra - INFO  [StorageServiceShutdownHook] 2019-05-29 07:50:03,934 Gossiper.java:1532 - Announcing shutdown
[info] c.g.n.e.c.Cassandra - INFO  [StorageServiceShutdownHook] 2019-05-29 07:50:03,938 StorageService.java:2268 - Node localhost/127.0.0.1 state jump to shutdown
[info] c.g.n.e.c.Cassandra - INFO  [StorageServiceShutdownHook] 2019-05-29 07:50:05,941 MessagingService.java:984 - Waiting for messaging service to quiesce
[info] c.g.n.e.c.Cassandra - INFO  [ACCEPT-localhost/127.0.0.1] 2019-05-29 07:50:05,948 MessagingService.java:1338 - MessagingService has terminated the accept() thread
[info] c.g.n.e.c.Cassandra - INFO  [StorageServiceShutdownHook] 2019-05-29 07:50:06,076 HintsService.java:220 - Paused hints dispatch
[info] c.g.n.e.c.l.WindowsCassandraNode - Successfully sent ctrl+c to process with id: 7276.
[info] c.g.n.e.c.l.WindowsCassandraNode - Apache Cassandra Node '7276' is stopped
[info] c.g.n.e.c.l.LocalCassandraDatabase - Apache Cassandra '3.11.1' is stopped (3490 ms)
[info] c.g.n.e.c.l.LocalCassandraDatabase - The working directory 'C:\Users\manu\AppData\Local\Temp\embedded-cassandra\3.11.1\0d155e04-97d5-4927-87ac-d46824a77c32' was deleted.
[debug] c.g.n.e.c.t.TestCassandra - TestCassandra 3.11.1 is stopped

Unable to start TestCassandra 3.11.1
com.github.nosan.embedded.cassandra.CassandraException: Unable to start TestCassandra 3.11.1
    at com.github.nosan.embedded.cassandra.test.TestCassandra.start(TestCassandra.java:128)
    at UnitSpecs.RepositorySpecs.UsersRepositorySpecs.$anonfun$new$3(UsersRepositorySpecs.scala:146)
    at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)

理想情况下,我应该得到类似于我使用时会得到的错误cqlsh

有没有办法获得更多的描述性错误?

标签: cassandra-3.0

解决方案


我找不到我Caused的未打印但我找到了这个解决方法

  try {
    testCassandra.start()
    println(s"cassandra state is ${testCassandra.getState}")
    testCassandra.executeScripts(cqlStatements)
    //println(s"result of execution is ${result}")
    //val settings = testCassandra.getSettings
    //println(s"settings are ${settings}")
  } catch {
    case e:Exception => {
      println(s"exception ${e} caused by ${e.getCause}")
      //println(s"caused by ${e.getCause()}")
     fail( new Throwable(e.getCause))
    }
  }finally {
    testCassandra.stop()

  }

以上印刷品

org.scalatest.exceptions.TestFailedException was thrown.
ScalaTestFailureLocation: UnitSpecs.RepositorySpecs.UsersRepositorySpecs at (UsersRepositorySpecs.scala:157)
...
Caused by: java.lang.Throwable: com.datastax.driver.core.exceptions.InvalidQueryException: No keyspace has been specified. USE a keyspace, or explicitly specify keyspace.tablename

推荐阅读