Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a way to simulate a non trivial work load
- Loading branch information
Showing
12 changed files
with
601 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.