DATACOUCH-260 - Update to 2.4.1 and fix tests

Adapted changes to 3.0 branch

Original pull request: #131.
This commit is contained in:
Subhashni Balakrishnan
2017-02-04 21:30:46 -08:00
parent 8733ea3cf5
commit 162d8124ab
17 changed files with 137 additions and 87 deletions

View File

@@ -18,8 +18,8 @@
</parent>
<properties>
<couchbase>2.2.8</couchbase>
<couchbase.osgi>2.2.8</couchbase.osgi>
<couchbase>2.4.1</couchbase>
<couchbase.osgi>2.4.1</couchbase.osgi>
<springdata.commons>2.0.0.BUILD-SNAPSHOT</springdata.commons>
</properties>

View File

@@ -20,18 +20,21 @@ import java.util.Collections;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.cluster.ClusterInfo;
import com.couchbase.client.java.query.Index;
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.view.DefaultView;
import com.couchbase.client.java.view.DesignDocument;
import com.couchbase.client.java.view.View;
import org.springframework.data.couchbase.config.BeanNames;
import org.springframework.data.couchbase.repository.index.IndexedRepositoryTests;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
/**
* @author Michael Nitschinger
*/
public class CouchbaseTemplateViewListener extends DependencyInjectionTestExecutionListener {
public class CouchbaseTemplateQueryListener extends DependencyInjectionTestExecutionListener {
@Override
public void beforeTestClass(final TestContext testContext) throws Exception {
@@ -39,6 +42,7 @@ public class CouchbaseTemplateViewListener extends DependencyInjectionTestExecut
ClusterInfo clusterInfo = (ClusterInfo) testContext.getApplicationContext().getBean(BeanNames.COUCHBASE_CLUSTER_INFO);
populateTestData(client, clusterInfo);
createAndWaitForDesignDocs(client);
client.query(N1qlQuery.simple(Index.createPrimaryIndex().on(client.name())));
}
private void populateTestData(Bucket client, ClusterInfo clusterInfo) {

View File

@@ -67,7 +67,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Anastasiia Smirnova */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = IntegrationTestApplicationConfig.class)
@TestExecutionListeners(CouchbaseTemplateViewListener.class)
@TestExecutionListeners(CouchbaseTemplateQueryListener.class)
public class CouchbaseTemplateTests {
@Rule
@@ -83,7 +83,7 @@ public class CouchbaseTemplateTests {
private void removeIfExist(String key) {
try {
client.remove(key);
template.remove(key);
}
catch (DocumentDoesNotExistException e) {
//ignore

View File

@@ -21,6 +21,8 @@ import java.util.Collections;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.cluster.ClusterInfo;
import com.couchbase.client.java.error.DocumentDoesNotExistException;
import com.couchbase.client.java.query.Index;
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.view.*;
import org.springframework.data.couchbase.config.BeanNames;
@@ -31,7 +33,7 @@ import rx.Observable;
/**
* @author Subhashni Balakrishnan
*/
public class ReactiveCouchbaseTemplateViewListener extends DependencyInjectionTestExecutionListener {
public class RxCouchbaseTemplateQueryListener extends DependencyInjectionTestExecutionListener {
@Override
public void beforeTestClass(final TestContext testContext) throws Exception {
@@ -39,6 +41,7 @@ public class ReactiveCouchbaseTemplateViewListener extends DependencyInjectionTe
ClusterInfo clusterInfo = (ClusterInfo) testContext.getApplicationContext().getBean(BeanNames.COUCHBASE_CLUSTER_INFO);
populateTestData(client, clusterInfo);
createAndWaitForDesignDocs(client);
client.query(N1qlQuery.simple(Index.createPrimaryIndex().on(client.name())));
}
private void populateTestData(Bucket client, ClusterInfo clusterInfo) {

View File

@@ -28,8 +28,6 @@ import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.PersistTo;
import com.couchbase.client.java.ReplicateTo;
import com.couchbase.client.java.document.RawJsonDocument;
import com.couchbase.client.java.error.DocumentAlreadyExistsException;
import com.couchbase.client.java.error.DocumentDoesNotExistException;
import com.couchbase.client.java.query.AsyncN1qlQueryResult;
import com.couchbase.client.java.query.N1qlParams;
import com.couchbase.client.java.query.N1qlQuery;
@@ -39,7 +37,6 @@ import com.couchbase.client.java.view.Stale;
import com.couchbase.client.java.view.ViewQuery;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
@@ -60,7 +57,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
**/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = ReactiveIntegrationTestApplicationConfig.class)
@TestExecutionListeners(ReactiveCouchbaseTemplateViewListener.class)
@TestExecutionListeners(RxCouchbaseTemplateQueryListener.class)
public class RxJavaCouchbaseTemplateTests {
@Rule
@@ -76,12 +73,18 @@ public class RxJavaCouchbaseTemplateTests {
private void removeIfExist(String key) {
template.remove(key).subscribe();
template.remove(key).subscribe(
v -> {},
err -> {}
);
}
private void removeCollectionIfExist(Collection<ReactiveBeer> beers) {
template.remove(beers, PersistTo.MASTER, ReplicateTo.NONE)
.subscribe();
.subscribe(
v -> {},
err -> {}
);
}
@Test
@@ -129,7 +132,7 @@ public class RxJavaCouchbaseTemplateTests {
removeIfExist(id);
template.save(beer).subscribe();
Object result = client.get(id);
Object result = template.findById(id, ReactiveBeer.class).toBlocking().single();
assertNotNull(result);
template.remove(beer).subscribe();
@@ -154,7 +157,7 @@ public class RxJavaCouchbaseTemplateTests {
ComplexPerson complex = new ComplexPerson(id, names, votes, info1, info2);
template.save(complex).toBlocking();
template.save(complex).subscribe();
assertNotNull(client.get(id));
ComplexPerson response = template.findById(id, ComplexPerson.class).toBlocking().single();
@@ -199,12 +202,10 @@ public class RxJavaCouchbaseTemplateTests {
@Test
public void shouldQueryRaw() {
N1qlQuery query = N1qlQuery.simple(select("name").from(i(client.name()))
.where(x("name").isNotMissing()));
N1qlQuery query = N1qlQuery.simple(select("name").from(i(client.name())).limit(1));
AsyncN1qlQueryResult queryResult = template.queryN1QL(query).toBlocking().single();
assertNotNull(queryResult);
assertTrue(queryResult.errors().toString(), queryResult.finalSuccess().toBlocking().single());
assertTrue(queryResult.finalSuccess().toBlocking().single());
assertFalse(queryResult.rows().toList().toBlocking().single().isEmpty());
}
@@ -212,7 +213,7 @@ public class RxJavaCouchbaseTemplateTests {
public void shouldQueryWithMapping() {
FullFragment ff1 = new FullFragment("fullFragment1", 1, "fullFragment", "test1");
FullFragment ff2 = new FullFragment("fullFragment2", 2, "fullFragment", "test2");
template.save(Arrays.asList(ff1, ff2));
template.save(Arrays.asList(ff1, ff2)).subscribe();
N1qlQuery query = N1qlQuery.simple(select(i("value")) //"value" is a n1ql keyword apparently
.from(i(client.name()))
@@ -270,9 +271,9 @@ public class RxJavaCouchbaseTemplateTests {
String id = "simple-doc-with-update-expiry-for-read";
DocumentWithTouchOnRead doc = new DocumentWithTouchOnRead(id);
template.save(doc).subscribe();
Thread.sleep(1500);
Thread.sleep(1000);
assertNotNull(template.findById(id, DocumentWithTouchOnRead.class).toBlocking().single());
Thread.sleep(1500);
Thread.sleep(1000);
assertNotNull(template.findById(id, DocumentWithTouchOnRead.class).toBlocking().single());
Thread.sleep(3000);
assertNull(template.findById(id, DocumentWithTouchOnRead.class).toBlocking().single());

View File

@@ -13,15 +13,15 @@ import reactor.core.publisher.Mono;
/**
* @author Subhashni Balakrishnan
*/
@ViewIndexed(designDoc = "party", viewName = "all")
@N1qlSecondaryIndexed(indexName = "party")
@ViewIndexed(designDoc = "reactiveParty", viewName = "all")
@N1qlSecondaryIndexed(indexName = "reactiveParty")
public interface ReactivePartyRepository extends ReactiveCouchbaseRepository<Party, String> {
Flux<Party> findByAttendeesGreaterThanEqual(int minAttendees);
Flux<Party> findByEventDateIs(Date targetDate);
@View(designDocument = "party", viewName = "byDate")
@View(designDocument = "reactiveParty", viewName = "byDate")
Flux<Party> findFirst3ByEventDateGreaterThanEqual(Date targetDate);
Flux<Object> findAllByDescriptionNotNull();

View File

@@ -20,25 +20,29 @@ import java.util.List;
import com.couchbase.client.java.view.ViewQuery;
import org.springframework.data.couchbase.core.query.N1qlSecondaryIndexed;
import org.springframework.data.couchbase.core.query.Query;
import org.springframework.data.couchbase.core.query.View;
import org.springframework.data.couchbase.core.query.ViewIndexed;
import reactor.core.publisher.Flux;
/**
* @author Subhashni Balakrishnan
*/
@ViewIndexed(designDoc = "reactiveUser", viewName = "all")
@N1qlSecondaryIndexed(indexName = "reactiveUser")
public interface ReactiveUserRepository extends ReactiveCouchbaseRepository<ReactiveUser, String> {
@View(designDocument = "user", viewName = "all")
Flux<ReactiveUser> customViewQuery(ViewQuery query);
@Query("#{#n1ql.selectEntity} WHERE username = $1")
@Query("#{#n1ql.selectEntity} WHERE username = $1 and #{#n1ql.filter}")
Flux<ReactiveUser> findByUsername(String username);
@Query("SELECT * FROM #{#n1ql.bucket} WHERE username = $1")
@Query("SELECT * FROM #{#n1ql.bucket} WHERE username = $1 and #{#n1ql.filter}")
Flux<ReactiveUser> findByUsernameBadSelect(String username);
@Query("#{#n1ql.selectEntity} WHERE username LIKE '%-#{3 + 1}'")
@Query("#{#n1ql.selectEntity} WHERE username LIKE '%-#{3 + 1}' and #{#n1ql.filter}")
Flux<ReactiveUser> findByUsernameWithSpelAndPlaceholder();
@Query

View File

@@ -20,8 +20,10 @@ import java.util.List;
import com.couchbase.client.java.view.ViewQuery;
import org.springframework.data.couchbase.core.query.N1qlSecondaryIndexed;
import org.springframework.data.couchbase.core.query.Query;
import org.springframework.data.couchbase.core.query.View;
import org.springframework.data.couchbase.core.query.ViewIndexed;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
@@ -29,6 +31,8 @@ import org.springframework.data.domain.Slice;
/**
* @author Michael Nitschinger
*/
@ViewIndexed(designDoc = "user", viewName = "all")
@N1qlSecondaryIndexed(indexName = "User")
public interface UserRepository extends CouchbaseRepository<User, String> {
@View(designDocument = "user", viewName = "all")

View File

@@ -1,6 +1,7 @@
package org.springframework.data.couchbase.repository.index;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.error.DesignDocumentDoesNotExistException;
import com.couchbase.client.java.query.Index;
import com.couchbase.client.java.query.N1qlQuery;
@@ -18,8 +19,12 @@ public class IndexedRepositoryTestListener extends DependencyInjectionTestExecut
@Override
public void beforeTestClass(final TestContext testContext) throws Exception {
Bucket client = (Bucket) testContext.getApplicationContext().getBean(BeanNames.COUCHBASE_BUCKET);
client.bucketManager().removeDesignDocument(IndexedRepositoryTests.VIEW_DOC);
client.bucketManager().removeDesignDocument("foo");
try {
client.bucketManager().removeDesignDocument(IndexedRepositoryTests.VIEW_DOC);
client.bucketManager().removeDesignDocument("foo");
} catch (DesignDocumentDoesNotExistException ex) {
//ignore
}
client.query(N1qlQuery.simple(Index.dropPrimaryIndex(client.name())));
client.query(N1qlQuery.simple(Index.dropIndex(client.name(), IndexedRepositoryTests.SECONDARY)));
}

View File

@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
import java.util.Arrays;
import com.couchbase.client.java.error.DesignDocumentDoesNotExistException;
import com.couchbase.client.java.query.N1qlQuery;
import com.couchbase.client.java.query.N1qlQueryResult;
import com.couchbase.client.java.view.DesignDocument;
@@ -81,13 +82,10 @@ public class IndexedRepositoryTests {
IndexedUserRepository repository = factory.getRepository(IndexedUserRepository.class);
String bucket = template.getCouchbaseBucket().name();
N1qlQuery existQuery = N1qlQuery.simple("SELECT COUNT(name) = 1 AS exist FROM system:indexes WHERE keyspace_id = \"" + bucket
+ "\" AND is_primary");
N1qlQuery existQuery = N1qlQuery.simple("SELECT 1 FROM `"+ bucket +"`");
N1qlQueryResult exist = template.queryN1QL(existQuery);
assertTrue(exist.finalSuccess());
assertEquals(1, exist.allRows().size());
assertEquals(true, exist.allRows().get(0).value().getBoolean("exist"));
}
@Test
@@ -95,22 +93,24 @@ public class IndexedRepositoryTests {
IndexedUserRepository repository = factory.getRepository(IndexedUserRepository.class);
String bucket = template.getCouchbaseBucket().name();
N1qlQuery existQuery = N1qlQuery.simple("SELECT COUNT(name) = 1 AS exist FROM system:indexes WHERE keyspace_id = \"" + bucket
+ "\" AND name = \"" + SECONDARY + "\"");
N1qlQuery existQuery = N1qlQuery.simple("SELECT 1 FROM `"+ bucket +"` USE INDEX (" + SECONDARY +")");
N1qlQueryResult exist = template.queryN1QL(existQuery);
assertTrue(exist.finalSuccess());
assertEquals(1, exist.allRows().size());
assertEquals(true, exist.allRows().get(0).value().getBoolean("exist"));
}
@Test
public void shouldFindViewIndex() {
IndexedUserRepository repository = factory.getRepository(IndexedUserRepository.class);
DesignDocument designDoc = template.getCouchbaseBucket()
.bucketManager()
.getDesignDocument(VIEW_DOC);
DesignDocument designDoc = null;
try {
designDoc = template.getCouchbaseBucket()
.bucketManager()
.getDesignDocument(VIEW_DOC);
} catch(DesignDocumentDoesNotExistException ex) {
}
assertNotNull(designDoc);
for (View view : designDoc.views()) {
@@ -123,22 +123,24 @@ public class IndexedRepositoryTests {
AnotherIndexedUserRepository repository = ignoringIndexFactory.getRepository(AnotherIndexedUserRepository.class);
String bucket = template.getCouchbaseBucket().name();
N1qlQuery existQuery = N1qlQuery.simple("SELECT COUNT(name) = 1 AS exist FROM system:indexes WHERE keyspace_id = \"" + bucket
+ "\" AND name = \"" + IGNORED_SECONDARY + "\"");
N1qlQuery existQuery = N1qlQuery.simple("SELECT 1 FROM `"+ bucket +"` USE INDEX (" + IGNORED_SECONDARY +")");
N1qlQueryResult exist = template.queryN1QL(existQuery);
assertTrue(exist.finalSuccess());
assertEquals(1, exist.allRows().size());
assertEquals(false, exist.allRows().get(0).value().getBoolean("exist"));
assertFalse(exist.finalSuccess());
}
@Test
public void shouldNotFindViewIndexWithIgnoringIndexManager() {
AnotherIndexedUserRepository repository = ignoringIndexFactory.getRepository(AnotherIndexedUserRepository.class);
DesignDocument designDoc = template.getCouchbaseBucket()
.bucketManager()
.getDesignDocument(VIEW_DOC);
DesignDocument designDoc = null;
try {
designDoc = template.getCouchbaseBucket()
.bucketManager()
.getDesignDocument(VIEW_DOC);
} catch(DesignDocumentDoesNotExistException ex) {
//ignored
}
if (designDoc != null) {
for (View view : designDoc.views()) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors
* Copyright 2012-2017 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@ import org.springframework.beans.factory.config.AbstractFactoryBean;
*
* @author Simon Baslé
* @author Simon Bland
* @author Subhashni Balakrishnan
*/
/*package*/ class CouchbaseEnvironmentFactoryBean extends AbstractFactoryBean<CouchbaseEnvironment> {
@@ -123,14 +124,6 @@ import org.springframework.beans.factory.config.AbstractFactoryBean;
this.couchbaseEnvBuilder.sslKeystorePassword(sslKeystorePassword);
}
public void setQueryEnabled(boolean queryEnabled) {
this.couchbaseEnvBuilder.queryEnabled(queryEnabled);
}
public void setQueryPort(int queryPort) {
this.couchbaseEnvBuilder.queryPort(queryPort);
}
public void setBootstrapHttpEnabled(boolean bootstrapHttpEnabled) {
this.couchbaseEnvBuilder.bootstrapHttpEnabled(bootstrapHttpEnabled);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors
* Copyright 2012-2017 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,14 @@
package org.springframework.data.couchbase.config;
import java.security.KeyStore;
import java.util.concurrent.TimeUnit;
import com.couchbase.client.core.env.WaitStrategyFactory;
import com.couchbase.client.core.event.EventBus;
import com.couchbase.client.core.metrics.MetricsCollector;
import com.couchbase.client.core.metrics.NetworkLatencyMetricsCollector;
import com.couchbase.client.core.node.MemcachedHashingStrategy;
import com.couchbase.client.core.retry.RetryStrategy;
import com.couchbase.client.core.time.Delay;
import com.couchbase.client.deps.io.netty.channel.EventLoopGroup;
@@ -32,6 +37,7 @@ import rx.Scheduler;
*
* @author Simon Baslé
* @author Jonathan Edwards
* @author Subhashni Balakrishnan
*/
public class CouchbaseEnvironmentNoShutdownProxy implements CouchbaseEnvironment {
@@ -42,8 +48,8 @@ public class CouchbaseEnvironmentNoShutdownProxy implements CouchbaseEnvironment
}
@Override
public Observable<Boolean> shutdown() {
return Observable.just(false);
public boolean shutdown() {
return false;
}
//===== DELEGATION METHODS =====
@@ -58,6 +64,11 @@ public class CouchbaseEnvironmentNoShutdownProxy implements CouchbaseEnvironment
return delegate.ioPool();
}
@Override
public EventLoopGroup kvIoPool() {
return delegate.kvIoPool();
}
@Override
public Scheduler scheduler() {
return delegate.scheduler();
@@ -83,18 +94,6 @@ public class CouchbaseEnvironmentNoShutdownProxy implements CouchbaseEnvironment
return delegate.sslKeystorePassword();
}
@Override
@Deprecated
public boolean queryEnabled() {
return delegate.queryEnabled();
}
@Override
@Deprecated
public int queryPort() {
return delegate.queryPort();
}
@Override
public boolean bootstrapHttpEnabled() {
return delegate.bootstrapHttpEnabled();
@@ -324,4 +323,39 @@ public class CouchbaseEnvironmentNoShutdownProxy implements CouchbaseEnvironment
public long searchTimeout() {
return delegate.searchTimeout();
}
@Override
public WaitStrategyFactory requestBufferWaitStrategy() {
return delegate.requestBufferWaitStrategy();
}
@Override
public EventLoopGroup viewIoPool() {
return delegate.viewIoPool();
}
@Override
public EventLoopGroup searchIoPool() {
return delegate.searchIoPool();
}
@Override
public EventLoopGroup queryIoPool() {
return delegate.queryIoPool();
}
@Override
public KeyStore sslKeystore() {
return delegate.sslKeystore();
}
@Override
public boolean shutdown(long timeout, TimeUnit timeUnit) {
return delegate.shutdown(timeout, timeUnit);
}
@Override
public MemcachedHashingStrategy memcachedHashingStrategy() {
return delegate.memcachedHashingStrategy();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors
* Copyright 2012-2017 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,8 +44,6 @@ import org.springframework.util.StringUtils;
* <li>{@link DefaultCouchbaseEnvironment.Builder#sslEnabled(boolean) sslEnabled}</li>
* <li>{@link DefaultCouchbaseEnvironment.Builder#sslKeystoreFile(String) sslKeystoreFile}</li>
* <li>{@link DefaultCouchbaseEnvironment.Builder#sslKeystorePassword(String) sslKeystorePassword}</li>
* <li>{@link DefaultCouchbaseEnvironment.Builder#queryEnabled(boolean) queryEnabled}</li>
* <li>{@link DefaultCouchbaseEnvironment.Builder#queryPort(int) queryPort}</li>
* <li>{@link DefaultCouchbaseEnvironment.Builder#bootstrapHttpEnabled(boolean) bootstrapHttpEnabled}</li>
* <li>{@link DefaultCouchbaseEnvironment.Builder#bootstrapCarrierEnabled(boolean) bootstrapCarrierEnabled}</li>
* <li>{@link DefaultCouchbaseEnvironment.Builder#bootstrapHttpDirectPort(int) bootstrapHttpDirectPort}</li>
@@ -69,6 +67,7 @@ import org.springframework.util.StringUtils;
* </ul>
*
* @author Simon Baslé
* @author Subhashni Balakrishnan
*/
public class CouchbaseEnvironmentParser extends AbstractSingleBeanDefinitionParser {
@@ -117,8 +116,6 @@ public class CouchbaseEnvironmentParser extends AbstractSingleBeanDefinitionPars
setPropertyValue(envDefinitionBuilder, envElement, "sslEnabled", "sslEnabled");
setPropertyValue(envDefinitionBuilder, envElement, "sslKeystoreFile", "sslKeystoreFile");
setPropertyValue(envDefinitionBuilder, envElement, "sslKeystorePassword", "sslKeystorePassword");
setPropertyValue(envDefinitionBuilder, envElement, "queryEnabled", "queryEnabled");
setPropertyValue(envDefinitionBuilder, envElement, "queryPort", "queryPort");
setPropertyValue(envDefinitionBuilder, envElement, "bootstrapHttpEnabled", "bootstrapHttpEnabled");
setPropertyValue(envDefinitionBuilder, envElement, "bootstrapCarrierEnabled", "bootstrapCarrierEnabled");
setPropertyValue(envDefinitionBuilder, envElement, "bootstrapHttpDirectPort", "bootstrapHttpDirectPort");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors
* Copyright 2012-2017 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@ import java.util.Collections;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.bucket.BucketManager;
import com.couchbase.client.java.document.json.JsonObject;
import com.couchbase.client.java.error.DesignDocumentDoesNotExistException;
import com.couchbase.client.java.query.AsyncN1qlQueryResult;
import com.couchbase.client.java.query.Index;
import com.couchbase.client.java.query.Statement;
@@ -53,6 +54,7 @@ import org.springframework.data.repository.core.RepositoryInformation;
* Index creation will be attempted in parallel using the asynchronous APIs, but the overall process is still blocking.
*
* @author Simon Baslé
* @author Subhashni Balakrishnan
*/
public class IndexManager {
@@ -281,7 +283,12 @@ public class IndexManager {
}
com.couchbase.client.java.view.View view = DefaultView.create(viewName, mapFunction, reduceFunction);
DesignDocument doc = manager.getDesignDocument(config.designDoc());
DesignDocument doc = null;
try {
doc = manager.getDesignDocument(config.designDoc());
} catch(DesignDocumentDoesNotExistException ex) {
//ignore
}
if (doc != null) {
for (com.couchbase.client.java.view.View existingView : doc.views()) {
if (existingView.name().equals(viewName)) {

View File

@@ -79,8 +79,6 @@ public class CouchbaseEnvironmentParserTest {
assertThat(env.sslEnabled(), allOf(equalTo(true), not(defaultEnv.sslEnabled())));
assertThat(env.sslKeystoreFile(), is(equalTo("test")));
assertThat(env.sslKeystorePassword(), is(equalTo("test")));
assertThat(env.queryEnabled(), allOf(equalTo(true), not(defaultEnv.queryEnabled())));
assertThat(env.queryPort(), is(equalTo(7)));
assertThat(env.bootstrapHttpEnabled(), allOf(equalTo(false), not(defaultEnv.bootstrapHttpEnabled())));
assertThat(env.bootstrapCarrierEnabled(), allOf(equalTo(false), not(defaultEnv.bootstrapCarrierEnabled())));
assertThat(env.bootstrapHttpDirectPort(), is(equalTo(8)));

View File

@@ -75,7 +75,7 @@ public class RepositoryIndexUsageTest {
@Test
public void testFindAllUsesViewWithConfiguredConsistency() {
String expectedQueryParams = "reduce=false&stale=false";
String expectedQueryParams = "ViewQuery(string/all){params=\"reduce=false&stale=false\"}";
repository.findAll();
verify(couchbaseOperations, never()).queryView(any(ViewQuery.class));
@@ -89,7 +89,7 @@ public class RepositoryIndexUsageTest {
@Test
public void testFindAllKeysUsesViewWithConfiguredConsistency() {
String expectedQueryParams = "reduce=false&stale=false";
String expectedQueryParams = "ViewQuery(string/all){params=\"reduce=false&stale=false\", keys=\"[\"someKey\"]\"}";
repository.findAll(Collections.singleton("someKey"));
verify(couchbaseOperations, never()).queryView(any(ViewQuery.class));
@@ -103,7 +103,7 @@ public class RepositoryIndexUsageTest {
@Test
public void testCountUsesViewWithConfiguredConsistencyAndReduces() {
String expectedQueryParams = "reduce=true&stale=false";
String expectedQueryParams = "ViewQuery(string/all){params=\"reduce=true&stale=false\"}";
repository.count();
verify(couchbaseOperations, never()).findByView(any(ViewQuery.class), any(Class.class));
@@ -123,7 +123,7 @@ public class RepositoryIndexUsageTest {
@Test
public void testDeleteAllUsesViewWithConfiguredConsistency() {
String expectedQueryParams = "reduce=false&stale=false";
String expectedQueryParams = "ViewQuery(string/all){params=\"reduce=false&stale=false\"}";
repository.deleteAll();
verify(couchbaseOperations, never()).findByView(any(ViewQuery.class), any(Class.class));

View File

@@ -23,8 +23,6 @@
sslEnabled="true"
sslKeystoreFile="test"
sslKeystorePassword="test"
queryEnabled="true"
queryPort="7"
bootstrapHttpEnabled="false"
bootstrapCarrierEnabled="false"
bootstrapHttpDirectPort="8"