Skip to content

Commit fad8b99

Browse files
committed
attachment integration tests WIP
1 parent c1e062b commit fad8b99

File tree

10 files changed

+258
-48
lines changed

10 files changed

+258
-48
lines changed

src/Tests/Aggregations/Bucket/DateHistogram/DateHistogramAggregationUsageTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ namespace Tests.Aggregations.Bucket.DateHistogram
1313
* From a functionality perspective, this histogram supports the same features as the normal histogram.
1414
* The main difference is that the interval can be specified by date/time expressions.
1515
*
16-
* When specifying a format and extended_bounds, in order for Elasticsearch to be able to parse
17-
* the serialized DateTimes of extended_bounds correctly, the date_optional_time format is included
18-
* as part of the format value.
16+
* When both format and extended_bounds are specified, the `date_optional_time` format is included
17+
* as part of the format value so that Elasticsearch to be able to parse
18+
* the serialized DateTimes of extended_bounds correctly.
1919
*
2020
* Be sure to read the elasticsearch documentation {ref}/search-aggregations-bucket-datehistogram-aggregation.html[on this subject here]
2121
*/

src/Tests/Aggregations/Bucket/Filters/FiltersAggregationUsageTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99

1010
namespace Tests.Aggregations.Bucket.Filters
1111
{
12-
/**
12+
/** == Named filters
13+
*
1314
* Defines a multi bucket aggregations where each bucket is associated with a filter.
1415
* Each bucket will collect all documents that match its associated filter. For documents
1516
* that do not match any filter, these will be collected in the other bucket.
1617
*
1718
* Be sure to read the elasticsearch documentation {ref}/search-aggregations-bucket-filters-aggregation.html[on this subject here]
1819
*/
19-
20-
/** == Named filters **/
2120
public class FiltersAggregationUsageTests : AggregationUsageTestBase
2221
{
2322
public FiltersAggregationUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { }
@@ -111,7 +110,6 @@ protected override void ExpectResponse(ISearchResponse<Project> response)
111110
}
112111

113112
/** == Anonymous filters **/
114-
115113
public class AnonymousUsage : AggregationUsageTestBase
116114
{
117115
public AnonymousUsage(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { }

src/Tests/ClientConcepts/LowLevel/PostData.doc.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Tests.ClientConcepts.LowLevel
1313
{
1414
public class PostingData
1515
{
16-
/** # Post data
16+
/** ## Post data
1717
* The low level allows you to post a string, byte[] array directly. On top of this if you pass a list of strings or objects
1818
* they will be serialized in Elasticsearch's special bulk/multi format.
1919
*/

src/Tests/Document/Single/Attachment/AttachmentApiTests.cs

Lines changed: 139 additions & 0 deletions
Large diffs are not rendered by default.
Binary file not shown.

src/Tests/Framework/Integration/Process/ElasticsearchNode.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ public class ElasticsearchNode : IDisposable
2222
{
2323
private static readonly object _lock = new object();
2424
// <installpath> <> <plugin folder prefix>
25-
private readonly Dictionary<string, string> SupportedPlugins = new Dictionary<string, string>
25+
private readonly Dictionary<string, Func<string, string>> SupportedPlugins = new Dictionary<string, Func<string, string>>
2626
{
27-
{ "delete-by-query", "delete-by-query" },
28-
{ "cloud-azure", "cloud-azure" }
27+
{ "delete-by-query", _ => "delete-by-query" },
28+
{ "cloud-azure", _ => "cloud-azure" },
29+
{ "mapper-attachments", MapperAttachmentPlugin.GetVersion },
30+
{ "mapper-murmur3", _ => "mapper-murmur3" },
2931
};
3032

3133
private readonly bool _doNotSpawnIfAlreadyRunning;
@@ -253,7 +255,7 @@ private void DownloadAndExtractElasticsearch()
253255

254256
if (!Directory.Exists(this.RoamingClusterFolder))
255257
{
256-
Console.WriteLine($"Unziping elasticsearch: {this.Version} ...");
258+
Console.WriteLine($"Unzipping elasticsearch: {this.Version} ...");
257259
ZipFile.ExtractToDirectory(localZip, this.RoamingFolder);
258260
}
259261

@@ -288,40 +290,40 @@ private void InstallPlugins()
288290
foreach (var plugin in SupportedPlugins)
289291
{
290292
var installPath = plugin.Key;
291-
var localPath = plugin.Value;
292-
var pluginFolder = Path.Combine(this.RoamingClusterFolder, "plugins", localPath);
293+
var command = plugin.Value(this.Version);
294+
var pluginFolder = Path.Combine(this.RoamingClusterFolder, "plugins", installPath);
293295

294296
if (!Directory.Exists(this.RoamingClusterFolder)) continue;
295297

296298
// assume plugin already installed
297299
if (Directory.Exists(pluginFolder)) continue;
298300

299-
Console.WriteLine($"Installing elasticsearch plugin: {localPath} ...");
300-
var timeout = TimeSpan.FromSeconds(60);
301+
Console.WriteLine($"Installing elasticsearch plugin: {installPath} ...");
302+
var timeout = TimeSpan.FromSeconds(120);
301303
var handle = new ManualResetEvent(false);
302304
Task.Run(() =>
303305
{
304-
using (var p = new ObservableProcess(pluginBat, "install", installPath))
306+
using (var p = new ObservableProcess(pluginBat, "install", command))
305307
{
306308
var o = p.Start();
307-
Console.WriteLine($"Calling: {pluginBat} install {installPath}");
309+
Console.WriteLine($"Calling: {pluginBat} install {command}");
308310
o.Subscribe(e=>Console.WriteLine(e),
309311
(e) =>
310312
{
311-
Console.WriteLine($"Failed installing elasticsearch plugin: {localPath} ");
313+
Console.WriteLine($"Failed installing elasticsearch plugin: {command}");
312314
handle.Set();
313315
throw e;
314316
},
315317
() => {
316-
Console.WriteLine($"Finished installing elasticsearch plugin: {localPath} exit code: {p.ExitCode}");
318+
Console.WriteLine($"Finished installing elasticsearch plugin: {installPath} exit code: {p.ExitCode}");
317319
handle.Set();
318320
});
319321
if (!handle.WaitOne(timeout, true))
320-
throw new Exception($"Could not install ${installPath} within {timeout}");
322+
throw new Exception($"Could not install {command} within {timeout}");
321323
}
322324
});
323325
if (!handle.WaitOne(timeout, true))
324-
throw new Exception($"Could not install ${installPath} within {timeout}");
326+
throw new Exception($"Could not install {command} within {timeout}");
325327
}
326328
}
327329

@@ -361,7 +363,7 @@ public void Stop()
361363
this._process?.Dispose();
362364
this._processListener?.Dispose();
363365

364-
if (this.Info != null && this.Info.Pid.HasValue)
366+
if (this.Info?.Pid != null)
365367
{
366368
var esProcess = Process.GetProcessById(this.Info.Pid.Value);
367369
Console.WriteLine($"Killing elasticsearch PID {this.Info.Pid}");
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Generic;
2+
3+
namespace Tests.Framework.Integration
4+
{
5+
public class MapperAttachmentPlugin
6+
{
7+
private static readonly Dictionary<string, string> Versions = new Dictionary<string, string>
8+
{
9+
{"2.1.2", "elasticsearch/elasticsearch-mapper-attachments/3.1.2"},
10+
{"2.1.1", "elasticsearch/elasticsearch-mapper-attachments/3.1.1"},
11+
{"2.1.0", "elasticsearch/elasticsearch-mapper-attachments/3.1.0"},
12+
{"2.0.2", "elasticsearch/elasticsearch-mapper-attachments/3.0.4"},
13+
{"2.0.1", "elasticsearch/elasticsearch-mapper-attachments/3.0.3"},
14+
{"2.0.0", "elasticsearch/elasticsearch-mapper-attachments/3.0.2"},
15+
{"2.0.0-beta2", "elasticsearch/elasticsearch-mapper-attachments/3.0.1"},
16+
{"2.0.0-beta1", "elasticsearch/elasticsearch-mapper-attachments/3.0.0"},
17+
{"1.7", "elasticsearch/elasticsearch-mapper-attachments/2.7.1"},
18+
{"1.6", "elasticsearch/elasticsearch-mapper-attachments/2.6.0"},
19+
{"1.5", "elasticsearch/elasticsearch-mapper-attachments/2.5.0"},
20+
{"1.4", "elasticsearch/elasticsearch-mapper-attachments/2.4.3"},
21+
{"1.3", "elasticsearch/elasticsearch-mapper-attachments/2.3.2"},
22+
{"1.2", "elasticsearch/elasticsearch-mapper-attachments/2.2.1"},
23+
{"1.1", "elasticsearch/elasticsearch-mapper-attachments/2.0.0"},
24+
{"1.0", "elasticsearch/elasticsearch-mapper-attachments/2.0.0"},
25+
{"0.90", "elasticsearch/elasticsearch-mapper-attachments/1.9.0"}
26+
};
27+
28+
public static string GetVersion(string elasticsearchVersion)
29+
{
30+
string attachmentVersion;
31+
if (!Versions.TryGetValue(elasticsearchVersion, out attachmentVersion))
32+
{
33+
// assume latest version in elasticsearch repository
34+
attachmentVersion = "mapper-attachments";
35+
}
36+
37+
return attachmentVersion;
38+
}
39+
}
40+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
7+
namespace Tests.Framework.Integration
8+
{
9+
public static class ProjectDirectory
10+
{
11+
static ProjectDirectory()
12+
{
13+
var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
14+
15+
// If running the classic .NET solution, tests run from bin/{config} directory,
16+
// but when running DNX solution, tests run from the test project root
17+
Root = directoryInfo.Name == "Tests" &&
18+
directoryInfo.Parent != null &&
19+
directoryInfo.Parent.Name == "src"
20+
? @".\"
21+
: @"..\..\";
22+
}
23+
24+
public static string Root { get; }
25+
}
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
3+
namespace Tests.Framework.MockData
4+
{
5+
public class Attachment
6+
{
7+
public string File { get; set; }
8+
9+
public string Author { get; set; }
10+
11+
public long? ContentLength { get; set; }
12+
13+
public string ContentType { get; set; }
14+
15+
public DateTime? Date { get; set; }
16+
17+
public string Keywords { get; set; }
18+
19+
public string Language { get; set; }
20+
21+
public string Name { get; set; }
22+
23+
public string Title { get; set; }
24+
}
25+
}

src/Tests/Mapping/Types/Specialized/Attachment/AttachmentMappingTests.cs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,11 @@
44
using System.Threading.Tasks;
55
using Nest;
66
using Xunit;
7+
using Tests.Framework.MockData;
78

89
namespace Tests.Mapping.Types.Specialized.Attachment
910
{
10-
public class AttachmentTest
11-
{
12-
public string File { get; set; }
13-
14-
public string Author { get; set; }
15-
16-
public long ContentLength { get; set; }
17-
18-
public string ContentType { get; set; }
19-
20-
public DateTime Date { get; set; }
21-
22-
public string Keywords { get; set; }
23-
24-
public string Language { get; set; }
25-
26-
public string Name { get; set; }
27-
28-
public string Title { get; set; }
29-
}
30-
31-
public class AttachmentMappingTests : TypeMappingTestBase<AttachmentTest>
11+
public class AttachmentMappingTests : TypeMappingTestBase<Tests.Framework.MockData.Attachment>
3212
{
3313
protected override object ExpectJson => new
3414
{
@@ -87,7 +67,7 @@ protected override void AttributeBasedSerializes()
8767
// TODO: Implement
8868
}
8969

90-
protected override Func<PropertiesDescriptor<AttachmentTest>, IPromise<IProperties>> FluentProperties => p => p
70+
protected override Func<PropertiesDescriptor<Framework.MockData.Attachment>, IPromise<IProperties>> FluentProperties => p => p
9171
.Attachment(a => a
9272
//.Fields(s => s)
9373
.Name(n => n.File)
@@ -97,7 +77,7 @@ protected override void AttributeBasedSerializes()
9777
.FileField(d => d
9878
.Name(n => n.File)
9979
)
100-
.ContentLengthField((NumberPropertyDescriptor<AttachmentTest> d) => d
80+
.ContentLengthField((NumberPropertyDescriptor<Framework.MockData.Attachment> d) => d
10181
.Name(n => n.ContentLength)
10282
)
10383
.ContentTypeField(d => d
@@ -109,7 +89,7 @@ protected override void AttributeBasedSerializes()
10989
.KeywordsField(d => d
11090
.Name(n => n.Keywords)
11191
)
112-
.LanguageField((StringPropertyDescriptor<AttachmentTest> d) => d
92+
.LanguageField((StringPropertyDescriptor<Framework.MockData.Attachment> d) => d
11393
.Name(n => n.Language)
11494
.DocValues()
11595
.NotAnalyzed()

0 commit comments

Comments
 (0)