Skip to content

Commit 39b21f9

Browse files
committed
added test for minimal reindex
1 parent dabb70f commit 39b21f9

File tree

8 files changed

+194
-9
lines changed

8 files changed

+194
-9
lines changed

src/Nest.Connection.Thrift/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[assembly: System.Runtime.InteropServices.ComVisible(false)]
1616
[assembly: System.CLSCompliant(true)]
1717
[assembly: System.Runtime.InteropServices.Guid("4d165338-2060-4641-8be6-b7aacbdee52d")]
18-
[assembly: System.Reflection.AssemblyVersion("0.11.2.0")]
19-
[assembly: System.Reflection.AssemblyFileVersion("0.11.2.0")]
18+
[assembly: System.Reflection.AssemblyVersion("0.11.3.0")]
19+
[assembly: System.Reflection.AssemblyFileVersion("0.11.3.0")]
2020

2121

src/Nest.Dsl.Factory/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
[assembly: System.Runtime.InteropServices.ComVisible(false)]
1717
[assembly: System.CLSCompliant(true)]
1818
[assembly: System.Runtime.InteropServices.Guid("665cc582-c91f-4f6c-924a-614289fa9449")]
19-
[assembly: System.Reflection.AssemblyVersion("0.11.2.0")]
20-
[assembly: System.Reflection.AssemblyFileVersion("0.11.2.0")]
19+
[assembly: System.Reflection.AssemblyVersion("0.11.3.0")]
20+
[assembly: System.Reflection.AssemblyFileVersion("0.11.3.0")]
2121

2222

src/Nest.Tests.Integration/Index/ReindexTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,27 @@ namespace Nest.Tests.Integration.Index
1111
[TestFixture]
1212
public class ReindexTests : IntegrationTests
1313
{
14+
[Test]
15+
public void ReindexMinimal()
16+
{
17+
var toIndex = ElasticsearchConfiguration.NewUniqueIndexName();
18+
var observable = this._client.Reindex<object>(r => r
19+
.FromIndex(ElasticsearchConfiguration.DefaultIndex)
20+
.ToIndex(toIndex)
21+
);
22+
var observer = new ReindexObserver<object>(
23+
onError: (e) => Assert.Fail(e.Message),
24+
completed: () =>
25+
{
26+
var originalIndexCount = this._client.Count(new[] { ElasticsearchConfiguration.DefaultIndex }, q => q.MatchAll());
27+
var newIndexCount = this._client.Count(new[] { toIndex }, q => q.MatchAll());
28+
Assert.Greater(newIndexCount.Count, 0);
29+
Assert.AreEqual(originalIndexCount.Count, newIndexCount.Count);
30+
}
31+
);
1432

33+
observable.Subscribe(observer);
34+
}
1535

1636
[Test]
1737
public void Reindex()
@@ -44,6 +64,7 @@ public void Reindex()
4464
{
4565
var originalIndexCount = this._client.Count(new[] { ElasticsearchConfiguration.DefaultIndex }, q=>q.MatchAll());
4666
var newIndexCount = this._client.Count(new[] { toIndex }, q=>q.MatchAll());
67+
Assert.Greater(newIndexCount.Count, 0);
4768
Assert.AreEqual(originalIndexCount.Count, newIndexCount.Count);
4869
}
4970
);

src/Nest.Tests.Integration/Nest.Tests.Integration.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<Compile Include="Integration\HighlightTests.cs" />
111111
<Compile Include="Integration\Query\TermQueryDynamic.cs" />
112112
<Compile Include="Mapping\NotAnalyzedTest.cs" />
113+
<Compile Include="Reproduce\Reproduce325Tests.cs" />
113114
<Compile Include="Reproduce\Reproduce308Tests.cs" />
114115
<Compile Include="Reproduce\Reproduce319Tests.cs" />
115116
<Compile Include="Reproduce\Reproduce211Tests.cs" />
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Nest.Tests.MockData;
5+
using Nest.Tests.MockData.Domain;
6+
using NUnit.Framework;
7+
using System.Diagnostics;
8+
using FluentAssertions;
9+
10+
namespace Nest.Tests.Integration.Reproduce
11+
{
12+
/// <summary>
13+
/// tests to reproduce reported errors
14+
/// </summary>
15+
[TestFixture]
16+
public class Reproduce325Tests : IntegrationTests
17+
{
18+
19+
/// <summary>
20+
/// https://github.com/Mpdreamz/NEST/issues/325
21+
/// </summary>
22+
[Test]
23+
public void FluentMappingReturnsResults()
24+
{
25+
var indexName = ElasticsearchConfiguration.NewUniqueIndexName();
26+
this._client.CreateIndex(indexName, settings => settings
27+
.Settings(s => s.Add("search.slowlog.threshold.fetch.warn", "1s"))
28+
.Analysis(x =>
29+
{
30+
var descriptor = x.Analyzers(i => i.Add("autocomplete", new CustomAnalyzer
31+
{
32+
Tokenizer = new WhitespaceTokenizer().Type,
33+
Filter = new[] { new LowercaseTokenFilter().Type, "engram" }
34+
}));
35+
36+
descriptor.TokenFilters(i => i.Add("engram", new EdgeNGramTokenFilter
37+
{
38+
MinGram = 3,
39+
MaxGram = 10
40+
}
41+
));
42+
43+
return descriptor;
44+
})
45+
.AddMapping<TechnicalProduct>(m => MapTechnicalProduct(m, indexName)));
46+
47+
}
48+
49+
50+
private static RootObjectMappingDescriptor<TechnicalProduct> MapTechnicalProduct(RootObjectMappingDescriptor<TechnicalProduct> m, string indexName)
51+
{
52+
return m
53+
.TypeName("technicalProducts")
54+
.DateDetection()
55+
.NumericDetection()
56+
.DynamicDateFormats(new[] { "dateOptionalTime", "yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z" })
57+
.IndexName(indexName)
58+
.Dynamic(false)
59+
.IdField(i => i
60+
.SetIndex("not_analyzed")
61+
.SetStored()
62+
)
63+
.Properties(o => o
64+
.String(i => i
65+
.Name(x => x.Name)
66+
.Index(FieldIndexOption.analyzed)
67+
.IndexAnalyzer("autocomplete")
68+
.SearchAnalyzer("standard")
69+
)
70+
.String(i => i
71+
.Name(x => x.Brand)
72+
.Index(FieldIndexOption.analyzed)
73+
.IndexAnalyzer("autocomplete")
74+
.SearchAnalyzer("standard")
75+
)
76+
);
77+
}
78+
79+
public class TechnicalProduct : Product
80+
{
81+
public virtual int NumberProcessorCores { get; protected set; }
82+
public virtual decimal ProcessorSpeed { get; protected set; }
83+
public virtual decimal BatteryLife { get; protected set; }
84+
public virtual int HardDriveSize { get; protected set; }
85+
public virtual decimal ScreenSize { get; protected set; }
86+
public virtual decimal Memory { get; protected set; }
87+
public virtual int HardDriveSpeed { get; protected set; }
88+
89+
90+
protected TechnicalProduct() { }
91+
92+
public TechnicalProduct(string brand, string name, string imageUrl, decimal price, int numberCores, decimal processorSpeed, decimal batteryLife, int hardDriveSize, decimal screenSize,
93+
decimal memory, int hardDriveSpeed)
94+
: base(brand, name, price, imageUrl)
95+
{
96+
NumberProcessorCores = numberCores;
97+
ProcessorSpeed = processorSpeed;
98+
BatteryLife = batteryLife;
99+
Price = price;
100+
HardDriveSize = hardDriveSize;
101+
ScreenSize = screenSize;
102+
Memory = memory;
103+
HardDriveSpeed = hardDriveSpeed;
104+
}
105+
}
106+
107+
public abstract class Product : Entity
108+
{
109+
private readonly Dictionary<string, string> _additionalAttributes;
110+
111+
public virtual string Brand { get; protected set; }
112+
public virtual decimal Price { get; protected set; }
113+
public virtual string ImageUrl { get; protected set; }
114+
public virtual string Name { get; protected set; }
115+
116+
public virtual IDictionary<string, string> AdditionalAttributes
117+
{
118+
get { return _additionalAttributes; }
119+
}
120+
121+
protected Product()
122+
{
123+
_additionalAttributes = new Dictionary<string, string>();
124+
}
125+
126+
protected Product(string brand, string name, decimal price, string imageUrl)
127+
: this()
128+
{
129+
Brand = brand;
130+
Name = name;
131+
Price = price;
132+
ImageUrl = imageUrl;
133+
}
134+
}
135+
136+
public abstract class Entity
137+
{
138+
private int? _oldHashCode;
139+
140+
public virtual int Id { get; protected set; }
141+
142+
public virtual bool Equals(Entity other)
143+
{
144+
return this == other;
145+
}
146+
147+
public static bool operator ==(Entity left, Entity right)
148+
{
149+
return Equals(left, right);
150+
}
151+
152+
public static bool operator !=(Entity left, Entity right)
153+
{
154+
return !Equals(left, right);
155+
}
156+
}
157+
}
158+
}

src/Nest/Domain/Responses/ReindexObservable.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ private void Reindex(IObserver<IReindexResponse<T>> observer)
4141
var indexSettings = this.CurrentClient.GetIndexSettings(this._reindexDescriptor._FromIndexName);
4242
var createSettings = new CreateIndexDescriptor(this.CurrentClient.Settings).InitializeUsing(indexSettings.Settings);
4343
var createIndexResponse = this.CurrentClient
44-
.CreateIndex(toIndex, (c) => this._reindexDescriptor._CreateIndexSelector(createSettings));
44+
.CreateIndex(toIndex, (c) =>
45+
{
46+
if (this._reindexDescriptor._CreateIndexSelector != null)
47+
return this._reindexDescriptor._CreateIndexSelector(createSettings);
48+
return c;
49+
});
4550
if (!createIndexResponse.IsValid)
4651
throw new ReindexException(createIndexResponse.ConnectionStatus);
4752

@@ -52,7 +57,7 @@ private void Reindex(IObserver<IReindexResponse<T>> observer)
5257
.AllTypes()
5358
.From(0)
5459
.Take(100)
55-
.Query(this._reindexDescriptor._QuerySelector)
60+
.Query(this._reindexDescriptor._QuerySelector ?? (q=>q.MatchAll()))
5661
.SearchType(SearchType.Scan)
5762
.Scroll(scroll)
5863
);

src/Nest/Domain/Responses/ReindexObserver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class ReindexObserver<T> : IObserver<IReindexResponse<T>> where T : class
88
private readonly Action<Exception> _onError;
99
private readonly Action _completed;
1010

11-
public ReindexObserver(Action<IReindexResponse<T>> onNext, Action<Exception> onError, Action completed)
11+
public ReindexObserver(Action<IReindexResponse<T>> onNext = null, Action<Exception> onError = null, Action completed = null)
1212
{
1313
this._completed = completed;
1414
this._onError = onError;

src/Nest/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[assembly: System.Runtime.InteropServices.ComVisible(false)]
1616
[assembly: System.CLSCompliant(true)]
1717
[assembly: System.Runtime.InteropServices.Guid("07E5CFA3-CF5F-4D17-874C-8D5CC6FA3E73")]
18-
[assembly: System.Reflection.AssemblyVersion("0.11.2.0")]
19-
[assembly: System.Reflection.AssemblyFileVersion("0.11.2.0")]
18+
[assembly: System.Reflection.AssemblyVersion("0.11.3.0")]
19+
[assembly: System.Reflection.AssemblyFileVersion("0.11.3.0")]
2020

2121

0 commit comments

Comments
 (0)