Ejemplo n.º 1
0
        public async Task Test(string file, HttpStatusCode httpStatusCode, Type errorType)
        {
            using (var response = ResourceHelper.ReadResourceAsStream(@"Documents\Query\" + file))
            {
                var buffer = new byte[response.Length];
                response.Read(buffer, 0, buffer.Length);

                var handlerMock = new Mock <HttpMessageHandler>();
                handlerMock.Protected().Setup <Task <HttpResponseMessage> >(
                    "SendAsync",
                    ItExpr.IsAny <HttpRequestMessage>(),
                    ItExpr.IsAny <CancellationToken>()).ReturnsAsync(new HttpResponseMessage
                {
                    StatusCode = httpStatusCode,
                    Content    = new ByteArrayContent(buffer)
                });

                var httpClient = new HttpClient(handlerMock.Object)
                {
                    BaseAddress = new Uri("http://localhost:8091")
                };
                var config      = new ClusterOptions().WithBucket("default").WithServers("http://localhost:8901");
                var clusterNode = new ClusterNode
                {
                    ClusterOptions = config,
                    EndPoint       = new Uri("http://localhost:8091").GetIpEndPoint(8091, false),
                    NodesAdapter   = new NodeAdapter(new Node {
                        Hostname = "127.0.0.1"
                    },
                                                     new NodesExt {
                        Hostname = "127.0.0.1", Services = new Couchbase.Core.Configuration.Server.Services
                        {
                            N1Ql = 8093
                        }
                    }, new BucketConfig())
                };
                clusterNode.BuildServiceUris();

                config.GlobalNodes = new ConcurrentBag <IClusterNode> {
                    clusterNode
                };

                var client = new QueryClient(httpClient, new JsonDataMapper(new DefaultSerializer()), config);

                try
                {
                    await client.QueryAsync <DynamicAttribute>("SELECT * FROM `default`", new QueryOptions());
                }
                catch (Exception e)
                {
                    Assert.True(e.GetType() == errorType);
                }
            }
        }
Ejemplo n.º 2
0
        private async Task LoadClusterMap()
        {
            foreach (var nodesExt in _bucketConfig.NodesExt)//will need to update to use "NodeAdapter" = Nodes + NodesExt like in 2.0
            {
                var endpoint = nodesExt.GetIpEndPoint(_configuration);
                if (_bucketNodes.TryGetValue(endpoint, out ClusterNode bootstrapNode))
                {
                    bootstrapNode.NodesExt = nodesExt;
                    bootstrapNode.BuildServiceUris();
                    continue; //bootstrap node is skipped because it already went through these steps
                }

                var connection = endpoint.GetConnection();
                await connection.Authenticate(_configuration, Name).ConfigureAwait(false);

                await connection.SelectBucket(Name).ConfigureAwait(false);

                //one error map per node
                var errorMap = await connection.GetErrorMap().ConfigureAwait(false);

                var supportedFeatures = await connection.Hello().ConfigureAwait(false);

                var clusterNode = new ClusterNode
                {
                    Connection     = connection,
                    ErrorMap       = errorMap,
                    EndPoint       = endpoint,
                    ServerFeatures = supportedFeatures,
                    Configuration  = _configuration,
                    NodesExt       = nodesExt,

                    //build the services urls
                    QueryUri     = endpoint.GetQueryUri(_configuration, nodesExt),
                    SearchUri    = endpoint.GetSearchUri(_configuration, nodesExt),
                    AnalyticsUri = endpoint.GetAnalyticsUri(_configuration, nodesExt),
                    ViewsUri     = endpoint.GetViewsUri(_configuration, nodesExt),
                };
                clusterNode.BuildServiceUris();
                _supportsCollections = clusterNode.Supports(ServerFeatures.Collections);
                _bucketNodes.AddOrUpdate(endpoint, clusterNode, (ep, node) => clusterNode);
                _configuration.GlobalNodes.Add(clusterNode);
            }
        }
        private async Task LoadClusterMap(BucketConfig bucketConfig)
        {
            foreach (var nodesExt in bucketConfig.NodesExt)
            {
                var endPoint = nodesExt.GetIpEndPoint(_configuration);
                if (_bucketNodes.TryGetValue(endPoint, out ClusterNode bootstrapNode))
                {
                    bootstrapNode.NodesExt = nodesExt;
                    bootstrapNode.BuildServiceUris();
                    continue; //bootstrap node is skipped because it already went through these steps
                }

                var connection = endPoint.GetConnection();
                await connection.Authenticate(_configuration, Name).ConfigureAwait(false);

                await connection.SelectBucket(Name).ConfigureAwait(false);

                //one error map per node
                var errorMap = await connection.GetErrorMap().ConfigureAwait(false);

                var supportedFeatures = await connection.Hello().ConfigureAwait(false);

                var clusterNode = new ClusterNode
                {
                    Connection     = connection,
                    ErrorMap       = errorMap,
                    EndPoint       = endPoint,
                    ServerFeatures = supportedFeatures,
                    Configuration  = _configuration,
                    NodesExt       = nodesExt
                };
                clusterNode.BuildServiceUris();
                _supportsCollections = clusterNode.Supports(ServerFeatures.Collections);
                _bucketNodes.AddOrUpdate(endPoint, clusterNode, (ep, node) => clusterNode);
                _configuration.GlobalNodes.Add(clusterNode);
            }
        }