DATACOUCH-290 - Upgrade to java-client 2.4.4

Original PR: #138.
This commit is contained in:
Subhashni Balakrishnan
2017-04-06 15:57:30 -07:00
parent 4a48cc115e
commit 4b78715ed5
12 changed files with 141 additions and 49 deletions

View File

@@ -21,8 +21,8 @@
<dist.key>DATACOUCH</dist.key>
<couchbase>2.2.8</couchbase>
<couchbase.osgi>2.2.8</couchbase.osgi>
<couchbase>2.4.4</couchbase>
<couchbase.osgi>2.4.4</couchbase.osgi>
<springdata.commons>1.13.2.BUILD-SNAPSHOT</springdata.commons>
<validation>1.0.0.GA</validation>
</properties>

View File

@@ -134,9 +134,9 @@ public class CouchbaseRepositoryViewTests {
String highKey = "uname-11";
List<String> keys = Arrays.asList(lowKey, middleKey, highKey);
User u1 = repository.findByUsernameIs(lowKey);
User u2 = repository.findByUsernameIs(middleKey);
User u3 = repository.findByUsernameIs(highKey);
User u1 = repository.findByUsernameIs(lowKey).get(0);
User u2 = repository.findByUsernameIs(middleKey).get(0);
User u3 = repository.findByUsernameIs(highKey).get(0);
List<User> in = repository.findAllByUsernameIn(keys);

View File

@@ -46,7 +46,7 @@ public interface CustomUserRepository extends CouchbaseRepository<User, String>
long countByUsernameGreaterThanEqualAndUsernameLessThan(String lowBound, String highBound);
@View(viewName = "customFindByNameView")
User findByUsernameIs(String lowKey);
List<User> findByUsernameIs(String lowKey);
@View(viewName = "customFindByNameView")
List<User> findAllByUsernameIn(List<String> keys);

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;
@@ -12,14 +13,19 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
* A test listener that will remove the indexes created in {@link IndexedRepositoryTests} before test case is run.
*
* @author Simon Baslé
* @author Subhashni Balakrishnan
*/
public class IndexedRepositoryTestListener extends DependencyInjectionTestExecutionListener {
@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;
@@ -136,9 +137,15 @@ public class IndexedRepositoryTests {
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) {
//ignore
}
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> {
@@ -51,6 +52,17 @@ import org.springframework.beans.factory.config.AbstractFactoryBean;
eventBus
systemMetricsCollectorConfig
networkLatencyMetricsCollectorConfig
requestBufferWaitStrategy
sslKeystore
memcachedHashingStrategy
kvIoPool
queryIoPool
searchIoPool
viewIoPool
kvServiceConfig
queryServiceConfig
searchServiceConfig
viewServiceConfig
*/
@Override
@@ -123,14 +135,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);
}
@@ -206,4 +210,8 @@ import org.springframework.beans.factory.config.AbstractFactoryBean;
public void setMutationTokensEnabled(boolean mutationTokensEnabled) {
this.couchbaseEnvBuilder.mutationTokensEnabled(mutationTokensEnabled);
}
}
public void setAnalyticsTimeout(long analyticsTimeout) {
this.couchbaseEnvBuilder.analyticsTimeout(analyticsTimeout);
}
}

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.*;
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 =====
@@ -83,18 +89,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 +318,74 @@ public class CouchbaseEnvironmentNoShutdownProxy implements CouchbaseEnvironment
public long searchTimeout() {
return delegate.searchTimeout();
}
}
@Override
public WaitStrategyFactory requestBufferWaitStrategy() {
return delegate.requestBufferWaitStrategy();
}
@Override
public EventLoopGroup kvIoPool() {
return delegate.kvIoPool();
}
@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();
}
@Override
public long analyticsTimeout() {
return delegate.analyticsTimeout();
}
@Override
public long configPollInterval() {
return delegate.configPollInterval();
}
@Override
public KeyValueServiceConfig kvServiceConfig() {
return delegate.kvServiceConfig();
}
@Override
public QueryServiceConfig queryServiceConfig() {
return delegate.queryServiceConfig();
}
@Override
public SearchServiceConfig searchServiceConfig() {
return delegate.searchServiceConfig();
}
@Override
public ViewServiceConfig viewServiceConfig() {
return delegate.viewServiceConfig();
}
}

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>
@@ -66,9 +64,11 @@ import org.springframework.util.StringUtils;
* <li>{@link DefaultCouchbaseEnvironment.Builder#bufferPoolingEnabled(boolean) bufferPoolingEnabled}</li>
* <li>{@link DefaultCouchbaseEnvironment.Builder#tcpNodelayEnabled(boolean) tcpNodelayEnabled}</li>
* <li>{@link DefaultCouchbaseEnvironment.Builder#mutationTokensEnabled(boolean) mutationTokensEnabled}</li>
* <li>{@link DefaultCouchbaseEnvironment.Builder#analyticsTimeout(long) analyticsTimeout}</li>
* </ul>
*
* @author Simon Baslé
* @author Subhashni Balakrishnan
*/
public class CouchbaseEnvironmentParser extends AbstractSingleBeanDefinitionParser {
@@ -117,8 +117,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");
@@ -138,6 +136,7 @@ public class CouchbaseEnvironmentParser extends AbstractSingleBeanDefinitionPars
setPropertyValue(envDefinitionBuilder, envElement, "bufferPoolingEnabled", "bufferPoolingEnabled");
setPropertyValue(envDefinitionBuilder, envElement, "tcpNodelayEnabled", "tcpNodelayEnabled");
setPropertyValue(envDefinitionBuilder, envElement, "mutationTokensEnabled", "mutationTokensEnabled");
setPropertyValue(envDefinitionBuilder, envElement, "analyticsTimeout", "analyticsTimeout");
//retry strategy is particular, in the xsd this is an enum (FailFast, BestEffort)
setPropertyValue(envDefinitionBuilder, envElement, "retryStrategy", "retryStrategy");

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.
@@ -23,6 +23,7 @@ import java.util.Collections;
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;
@@ -51,6 +52,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 {
@@ -241,7 +243,14 @@ 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

@@ -54,6 +54,7 @@
<xsd:attribute name="bufferPoolingEnabled" type="xsd:boolean"/>
<xsd:attribute name="tcpNodelayEnabled" type="xsd:boolean"/>
<xsd:attribute name="mutationTokensEnabled" type="xsd:boolean"/>
<xsd:attribute name="analyticsTimeout" type="xsd:long"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

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.
@@ -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)));
@@ -101,6 +99,7 @@ public class CouchbaseEnvironmentParserTest {
assertThat(env.bufferPoolingEnabled(), allOf(equalTo(false), not(defaultEnv.bufferPoolingEnabled())));
assertThat(env.tcpNodelayEnabled(), allOf(equalTo(false), not(defaultEnv.tcpNodelayEnabled())));
assertThat(env.mutationTokensEnabled(), allOf(equalTo(true), not(defaultEnv.mutationTokensEnabled())));
assertThat(env.analyticsTimeout(), is(equalTo(30L)));
}
@AfterClass

View File

@@ -23,8 +23,6 @@
sslEnabled="true"
sslKeystoreFile="test"
sslKeystorePassword="test"
queryEnabled="true"
queryPort="7"
bootstrapHttpEnabled="false"
bootstrapCarrierEnabled="false"
bootstrapHttpDirectPort="8"
@@ -45,6 +43,7 @@
bufferPoolingEnabled="false"
tcpNodelayEnabled="false"
mutationTokensEnabled="true"
analyticsTimeout="30"
/>
</beans>