gpt4 book ai didi

java - Cassandra-unit : java. io.IOException:连接被对等方重置

转载 作者:行者123 更新时间:2023-11-30 02:07:05 27 4
gpt4 key购买 nike

我正在使用 cassandra-unit 尝试嵌入式 Cassandra 并遇到以下异常,

com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /127.0.0.1 (com.datastax.driver.core.ConnectionException: [/127.0.0.1] Unexpected error during transport initialization (com.datastax.driver.core.TransportException: [/127.0.0.1] Unexpected exception triggered (java.io.IOException: Connection reset by peer))))
at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:195)
at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:78)
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1029)
at com.datastax.driver.core.Cluster.init(Cluster.java:120)
at com.datastax.driver.core.SessionManager.init(SessionManager.java:61)
at com.datastax.driver.core.SessionManager.execute(SessionManager.java:416)
at com.datastax.driver.core.SessionManager.executeQuery(SessionManager.java:453)
at com.datastax.driver.core.SessionManager.executeAsync(SessionManager.java:103)
at com.datastax.driver.core.SessionManager.execute(SessionManager.java:91)
at com.datastax.driver.core.SessionManager.execute(SessionManager.java:83)
at com.me.cc.bma.cassandra.test.main(test.java:30)

对于以下代码,

import com.datastax.driver.core.Cluster;
import org.cassandraunit.CQLDataLoader;
import org.cassandraunit.dataset.CQLDataSet;
import org.cassandraunit.dataset.cql.ClassPathCQLDataSet;
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
import org.apache.cassandra.config.DatabaseDescriptor;
import com.datastax.driver.core.ResultSet;
import static com.datastax.driver.core.Cluster.builder;
import com.datastax.driver.core.Session;


public class Test{

static Session session;

public static void main(String args[]) throws Exception {

EmbeddedCassandraServerHelper.startEmbeddedCassandra(500000L);
Cluster.Builder clusterBuilder = builder().addContactPoint("127.0.0.1").withClusterName(EmbeddedCassandraServerHelper.getClusterName()).withPort(7010);
Cluster cluster = clusterBuilder.build();
session = cluster.newSession();
try {
session.execute("CREATE KEYSPACE ci WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}");
session = cluster.connect("ci");
session.execute("CREATE TABLE login (l_id int)");
session.execute("insert into login(l_id) values(1)");
ResultSet res = session.execute("select * from login");
System.out.println(res.all());
}
catch (Exception ex) {
ex.printStackTrace();
}
}

}

版本:

  • Cassandra 驱动程序核心:3.5.0
  • Cassandra 单元:3.5.0.1

如有任何修复,我们将不胜感激!

最佳答案

将端口更改为 9142(默认 cassndra native 传输端口)。

Cluster.builder().addContactPoint("127.0.0.1").withClusterName(EmbeddedCassandraServerHelper.getClusterName()).withPort(9142);

同时在创建表查询中指定 PRIMARY KEY

关于java - Cassandra-unit : java. io.IOException:连接被对等方重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51059763/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com