Permalink
Browse files

Adding a way to simulate a non trivial work load

  • Loading branch information...
1 parent cfbf67c commit 5970bc09a660f70009746fc83bfecdb1439168a2 @ayende committed Dec 20, 2012
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <connectionStrings>
+ <add name="RavenDB" connectionString="Url=http://localhost:8080;Database=Load"/>
+ </connectionStrings>
+ <appSettings>
+ <add key="DataPath" value="C:\Work\Temp"/>
+ </appSettings>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+ </startup>
+</configuration>
@@ -0,0 +1,21 @@
+// -----------------------------------------------------------------------
+// <copyright file="Users_Locations.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+// -----------------------------------------------------------------------
+using System.Linq;
+using Raven.Client.Indexes;
+using Raven.SimulatedWorkLoad.Model;
+
+namespace Raven.SimulatedWorkLoad.Indexes
+{
+ public class Users_Locations : AbstractIndexCreationTask<User>
+ {
+ public Users_Locations()
+ {
+ Map = users =>
+ from user in users
+ select new {user.City, user.State, user.StreetAddress, user.Zip};
+ }
+ }
+}
@@ -0,0 +1,24 @@
+// -----------------------------------------------------------------------
+// <copyright file="Users_Search.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+// -----------------------------------------------------------------------
+using System.Linq;
+using Raven.Client.Indexes;
+using Raven.SimulatedWorkLoad.Model;
+
+namespace Raven.SimulatedWorkLoad.Indexes
+{
+ public class Users_Search : AbstractIndexCreationTask<User>
+ {
+ public Users_Search()
+ {
+ Map = users =>
+ from user in users
+ select new
+ {
+ Query = new object[] { user.First, user.Last, user.Email, user.Email.Split('@'), user.Phone }
+ };
+ }
+ }
+}
@@ -0,0 +1,70 @@
+// -----------------------------------------------------------------------
+// <copyright file="Users_Stats_ByCountry.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+// -----------------------------------------------------------------------
+using System.Linq;
+using Raven.Client.Indexes;
+using Raven.SimulatedWorkLoad.Model;
+
+namespace Raven.SimulatedWorkLoad.Indexes
+{
+ public class Users_Stats_ByState : AbstractIndexCreationTask<User, Users_Stats_ByState.Result>
+ {
+ public class Result
+ {
+ public string State { get; set; }
+ public int Count { get; set; }
+ }
+ public Users_Stats_ByState()
+ {
+ Map = users =>
+ from user in users
+ select new
+ {
+ user.State,
+ Count = 1
+ };
+ Reduce = results =>
+ from result in results
+ group result by result.State
+ into g
+ select new
+ {
+ State = g.Key,
+ Count = g.Sum(x => x.Count)
+ };
+ }
+ }
+
+ public class Users_Stats_ByStateAndcity : AbstractIndexCreationTask<User, Users_Stats_ByStateAndcity.Result>
+ {
+ public class Result
+ {
+ public string State { get; set; }
+ public string City { get; set; }
+ public int Count { get; set; }
+ }
+ public Users_Stats_ByStateAndcity()
+ {
+ Map = users =>
+ from user in users
+ select new
+ {
+ user.State,
+ user.City,
+ Count = 1
+ };
+ Reduce = results =>
+ from result in results
+ group result by new { result.State , result.City}
+ into g
+ select new
+ {
+ g.Key.State,
+ g.Key.City,
+ Count = g.Sum(x => x.Count)
+ };
+ }
+ }
+}
@@ -0,0 +1,14 @@
+namespace Raven.SimulatedWorkLoad.Model
+{
+ public class User
+ {
+ public string City { get; set; }
+ public string Email { get; set; }
+ public string First { get; set; }
+ public string Last { get; set; }
+ public string Phone { get; set; }
+ public string State { get; set; }
+ public string StreetAddress { get; set; }
+ public string Zip { get; set; }
+ }
+}
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Concurrent;
+using System.Collections.Generic;
+using System.Reactive.Disposables;
+using Raven.Database.Util;
+
+namespace Raven.SimulatedWorkLoad
+{
+ public class Observing<T> : IObservable<T>
+ {
+ private readonly IEnumerator<T> enumerator;
+ private readonly ConcurrentSet<IObserver<T>> observers = new ConcurrentSet<IObserver<T>>();
+
+ public bool Completed { get; private set; }
+
+ public Observing(IEnumerable<T> src)
+ {
+ enumerator = src.GetEnumerator();
+ }
+
+ public IDisposable Subscribe(IObserver<T> observer)
+ {
+ observers.Add(observer);
+ return Disposable.Create(() => observers.TryRemove(observer));
+ }
+
+ public void Release(int count)
+ {
+ if (Completed)
+ return;
+
+ for (int i = 0; i < count; i++)
+ {
+ if (enumerator.MoveNext() == false)
+ {
+ foreach (var observer in observers)
+ {
+ observer.OnCompleted();
+ }
+ Completed = true;
+ break;
+ }
+ foreach (var observer in observers)
+ {
+ observer.OnNext(enumerator.Current);
+ }
+ }
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 5970bc0

Please sign in to comment.