Java Examples for org.couchbase.mock.CouchbaseMock

The following java examples will help you to understand the usage of org.couchbase.mock.CouchbaseMock. These source code samples are taken from different open source projects.

Example 1
Project: CouchbaseMock-master  File: ClientViewTest.java View source code
@BeforeClass
public static void before() throws Exception {
    config = new BucketConfiguration();
    config.numNodes = 4;
    config.numReplicas = 1;
    config.name = "default";
    config.password = "";
    List<BucketConfiguration> configs = new ArrayList<BucketConfiguration>();
    configs.add(config);
    if (mock == null) {
        mock = new CouchbaseMock(null, 0, 4, 0, 1024, "", 1);
        mock.clearInitialConfigs();
        mock.start();
        mock.waitForStartup();
    } else {
        clearAllBuckets();
    }
    mock.createBucket(config);
    initClient();
    String view = "{\"language\":\"javascript\",\"views\":{\"" + VIEW_NAME_W_REDUCE + "\":{\"map\":\"function (doc) { " + "if(doc.type != \\\"dated\\\") {emit(doc.type, 1)}}\"," + "\"reduce\":\"_sum\" }}}";
    try {
        createDesignDocument(DESIGN_DOC_W_REDUCE, view);
    } catch (IOException ex) {
        throw ex;
    }
    // Creating the Design/View for the binary docs
    view = "{\"language\":\"javascript\",\"views\":{\"" + VIEW_NAME_BINARY + "\":{\"map\":\"function (doc, meta) " + "{ if(meta.id.match(/nonjson/)) { emit(meta.id, null); }}\"}}}";
    createDesignDocument(DESIGN_DOC_BINARY, view);
    view = "{\"language\":\"javascript\",\"views\":{\"" + VIEW_NAME_FOR_DATED + "\":{\"map\":\"function (doc) {  " + "emit(doc.type, 1)}\"}}}";
    createDesignDocument(DESIGN_DOC_WO_REDUCE, view);
    for (Entry<String, Object> item : ITEMS.entrySet()) {
        OperationFuture<Boolean> future = client.set(item.getKey(), item.getValue());
        assertTrue(future.getStatus().toString(), future.get());
    }
    client.shutdown();
}
Example 2
Project: sling-master  File: SlingLaunchpadNosqlCouchbaseIT.java View source code
@Configuration
public Option[] configuration() throws IOException, InterruptedException {
    final int port = findFreePort();
    startCouchbase(port);
    final String couchbaseHosts = String.format("localhost:%s", port);
    return OptionUtils.combine(baseConfiguration(), editConfigurationFilePut("etc/org.apache.karaf.features.cfg", "featuresBoot", "(wrap)"), editConfigurationFilePut("etc/org.apache.sling.nosql.couchbase.client.CouchbaseClient.factory.config.config", "couchbaseHosts", couchbaseHosts), editConfigurationFilePut("etc/org.apache.sling.nosql.couchbase.client.CouchbaseClient.factory.config.config", "clientId", "sling-resourceprovider-couchbase"), editConfigurationFilePut("etc/org.apache.sling.nosql.couchbase.client.CouchbaseClient.factory.config.config", "bucketName", "sling"), editConfigurationFilePut("etc/org.apache.sling.nosql.couchbase.client.CouchbaseClient.factory.config.config", "enabled", "true"), // wrappedBundle(mavenBundle().groupId("org.couchbase.mock").artifactId("CouchbaseMock").versionAsInProject()),
    wrappedBundle(mavenBundle().groupId("com.couchbase.client").artifactId("couchbase-client").versionAsInProject()), wrappedBundle(mavenBundle().groupId("com.intellij").artifactId("annotations").versionAsInProject()), mavenBundle().groupId("com.google.code.gson").artifactId("gson").versionAsInProject(), mavenBundle().groupId("com.googlecode.json-simple").artifactId("json-simple").versionAsInProject(), mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.rhino").versionAsInProject(), mavenBundle().groupId("org.tukaani").artifactId("xz").versionAsInProject(), addSlingFeatures("sling-launchpad-nosql-couchbase"));
}
Example 3
Project: gobblin-master  File: CouchbaseTestServer.java View source code
public void start() {
    log.info("Starting couchbase server on port " + _port);
    String[] commands = { "/usr/bin/java", "-cp", COUCHBASE_MOCK_JAR, "org.couchbase.mock.CouchbaseMock", "--port", _port + "", "-n", "1", "-R", "0", "-b", "default:", "--host", "127.0.0.1" };
    try {
        System.out.println("Will run command " + Arrays.toString(commands));
        couchbaseProcess = new ProcessBuilder().inheritIO().command(commands).start();
    } catch (Exception e) {
        log.error("Failed to start couchbase mock server", e);
        Throwables.propagate(e);
    }
    boolean isUp = false;
    int numTries = 5;
    while (!isUp && numTries-- > 0) {
        try {
            // wait .5 secs
            Thread.sleep(500);
            isUp = isUp();
        } catch (Exception e) {
        }
    }
    Assert.assertTrue(isUp, "Server is not up!");
    fillServerPort();
}
Example 4
Project: couchbase-jvm-core-master  File: TestProperties.java View source code
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 5
Project: micro-server-master  File: CouchbaseRunnerTest.java View source code
@Before
public void startServer() {
    try {
        // couchbase already running?
        rest.get("http://localhost:8091/pools");
    } catch (Exception e) {
        CouchbaseMock.main(new String[] { "-S" });
    }
    server = new MicroserverApp(ConfigurableModule.builder().context("simple-app").build());
    server.start();
}
Example 6
Project: memcached-session-manager-master  File: CouchbaseIntegrationTest.java View source code
private List<URI> getURIs() throws URISyntaxException {
    final List<URI> uris = new ArrayList<URI>(cluster.size());
    for (final Pair<CouchbaseMock, Thread> server : cluster) {
        uris.add(new URI("http://localhost:" + server.getFirst().getHttpPort() + "/pools"));
    }
    return uris;
}