示例#1
0
 public static int GetMaxNrOfTimeoutsWithoutIndexByRavenVersion(RavenDbVersion version)
 {
     return(version switch
     {
         RavenDbVersion.ThreeDotFive => 300000,
         RavenDbVersion.Four => 1000000,
         _ => throw new ArgumentOutOfRangeException("Unsupported version of RavenDB"),
     });
 static async Task CreateIndex(string serverName, string databaseName, RavenDbVersion version)
 {
     if (version == RavenDbVersion.ThreeDotFive)
     {
         await CreateRaven3Index(serverName, databaseName);
     }
     else
     {
         await CreateRaven4Index(serverName, databaseName);
     }
 }
示例#3
0
 public RavenDbTimeoutsSource(
     ILogger logger,
     string serverUrl,
     string databaseName,
     string timeoutDocumentPrefix,
     RavenDbVersion ravenVersion,
     bool useIndex)
 {
     this.logger = logger;
     this.timeoutDocumentPrefix = timeoutDocumentPrefix;
     this.ravenVersion          = ravenVersion;
     this.useIndex = useIndex;
     ravenAdapter  = RavenDataReaderFactory.Resolve(serverUrl, databaseName, ravenVersion);
 }
        static StringContent BuildHttpContentForDbCreation(RavenDbVersion ravenVersion, string databaseName)
        {
            StringContent stringContent;

            if (ravenVersion == RavenDbVersion.Four)
            {
                // Create the db
                var dbRaven4 = new DatabaseRecordRaven4
                {
                    Disabled     = false,
                    DatabaseName = databaseName
                };
                stringContent = new StringContent(JsonConvert.SerializeObject(dbRaven4));
                return(stringContent);
            }

            var dbRaven3 = new DatabaseRecordRaven3(databaseName);

            stringContent = new StringContent(JsonConvert.SerializeObject(dbRaven3));
            return(stringContent);
        }
示例#5
0
 public static ICanTalkToRavenVersion Resolve(string serverUrl, string databaseName, RavenDbVersion version)
 {
     return(version switch
     {
         RavenDbVersion.ThreeDotFive => new Raven3Adapter(serverUrl, databaseName),
         RavenDbVersion.Four => new Raven4Adapter(serverUrl, databaseName),
         _ => throw new ArgumentOutOfRangeException(nameof(version), version, null),
     });
        static async Task <int> InitTimeouts(decimal nrOfBatches, string serverName, string databaseName, int nrOfTimeoutsToInsert, string timeoutsPrefix, RavenDbVersion ravenVersion)
        {
            var timeoutIdCounter = 0;

            // batch inserts per paging size
            for (var i = 1; i <= nrOfBatches; i++)
            {
                var commands      = new List <object>();
                var bulkInsertUrl = $"{serverName}/databases/{databaseName}/bulk_docs";

                for (var j = 0; j < RavenConstants.DefaultPagingSize && timeoutIdCounter < nrOfTimeoutsToInsert; j++)
                {
                    timeoutIdCounter++;
                    var timeout = CreateTimeoutData(timeoutsPrefix, timeoutIdCounter);

                    var insertCommand = ravenVersion == RavenDbVersion.Four ? CreateRaven4TimeoutInsertCommand(timeout) : CreateRaven3TimeoutInsertCommand(timeout);
                    commands.Add(insertCommand);
                }

                object request;
                if (ravenVersion == RavenDbVersion.Four)
                {
                    request = new
                    {
                        Commands = commands.ToArray()
                    };
                }
                else
                {
                    request = commands.ToArray();
                }

                var serializeObject = JsonConvert.SerializeObject(request);
                var result          = await httpClient.PostAsync(bulkInsertUrl, new StringContent(serializeObject, Encoding.UTF8, "application/json"));

                result.EnsureSuccessStatusCode();
                Console.Write(".");
            }

            return(timeoutIdCounter);
        }