2 za02157100419 za02157100419 于 2018.02.13 21:03 提问

java.net.SocketException: Socket is not connected 5C

solr集群测试
package com.taotao.search;

import java.io.IOException;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;

public class SolrCloudTest {

@Test
public void testAddDocument() throws Exception {
    // 创建一个和solr集群的连接
    // 参数就是zookeeper的地址列表,使用逗号分隔
    String zkHost = "192.168.248.135:2181,192.168.248.135:2182,192.168.248.135:2183";
    CloudSolrServer solrServer = new CloudSolrServer(zkHost);
    // 设置默认的collection
    solrServer.setDefaultCollection("collection2");
    // 创建一个文档对象
    SolrInputDocument document = new SolrInputDocument();
    // 向文档中添加域
    document.addField("id", "test001");
    document.addField("item_title", "测试商品");
    // 把文档添加到索引库
    solrServer.add(document);
    // 提交
    solrServer.commit();
}

@Test
public void deleteDocument() throws SolrServerException, IOException {
    // 创建一个和solr集群的连接
    // 参数就是zookeeper的地址列表,使用逗号分隔
    String zkHost = "192.168.248.135:2181,192.168.248.135:2182,192.168.248.135:2183";
    CloudSolrServer solrServer = new CloudSolrServer(zkHost);
    // 设置默认的collection
    solrServer.setDefaultCollection("collection2");

    solrServer.deleteByQuery("*:*");
    solrServer.commit();
}

}

出现异常
java.net.SocketException: Socket is not connected
at sun.nio.ch.Net.translateToSocketException(Net.java:123)
at sun.nio.ch.Net.translateException(Net.java:157)
at sun.nio.ch.Net.translateException(Net.java:163)
at sun.nio.ch.SocketAdaptor.shutdownInput(SocketAdaptor.java:401)
at org.apache.zookeeper.ClientCnxnSocketNIO.cleanup(ClientCnxnSocketNIO.java:200)
at org.apache.zookeeper.ClientCnxn$SendThread.cleanup(ClientCnxn.java:1185)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1110)
Caused by: java.nio.channels.NotYetConnectedException
at sun.nio.ch.SocketChannelImpl.shutdownInput(SocketChannelImpl.java:782)
at sun.nio.ch.SocketAdaptor.shutdownInput(SocketAdaptor.java:399)
... 3 more

2个回答

github_39599694
github_39599694   2018.02.13 23:45

并不会solr,建议检查网络/防火墙/端口配置

diaoliwei2
diaoliwei2   Rxr 2018.02.17 12:18

那几个机器是否能ping通呢?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!