在upsert时,couchbase连接关闭

时间:2017-08-22 01:57:47

标签: java spring-boot junit couchbase

我有两种方法可以融入couchbase。然后我用springboottest写了两个Junit测试器。在一个Junit测试器完成后,另一个测试将抛出此异常。如何解决?

有两种upsert方法:我不知道哪种方法更好?

public List<RawJsonDocument> upsert2(String generatorId, String idPrefix, List<String> contents)
{
    List<RawJsonDocument> rjd = new ArrayList<RawJsonDocument>(contents.size());

    Observable.from(contents).flatMap(new Func1<String,Observable<String>>(){
        @Override
        public Observable<String> call(String t)
        {
            return bucket.async().counter(generatorId, 1)
            .map(jsonLongDocument -> {
                String idStr = idPrefix + generatorId + jsonLongDocument.content();
                String jsonStr = idStr + "=" + t;
                return jsonStr;
            });
        }}).subscribe(new Action1<String>() {
            @Override
            public void call(String t)
            {
                String[] s = t.split("[=]");
                LOGGER.debug("\n methord2 generatorId:" + s[0] + "\n content:" + s[1]);
                bucket.async().upsert(RawJsonDocument.create(s[0],s[1]));

            }});

    return rjd;
}
public List<RawJsonDocument> upsert1(String generatorId, String idPrefix, List<String> contents)
{
    if(contents == null)
    {
        return null;
    }
    List<RawJsonDocument> rjd = new ArrayList<RawJsonDocument>(contents.size());
    Observable.from(contents).flatMap(new Func1<String,Observable<RawJsonDocument>>(){
        @Override
        public Observable<RawJsonDocument> call(String t)
        {
            return bucket.async().counter(generatorId, 1)
            .map(jsonLongDocument -> {
                String idStr = idPrefix + generatorId + jsonLongDocument.content();
                LOGGER.debug("\n method3 generatorId:" + idStr + "\n content:" + t);
                return RawJsonDocument.create(idStr,t);
            });

        }}).subscribe(new Action1<RawJsonDocument>() {
            @Override
            public void call(RawJsonDocument t)
            {
                rjd.add(bucket.async().upsert(t).toBlocking().single());

            }});
    return rjd;
}

这是我的Junit Tester:

@Test
public void testIncrementIds3()
{

    assertThat(generatorId.upsert2("counter", "idprefix", Arrays.asList("aabbccdd","ffddeeaa")).size(),is(2));
    assertThat(generatorId.upsert1("counter", "idprefix", Arrays.asList("aabbccdd","ffddeeaa")).size(),is(2));
}

0 个答案:

没有答案