11namespace ServiceControl . Audit . Persistence . Tests ;
22
3+ using System ;
34using System . Threading ;
45using System . Threading . Tasks ;
56using NUnit . Framework ;
67using Persistence . RavenDB ;
78using Persistence . RavenDB . Indexes ;
89using Raven . Client . Documents . Indexes ;
910using Raven . Client . Documents . Operations . Indexes ;
11+ using Raven . Client . Exceptions . Documents . Indexes ;
1012
1113[ TestFixture ]
1214class IndexSetupTests : PersistenceTestFixture
@@ -55,4 +57,50 @@ public async Task Indexes_should_be_reset_on_setup()
5557 var indexStatsAfter = await configuration . DocumentStore . Maintenance . SendAsync ( new GetIndexStatisticsOperation ( index . IndexName ) ) ;
5658 Assert . That ( indexStatsAfter . SearchEngineType , Is . EqualTo ( SearchEngineType . Corax ) ) ;
5759 }
60+
61+ [ Test ]
62+ public async Task Indexes_should_not_be_reset_on_setup_when_locked_as_ignore ( )
63+ {
64+ var index = new MessagesViewIndexWithFullTextSearch { Configuration = { [ "Indexing.Static.SearchEngineType" ] = SearchEngineType . Lucene . ToString ( ) } } ;
65+
66+ await IndexCreation . CreateIndexesAsync ( [ index ] , configuration . DocumentStore ) ;
67+
68+ await configuration . DocumentStore . Maintenance . SendAsync ( new SetIndexesLockOperation ( new SetIndexesLockOperation . Parameters
69+ {
70+ IndexNames = [ index . IndexName ] ,
71+ Mode = IndexLockMode . LockedIgnore
72+ } ) ) ;
73+
74+ //TODO: find a better way
75+ await Task . Delay ( 1000 ) ;
76+
77+ var indexStatsBefore = await configuration . DocumentStore . Maintenance . SendAsync ( new GetIndexStatisticsOperation ( index . IndexName ) ) ;
78+
79+ Assert . That ( indexStatsBefore . SearchEngineType , Is . EqualTo ( SearchEngineType . Lucene ) ) ;
80+
81+
82+ await DatabaseSetup . CreateIndexes ( configuration . DocumentStore , true , CancellationToken . None ) ;
83+
84+ //TODO: find a better way
85+ await Task . Delay ( 1000 ) ;
86+
87+ var indexStatsAfter = await configuration . DocumentStore . Maintenance . SendAsync ( new GetIndexStatisticsOperation ( index . IndexName ) ) ;
88+ Assert . That ( indexStatsAfter . SearchEngineType , Is . EqualTo ( SearchEngineType . Lucene ) ) ;
89+ }
90+
91+ [ Test ]
92+ public async Task Indexes_should_not_be_reset_on_setup_when_locked_as_error ( )
93+ {
94+ var index = new MessagesViewIndexWithFullTextSearch { Configuration = { [ "Indexing.Static.SearchEngineType" ] = SearchEngineType . Lucene . ToString ( ) } } ;
95+
96+ await IndexCreation . CreateIndexesAsync ( [ index ] , configuration . DocumentStore ) ;
97+
98+ await configuration . DocumentStore . Maintenance . SendAsync ( new SetIndexesLockOperation ( new SetIndexesLockOperation . Parameters
99+ {
100+ IndexNames = [ index . IndexName ] ,
101+ Mode = IndexLockMode . LockedError
102+ } ) ) ;
103+
104+ Assert . ThrowsAsync < IndexCreationException > ( async ( ) => await DatabaseSetup . CreateIndexes ( configuration . DocumentStore , true , CancellationToken . None ) ) ;
105+ }
58106}
0 commit comments