forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RavenDB-21084 : HandleClusterDatabaseChanged : if sharded database is…
… disabled we need to remove the ShardedDatabaseContext from ShardedDatabasesCache
- Loading branch information
Showing
2 changed files
with
88 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Threading.Tasks; | ||
using FastTests; | ||
using Raven.Client.ServerWide.Operations; | ||
using Raven.Server.Utils; | ||
using Tests.Infrastructure; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace SlowTests.Sharding.Issues; | ||
|
||
public class RavenDB_21084 : RavenTestBase | ||
{ | ||
public RavenDB_21084(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
|
||
[RavenFact(RavenTestCategory.Sharding)] | ||
public async Task DisableShardedDb_ShouldRemoveDbFromShardedDatabasesCache() | ||
{ | ||
using (var store = Sharding.GetDocumentStore()) | ||
{ | ||
var dbLandlord = Server.ServerStore.DatabasesLandlord; | ||
|
||
Assert.True(dbLandlord.ShardedDatabasesCache.TryGetValue(store.Database, out _)); | ||
|
||
var shardingConfig = await Sharding.GetShardingConfigurationAsync(store); | ||
foreach (var shardNumber in shardingConfig.Shards.Keys) | ||
{ | ||
var shard = ShardHelper.ToShardName(store.Database, shardNumber); | ||
Assert.True(dbLandlord.DatabasesCache.TryGetValue(shard, out _)); | ||
} | ||
|
||
var operationResult = await store.Maintenance.Server.SendAsync(new ToggleDatabasesStateOperation(store.Database, disable: true)); | ||
Assert.True(operationResult.Success); | ||
Assert.True(operationResult.Disabled); | ||
|
||
// should remove document databases from DatabasesCache | ||
foreach (var shardNumber in shardingConfig.Shards.Keys) | ||
{ | ||
var shard = ShardHelper.ToShardName(store.Database, shardNumber); | ||
Assert.False(dbLandlord.DatabasesCache.TryGetValue(shard, out _)); | ||
} | ||
|
||
// should remove sharded database context from ShardedDatabasesCache | ||
Assert.False(dbLandlord.ShardedDatabasesCache.TryGetValue(store.Database, out _)); | ||
|
||
await store.Maintenance.Server.SendAsync(new ToggleDatabasesStateOperation(store.Database, disable: false)); | ||
} | ||
} | ||
|
||
} |