Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

Commit

Permalink
remove ExportResultsStream class and use only ResponseStream class fo…
Browse files Browse the repository at this point in the history
…r both export and Result stream
  • Loading branch information
ljiang1 committed Dec 16, 2013
1 parent 75295c8 commit f890f4e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 160 deletions.
99 changes: 0 additions & 99 deletions SplunkSDK/ExportResultsStream.cs

This file was deleted.

13 changes: 5 additions & 8 deletions SplunkSDK/ResponseMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public ResponseMessage(
this.Dispose();
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
if (this.response != null)
Expand All @@ -110,10 +113,7 @@ public void Dispose()
/// <returns>The stream.</returns>
public Stream Content
{
get
{
return this.content;
}
get { return this.content; }
}

/// <summary>
Expand All @@ -138,10 +138,7 @@ public Dictionary<string, string> Header
/// <returns>The status.</returns>
public int Status
{
get
{
return this.status;
}
get { return this.status; }
}
}
}
37 changes: 24 additions & 13 deletions SplunkSDK/ResponseStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,53 @@ namespace Splunk
/// redirected to the original stream.
/// </summary>
[SuppressMessage(
"Microsoft.StyleCop.CSharp.DocumentationRules",
"Microsoft.StyleCop.CSharp.DocumentationRules",
"SA1600:ElementsMustBeDocumented",
Justification =
Justification =
"Internal class. Pure passthrough")]
internal class ResponseStream : Stream
{
private ResponseMessage message;
private readonly bool isExportResult;

internal ResponseStream(ResponseMessage message)
{
this.message = message;
}

internal ResponseStream(ResponseMessage message, bool isExportResult)
{
this.message = message;
this.isExportResult = isExportResult;
}

public new void Dispose()
{
this.message.Dispose();
base.Dispose();
}

/// <summary>
/// Gets the body content stream.
/// </summary>
/// <returns>The stream.</returns>
public bool IsExportResult
{
get { return this.isExportResult; }
}

public override long Position
{
get
{
return this.message.Content.Position;
}

set
{
this.message.Content.Position = value;
}
get { return this.message.Content.Position; }

set { this.message.Content.Position = value; }
}

public override long Length
{
get { return this.message.Content.Length; }
}

public override bool CanRead
{
get { return this.message.Content.CanRead; }
Expand All @@ -71,7 +82,7 @@ public override bool CanSeek
{
get { return this.message.Content.CanSeek; }
}

public override bool CanWrite
{
get { return this.message.Content.CanWrite; }
Expand Down
11 changes: 8 additions & 3 deletions SplunkSDK/ResultsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public abstract class ResultsReader : ISearchResults, IDisposable
/// is false, which results in no result set skipping.
/// </summary>
private bool isPreview;

/// <summary>
/// Initializes a new instance of the <see cref="ResultsReader" /> class.
/// </summary>
Expand All @@ -73,10 +73,15 @@ public abstract class ResultsReader : ISearchResults, IDisposable
/// </param>
protected ResultsReader(Stream stream, bool isInMultiReader)
{
this.IsExportStream = stream is ExportResultsStream;
ResponseStream responseStream = stream as ResponseStream;
if (responseStream != null)
{
this.IsExportStream = responseStream.IsExportResult;
}

this.isInMultiReader = isInMultiReader;
}

/// <summary>
/// Gets a value indicating whether the stream is
/// from the export endpoint.
Expand Down
4 changes: 2 additions & 2 deletions SplunkSDK/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,12 @@ public Stream Export(string search)
/// <param name="search">The search query string.</param>
/// <param name="args">The search arguments.</param>
/// <returns>A results stream.</returns>
public Stream Export(string search, Args args)
public Stream Export(string search, Args args)
{
args = Args.Create(args).Set("search", search);
SetSegmentationDefault(ref args);
ResponseMessage response = Get("search/jobs/export", args);
return new ExportResultsStream(new ResponseStream(response));
return new ResponseStream(response, true);
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion SplunkSDK/SplunkSDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<Compile Include="EntityMetadata.cs" />
<Compile Include="EventType.cs" />
<Compile Include="EventTypeCollection.cs" />
<Compile Include="ExportResultsStream.cs" />
<Compile Include="FiredAlert.cs" />
<Compile Include="FiredAlertGroup.cs" />
<Compile Include="FiredAlertsGroupCollection.cs" />
Expand Down
49 changes: 15 additions & 34 deletions UnitTests/ResultsReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ private const string Splunk502XmlEmptyInputFilePath
/// Splunk Version 5, with simple data common to all readers.
/// </summary>
[TestMethod]
[DeploymentItem(
Splunk5JsonInputFilePath,
TestDataFolder)]
[DeploymentItem(TestDataFolder)]
public void TestReaderJsonOnSplunk5()
{
this.TestReadJson(Splunk5JsonInputFilePath);
Expand All @@ -100,9 +98,7 @@ public void TestReaderJsonOnSplunk5()
/// Splunk Version 4, with simple data common to all readers.
/// </summary>
[TestMethod]
[DeploymentItem(
Splunk4JsonInputFilePath,
TestDataFolder)]
[DeploymentItem(TestDataFolder)]
public void TestReaderJsonOnSplunk4()
{
this.TestReadJson(Splunk4JsonInputFilePath);
Expand All @@ -113,9 +109,7 @@ public void TestReaderJsonOnSplunk4()
/// Splunk, with simple data common to all readers.
/// </summary>
[TestMethod]
[DeploymentItem(
SplunkXmlInputFilePath,
TestDataFolder)]
[DeploymentItem(TestDataFolder)]
public void TestReadXml()
{
var input = this.OpenResourceFileFromDataFolder(
Expand All @@ -134,9 +128,7 @@ public void TestReadXml()
/// http://splunk-base.splunk.com/answers/34106/invalid-xml-returned-from-rest-api
/// </summary>
[TestMethod]
[DeploymentItem(
SplunkExportResultsXmlInputFilePath,
TestDataFolder)]
[DeploymentItem(TestDataFolder)]
public void TestExportMultiReaderXml()
{
var input = this.OpenResourceFileFromDataFolder(
Expand All @@ -153,9 +145,7 @@ public void TestExportMultiReaderXml()
/// with multiple 'results' elements.
/// </summary>
[TestMethod]
[DeploymentItem(
SplunkExportResultsJsonInputFilePath,
TestDataFolder)]
[DeploymentItem(TestDataFolder)]
public void TestExportMultiReaderJson()
{
var input = this.OpenResourceFileFromDataFolder(
Expand Down Expand Up @@ -246,9 +236,7 @@ private void TestExportMultiReader<T>(
/// http://splunk-base.splunk.com/answers/34106/invalid-xml-returned-from-rest-api
/// </summary>
[TestMethod]
[DeploymentItem(
SplunkExportResultsXmlInputFilePath,
TestDataFolder)]
[DeploymentItem(TestDataFolder)]
public void TestExportSingleReaderXml()
{
var stream = this.GetExportResultsStream(
Expand All @@ -264,9 +252,7 @@ public void TestExportSingleReaderXml()
/// with multiple 'results' elements.
/// </summary>
[TestMethod]
[DeploymentItem(
SplunkExportResultsJsonInputFilePath,
TestDataFolder)]
[DeploymentItem(TestDataFolder)]
public void TestExportSingleReaderJson()
{
var stream = this.GetExportResultsStream(
Expand All @@ -281,12 +267,13 @@ public void TestExportSingleReaderJson()
/// </summary>
/// <param name="fileName">A file name</param>
/// <returns>A export stream</returns>
private ExportResultsStream GetExportResultsStream(string fileName)
private ResponseStream GetExportResultsStream(string fileName)
{
var stream = this.OpenResourceFileFromDataFolder(
fileName);
fileName);

return new ExportResultsStream(stream);
ResponseMessage message = new ResponseMessage(0, stream, null);
return new ResponseStream(message, true);
}

/// <summary>
Expand Down Expand Up @@ -326,9 +313,7 @@ private void TestExportSingleReader(
/// Splunk, covering preview and field '_raw'.
/// </summary>
[TestMethod]
[DeploymentItem(
Splunk435PreviewXmlInputFilePath,
TestDataFolder)]
[DeploymentItem(TestDataFolder)]
public void TestReadXmlPreviewAndFields()
{
var input = this.OpenResourceFileFromDataFolder(
Expand Down Expand Up @@ -375,9 +360,7 @@ public void TestReadXmlPreviewAndFields()
/// Splunk, covering empty results.
/// </summary>
[TestMethod]
[DeploymentItem(
Splunk502XmlEmptyInputFilePath,
TestDataFolder)]
[DeploymentItem(TestDataFolder)]
public void TestReadXmlEmpty()
{
var input = this.OpenResourceFileFromDataFolder(
Expand All @@ -402,9 +385,7 @@ public void TestReadXmlEmpty()
/// and XML charactor escaping.
/// </summary>
[TestMethod]
[DeploymentItem(
Splunk502XmlInputFilePath,
TestDataFolder)]
[DeploymentItem(TestDataFolder)]
public void TestReadXmlSplunk5MVAndFieldRaw()
{
var input = this.OpenResourceFileFromDataFolder(
Expand Down Expand Up @@ -582,7 +563,7 @@ private static void AddToEvent(
/// <returns>Stream of resource content</returns>
private Stream OpenResourceFileFromDataFolder(string relativePath)
{
return File.OpenRead(TestDataFolder + @"\" + relativePath);
return File.OpenRead(Directory.GetCurrentDirectory() + @"\" + relativePath);
}

/// <summary>
Expand Down

0 comments on commit f890f4e

Please sign in to comment.