示例#1
0
        public Test_AnsibleCouchbaseQuery(CouchbaseFixture couchbase)
        {
            this.couchbase = couchbase;

            // These tests are all read-only so we're going to initialize the
            // database once with some test data.

            if (couchbase.Start())
            {
                var block = new List <IDocument <TestInfo> >();

                for (int docNum = 0; docNum < docCount; docNum++)
                {
                    var doc = new Document <TestInfo>();

                    doc.Id           = Guid.NewGuid().ToString("D");
                    doc.Content      = new TestInfo();
                    doc.Content.name = $"name-{docNum.ToString("000#")}";
                    doc.Content.age  = docNum;

                    block.Add(doc);
                }

                couchbase.Bucket.InsertSafeAsync <TestInfo>(block).Wait();
            }

            bucket = couchbase.Bucket;
        }
示例#2
0
        public Test_NeonBucket(CouchbaseFixture couchbase)
        {
            this.couchbase = couchbase;

            couchbase.Start();

            bucket = couchbase.Bucket;
        }
示例#3
0
        public Test_CouchbaseFlushInTest(CouchbaseFixture couchbase)
        {
            this.couchbase = couchbase;

            couchbase.Start();

            bucket = couchbase.Bucket;
        }
示例#4
0
        public Test_NeonBucket(CouchbaseFixture couchbase)
        {
            TestHelper.ResetDocker(this.GetType());

            this.couchbase = couchbase;

            couchbase.Start();

            bucket = couchbase.Bucket;
        }
        public Test_CouchbaseCommands(CouchbaseFixture couchbase)
        {
            this.couchbase = couchbase;

            if (couchbase.Start() == TestFixtureStatus.AlreadyRunning)
            {
                couchbase.Clear();
            }

            bucket  = couchbase.Bucket;
            context = new BucketContext(bucket);
        }
示例#6
0
        public Test_CouchbaseFlushInConstructor(CouchbaseFixture couchbase)
        {
            this.couchbase = couchbase;

            if (!couchbase.Start())
            {
                // Clear the database if we didn't just start it.

                couchbase.Clear();
            }

            bucket = couchbase.Bucket;
        }
示例#7
0
        public Test_AnsibleCouchbaseImport(CouchbaseFixture couchbase)
        {
            this.couchbase = couchbase;

            if (!couchbase.Start())
            {
                // Clear the database if we didn't just start it.

                couchbase.Clear();
            }

            bucket = couchbase.Bucket;
        }
示例#8
0
        public Test_CouchbaseFixture(CouchbaseFixture couchbase)
        {
            this.couchbase = couchbase;

            couchbase.Start();

            bucket = couchbase.Bucket;

            jsonClient             = new JsonClient();
            jsonClient.BaseAddress = new Uri("http://localhost:8094");
            jsonClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                "Basic",
                Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes($"Administrator:password")));
        }
示例#9
0
        public Test_CouchbaseReadOnly(CouchbaseFixture couchbase)
        {
            this.couchbase = couchbase;

            if (couchbase.Start())
            {
                // We're going to initialize read-only Couchbase data here
                // and since this initialization action is called only once
                // by the test runner for this test class, the database
                // state will be shared across all of the test method calls.

                var bucket = couchbase.Bucket;

                bucket.UpsertSafeAsync("one", "1").Wait();
                bucket.UpsertSafeAsync("two", "2").Wait();
            }

            bucket = couchbase.Bucket;
        }
示例#10
0
        public Test_Docker(DockerFixture fixture)
        {
            this.fixture = fixture;

            var reset = fixture.Initialize(
                () =>
            {
                // We're going to add a [HostsFixture] so tests can modify
                // the local [hosts] file to customize DNS lookups.  Note
                // that subfixtures are identified by name and can be
                // retrieved later using a fixture indexer.

                fixture.AddFixture("hosts", new HostsFixture());

                // Add a Couchbase instance to the test.

                fixture.AddFixture("couchbase", new CouchbaseFixture(), subFixture => subFixture.StartInAction());
            });

            // Fetch the hosts fixture so it'll be easy to access from
            // the tests.

            hosts     = (HostsFixture)fixture["hosts"];
            couchbase = (CouchbaseFixture)fixture["couchbase"];
            bucket    = couchbase.Bucket;

            if (!reset)
            {
                // Reset the fixture state if the [Initialize()]
                // method hasn't already done so.

                hosts.Reset();
                fixture.Reset();
                couchbase.Clear();
            }
        }
示例#11
0
        /// <summary>
        /// Returns a Couchbase bucket connection using specified settings and the cluster credentials.
        /// </summary>
        /// <param name="settings">The Couchbase settings.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="timeout">The optional timeout (defaults to 60 seconds).</param>
        /// <param name="ignoreDurability">Optionally configure the bucket to ignore durability parameters.</param>
        /// <returns>The connected <see cref="NeonBucket"/>.</returns>
        /// <exception cref="TimeoutException">Thrown if the bucket is not ready after waiting <paramref name="timeout"/>.</exception>
        /// <remarks>
        /// <para>
        /// You may explicitly pass <paramref name="ignoreDurability"/><c>=true</c> for
        /// development and test environments where there may not be enough cluster nodes to
        /// satisfy durability constraints.  If this is <c>null</c> (the default) then the bucket
        /// will look for the presence of the <b>DEV_WORKSTATION</b> environment variable
        /// and ignore durability constraints if this variable exists, otherwise durability
        /// constraints will be honored.
        /// </para>
        /// </remarks>
        public static NeonBucket OpenBucket(this CouchbaseSettings settings,
                                            string username,
                                            string password,
                                            TimeSpan timeout      = default(TimeSpan),
                                            bool?ignoreDurability = null)
        {
            var bucketConfig =
                new BucketConfiguration()
            {
                BucketName            = settings.Bucket,
                UseEnhancedDurability = settings.UseEnhancedDurability,

                PoolConfiguration = new PoolConfiguration()
                {
                    ConnectTimeout = settings.ConnectTimeout,
                    SendTimeout    = settings.SendTimeout,
                    MaxSize        = settings.MaxPoolConnections,
                    MinSize        = settings.MinPoolConnections
                }
            };

            bucketConfig.PoolConfiguration.ClientConfiguration =
                new ClientConfiguration()
            {
                QueryRequestTimeout = (uint)settings.QueryRequestTimeout,
                ViewRequestTimeout  = settings.ViewRequestTimeout,
                Serializer          = () => new EntitySerializer()
            };

            var config = settings.ToClientConfig();

            config.BucketConfigs.Clear();
            config.BucketConfigs.Add(settings.Bucket, bucketConfig);

            var cluster = new Cluster(config);

            // We have to wait for three Couchbase operations to complete
            // successfully:
            //
            //      1. Authenticate
            //      2. Open Bucket
            //      3. List Indexes
            //
            // Each of these can fail if Couchbase isn't ready.  The Open Bucket
            // can fail after the Authenticate succeeded because the bucket is
            // still warming up in the cluster.

            if (timeout <= TimeSpan.Zero)
            {
                timeout = NeonBucket.ReadyTimeout;
            }

            //-----------------------------------------------------------------
            // Authenticate against the Couchbase cluster.

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            NeonHelper.WaitFor(
                () =>
            {
                try
                {
                    cluster.Authenticate(username, password);
                    return(true);
                }
                catch
                {
                    return(false);
                }
            },
                timeout: timeout,
                pollTime: TimeSpan.FromSeconds(0.5));

            //-----------------------------------------------------------------
            // Open the bucket.  Note that we're going to recreate the bucket after
            // each failed attempt because it doesn't seem to recover from connection
            // failures.
            //
            // I believe this may be due to the index and or query services not being
            // ready yet after Couchbase has just been spun up and the bucket isn't
            // notified when these become ready, even after some time passes.

            timeout = timeout - stopwatch.Elapsed;  // Adjust the timeout downward by the time taken to authenticate.
            stopwatch.Restart();

            var bucket = (NeonBucket)null;

            NeonHelper.WaitFor(
                () =>
            {
                try
                {
                    bucket = new NeonBucket(cluster.OpenBucket(settings.Bucket), settings, ignoreDurability);
                    return(true);
                }
                catch
                {
                    return(false);
                }
            },
                timeout: timeout,
                pollTime: TimeSpan.FromSeconds(0.5));

            //-----------------------------------------------------------------
            // Wait until the bucket can perform a simple read operation without
            // failing.  It appears that we can see early failures for Couchbase
            // clusters that have just been created (e.g. during unit tests).

            timeout = timeout - stopwatch.Elapsed;  // Adjust the timeout downward by the time taken to connect.
            stopwatch.Restart();

            bucket.WaitUntilReadyAsync(timeout).Wait();

            return(bucket);
        }