Skip to content

Commit

Permalink
RavenDB-3623: Implemented recording functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
maximburyak committed Jul 8, 2015
1 parent 8c9b3df commit cf314ee
Show file tree
Hide file tree
Showing 11 changed files with 835 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Raven.Server/FromMono/Options.cs
Expand Up @@ -1258,6 +1258,9 @@ public enum OptionCategory

[Description("Import Database/FileSystem")]
SmugglerImportDatabaseFileSystem = 1 << 13,

[Description("Record/Replay Options")]
TrafficRecordReplay = 1 << 14,
}
}

2 changes: 1 addition & 1 deletion Raven.Tests.Core/ChangesApi/WebsocketsTests.cs
Expand Up @@ -26,7 +26,7 @@ public async Task Can_connect_via_websockets_and_receive_heartbeat()
using (var clientWebSocket = TryCreateClientWebSocket())
{
string url = store.Url.Replace("http:", "ws:");
url = url + "/changes/websocket?id=" + Guid.NewGuid();
url = url + "/traffic-watch/events?" + Guid.NewGuid();
await clientWebSocket.ConnectAsync(new Uri(url), CancellationToken.None);

var buffer = new byte[1024];
Expand Down
9 changes: 9 additions & 0 deletions RavenDB.sln
Expand Up @@ -101,6 +101,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sparrow.Tryout", "Raven.Spa
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raven.Tests.Web", "Raven.Tests.Web\Raven.Tests.Web.csproj", "{551BAFD7-082C-4ABF-8415-55E178CCA2AD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raven.Traffic", "Tools\Raven.Traffic\Raven.Traffic.csproj", "{5BB7F2B6-CE06-4F1F-9D12-8E25E60FF06F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -330,6 +332,12 @@ Global
{551BAFD7-082C-4ABF-8415-55E178CCA2AD}.Profiling|Any CPU.Build.0 = Release|Any CPU
{551BAFD7-082C-4ABF-8415-55E178CCA2AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{551BAFD7-082C-4ABF-8415-55E178CCA2AD}.Release|Any CPU.Build.0 = Release|Any CPU
{5BB7F2B6-CE06-4F1F-9D12-8E25E60FF06F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5BB7F2B6-CE06-4F1F-9D12-8E25E60FF06F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5BB7F2B6-CE06-4F1F-9D12-8E25E60FF06F}.Profiling|Any CPU.ActiveCfg = Release|Any CPU
{5BB7F2B6-CE06-4F1F-9D12-8E25E60FF06F}.Profiling|Any CPU.Build.0 = Release|Any CPU
{5BB7F2B6-CE06-4F1F-9D12-8E25E60FF06F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5BB7F2B6-CE06-4F1F-9D12-8E25E60FF06F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -365,6 +373,7 @@ Global
{794CC625-31A4-4DA2-968E-5D33CF1CADA1} = {DB0F0968-FB58-4A29-8BEA-F73E55D92665}
{15CDA168-1BF1-4DE6-AD59-DC37494E5C12} = {39EAEB7D-1638-48FA-9BAB-E4FA8F7DB7A4}
{551BAFD7-082C-4ABF-8415-55E178CCA2AD} = {DB0F0968-FB58-4A29-8BEA-F73E55D92665}
{5BB7F2B6-CE06-4F1F-9D12-8E25E60FF06F} = {702CE58F-C8D5-4C3E-8138-98D20B0E26F9}
EndGlobalSection
GlobalSection(CodealikeProperties) = postSolution
SolutionGuid = 6944aade-3195-477c-8aed-9ebe2902fc57
Expand Down
6 changes: 6 additions & 0 deletions Tools/Raven.Traffic/App.config
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
91 changes: 91 additions & 0 deletions Tools/Raven.Traffic/Program.cs
@@ -0,0 +1,91 @@
using System;
using Raven.Abstractions;
using Raven.Client;
using Raven.Client.Document;
using Raven.Traffic;

namespace TrafficRecorder
{

public class Program
{
private static void Main(string[] args)
{
TrafficToolConfiguration config;
var parseStatus = TrafficToolConfiguration.ProcessArgs(args, out config);
switch (parseStatus)
{
case TrafficToolConfiguration.TrafficArgsProcessStatus.InvalidMode:
PrintUsage();
break;
case TrafficToolConfiguration.TrafficArgsProcessStatus.NoArguments:
PrintUsage();
break;
case TrafficToolConfiguration.TrafficArgsProcessStatus.NotEnoughArguments:
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Illegal arguments amount, see usage instructions:");
Console.ForegroundColor = ConsoleColor.White;
break;
case TrafficToolConfiguration.TrafficArgsProcessStatus.ValidConfig:
IDocumentStore store;
try
{
store = new DocumentStore
{
Url = config.ConnectionString.Url,
DefaultDatabase = config.ResourceName,
Credentials = config.ConnectionString.Credentials,
}.Initialize();
}
catch (Exception e)
{
Console.WriteLine("Could not connect to server. Exception: {0}",e);
return;
}

using (store)
{
try
{
store.DatabaseCommands.GetStatistics();
}
catch (Exception e)
{
Console.WriteLine("Database does not exist");
return;
}
new TrafficRec(store, config).ExecuteTrafficCommand();
}
break;
}


}

private static void PrintUsage()
{
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine(@"
Traffic Recording and Replaying utility for RavenDB
----------------------------------------------
Copyright (C) 2008 - {0} - Hibernating Rhinos
----------------------------------------------", SystemTime.UtcNow.Year);
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(@"
Usage:
Raven.Traffic [Mode(rec/play)] [Url] [resource name] [recordingFile] [[option1], [option2] ...]
Examples:
- Record 'Northwind' database found on specified server:
Raven.Traffic rec http://localhost:8080/ Northwind recording.json
- Replay 'Northwind' database from specified server to the dump.raven file:
Raven.Traffic play http://localhost:8080/ Northwind recording.json ");

Console.ForegroundColor = ConsoleColor.Green;
TrafficToolConfiguration.InitOptionsSetObject().WriteOptionDescriptions(Console.Out);
Console.ForegroundColor = ConsoleColor.White;
}


}
}
36 changes: 36 additions & 0 deletions Tools/Raven.Traffic/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TrafficRecorder")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TrafficRecorder")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1a0bd55c-571b-43c9-908c-b560b833ef12")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Empty file.
78 changes: 78 additions & 0 deletions Tools/Raven.Traffic/Raven.Traffic.csproj
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5BB7F2B6-CE06-4F1F-9D12-8E25E60FF06F}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Raven.Traffic</RootNamespace>
<AssemblyName>Raven.Traffic</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\raven.server\frommono\Options.cs">
<Link>FromMono\Options.cs</Link>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TrafficRec.cs" />
<Compile Include="TrafficRecorderConfiguration.cs" />
<Compile Include="TrafficWatchObserver.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Raven.Abstractions\Raven.Abstractions.csproj">
<Project>{41AC479E-1EB2-4D23-AAF2-E4C8DF1BC2BA}</Project>
<Name>Raven.Abstractions</Name>
</ProjectReference>
<ProjectReference Include="..\..\Raven.Client.Lightweight\Raven.Client.Lightweight.csproj">
<Project>{4E087ECB-E7CA-4891-AC3C-3C76702715B6}</Project>
<Name>Raven.Client.Lightweight</Name>
</ProjectReference>
<ProjectReference Include="..\..\Raven.Database\Raven.Database.csproj">
<Project>{212823CD-25E1-41AC-92D1-D6DF4D53FC85}</Project>
<Name>Raven.Database</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

0 comments on commit cf314ee

Please sign in to comment.