Java Code Examples for com.couchbase.mock.CouchbaseMock

The following examples show how to use com.couchbase.mock.CouchbaseMock. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: couchbase-jvm-core   Source File: TestProperties.java    License: Apache License 2.0 6 votes vote down vote up
private static void createMock() {
    BucketConfiguration bucketConfiguration = new BucketConfiguration();
    bucketConfiguration.numNodes = mockNodeCount;
    bucketConfiguration.numReplicas = mockNodeCount;
    bucketConfiguration.numVBuckets = 1024;
    bucketConfiguration.name = bucket;
    bucketConfiguration.type = bucketType;
    bucketConfiguration.password = password;
    ArrayList<BucketConfiguration> configList = new ArrayList<BucketConfiguration>();
    configList.add(bucketConfiguration);
    try {
        mock = new CouchbaseMock(0, configList);
        mock.start();
        mock.waitForStartup();
    } catch (Exception ex) {
        throw new RuntimeException("Unable to initialize mock" + ex.getMessage(), ex);
    }
}
 
Example 2
Source Project: java-specialagent   Source File: CouchbaseClientTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startCouchbaseMock() throws Exception {
  couchbaseMock = new CouchbaseMock("localhost", 8091, 2, 1);
  final BucketConfiguration bucketConfiguration = new BucketConfiguration();
  bucketConfiguration.name = bucketName;
  bucketConfiguration.numNodes = 1;
  bucketConfiguration.numReplicas = 1;
  bucketConfiguration.password = "";
  couchbaseMock.start();
  couchbaseMock.waitForStartup();
  couchbaseMock.createBucket(bucketConfiguration);
}
 
Example 3
Source Project: java-specialagent   Source File: CouchbaseClientITest.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws BucketAlreadyExistsException, InterruptedException, IOException {
  final CouchbaseMock couchbaseMock = new CouchbaseMock("localhost", 8091, 2, 1);
  final BucketConfiguration bucketConfiguration = new BucketConfiguration();
  bucketConfiguration.name = bucketName;
  bucketConfiguration.numNodes = 1;
  bucketConfiguration.numReplicas = 1;
  bucketConfiguration.password = "";
  couchbaseMock.start();
  couchbaseMock.waitForStartup();
  couchbaseMock.createBucket(bucketConfiguration);

  final Cluster cluster = CouchbaseCluster.create(DefaultCouchbaseEnvironment.builder().connectTimeout(TimeUnit.SECONDS.toMillis(60)).build());
  final Bucket bucket = cluster.openBucket(bucketName);

  final JsonObject arthur = JsonObject
    .create().put("name", "Arthur")
    .put("email", "[email protected]")
    .put("interests", JsonArray.from("Holy Grail", "African Swallows"));

  bucket.upsert(JsonDocument.create("u:king_arthur", arthur));

  System.out.println(bucket.get("u:king_arthur"));

  cluster.disconnect(60, TimeUnit.SECONDS);
  couchbaseMock.stop();

  TestUtil.checkSpan(new ComponentSpanCount("couchbase-java-client.*", 2));
}
 
Example 4
Source Project: samza   Source File: TestCouchbaseRemoteTableEndToEnd.java    License: Apache License 2.0 5 votes vote down vote up
protected void createMockBuckets(List<String> bucketNames) throws Exception {
  ArrayList<BucketConfiguration> configList = new ArrayList<>();
  bucketNames.forEach(name -> configList.add(configBucket(name)));
  couchbaseMock = new CouchbaseMock(0, configList);
  couchbaseMock.start();
  couchbaseMock.waitForStartup();
}
 
Example 5
Source Project: tutorials   Source File: CouchbaseMockConfiguration.java    License: MIT License 5 votes vote down vote up
public CouchbaseMockConfiguration(final CouchbaseProperties couchbaseProperties) {
    final BucketConfiguration bucketConfiguration = new BucketConfiguration();
    bucketConfiguration.numNodes = 1;
    bucketConfiguration.numReplicas = 1;
    bucketConfiguration.numVBuckets = 1024;
    bucketConfiguration.name = couchbaseProperties.getBucketName();
    bucketConfiguration.type = Bucket.BucketType.COUCHBASE;
    bucketConfiguration.password = couchbaseProperties.getBucketPassword();

    try {
        couchbaseMock = new CouchbaseMock(couchbaseProperties.getPort(), Collections.singletonList(bucketConfiguration));
    } catch (final IOException ex) {
        throw new UncheckedIOException(ex);
    }
}
 
Example 6
Source Project: couchbase-jvm-core   Source File: TestProperties.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Mock node count
 *
 * @return node count configured for mock
 */
public static CouchbaseMock couchbaseMock() {
    return mock;
}
 
Example 7
Source Project: couchbase-jvm-core   Source File: MockDependentTest.java    License: Apache License 2.0 votes vote down vote up
public static CouchbaseMock mock() { return couchbaseMock; } 
Example 8
public static CouchbaseMock mock() { return couchbaseMock; }