mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Merge pull request #16593 from peppy/realm-clean-up
Clean up realm naming
This commit is contained in:
@ -38,10 +38,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestDetachBeatmapSet()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using (var importer = new BeatmapModelManager(realmFactory, storage))
|
||||
using (new RulesetStore(realmFactory, storage))
|
||||
using (var importer = new BeatmapModelManager(realm, storage))
|
||||
using (new RulesetStore(realm, storage))
|
||||
{
|
||||
ILive<BeatmapSetInfo>? beatmapSet;
|
||||
|
||||
@ -82,10 +82,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestUpdateDetachedBeatmapSet()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using (var importer = new BeatmapModelManager(realmFactory, storage))
|
||||
using (new RulesetStore(realmFactory, storage))
|
||||
using (var importer = new BeatmapModelManager(realm, storage))
|
||||
using (new RulesetStore(realm, storage))
|
||||
{
|
||||
ILive<BeatmapSetInfo>? beatmapSet;
|
||||
|
||||
@ -139,53 +139,53 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportBeatmapThenCleanup()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using (var importer = new BeatmapModelManager(realmFactory, storage))
|
||||
using (new RulesetStore(realmFactory, storage))
|
||||
using (var importer = new BeatmapModelManager(realm, storage))
|
||||
using (new RulesetStore(realm, storage))
|
||||
{
|
||||
ILive<BeatmapSetInfo>? imported;
|
||||
|
||||
using (var reader = new ZipArchiveReader(TestResources.GetTestBeatmapStream()))
|
||||
imported = await importer.Import(reader);
|
||||
|
||||
Assert.AreEqual(1, realmFactory.Context.All<BeatmapSetInfo>().Count());
|
||||
Assert.AreEqual(1, realm.Realm.All<BeatmapSetInfo>().Count());
|
||||
|
||||
Assert.NotNull(imported);
|
||||
Debug.Assert(imported != null);
|
||||
|
||||
imported.PerformWrite(s => s.DeletePending = true);
|
||||
|
||||
Assert.AreEqual(1, realmFactory.Context.All<BeatmapSetInfo>().Count(s => s.DeletePending));
|
||||
Assert.AreEqual(1, realm.Realm.All<BeatmapSetInfo>().Count(s => s.DeletePending));
|
||||
}
|
||||
});
|
||||
|
||||
Logger.Log("Running with no work to purge pending deletions");
|
||||
|
||||
RunTestWithRealm((realmFactory, _) => { Assert.AreEqual(0, realmFactory.Context.All<BeatmapSetInfo>().Count()); });
|
||||
RunTestWithRealm((realm, _) => { Assert.AreEqual(0, realm.Realm.All<BeatmapSetInfo>().Count()); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestImportWhenClosed()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
await LoadOszIntoStore(importer, realm.Realm);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAccessFileAfterImport()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
var imported = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
var beatmap = imported.Beatmaps.First();
|
||||
var file = beatmap.File;
|
||||
@ -198,24 +198,24 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportThenDelete()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
var imported = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
deleteBeatmapSet(imported, realmFactory.Context);
|
||||
deleteBeatmapSet(imported, realm.Realm);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestImportThenDeleteFromStream()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
string? tempPath = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -224,7 +224,7 @@ namespace osu.Game.Tests.Database
|
||||
using (var stream = File.OpenRead(tempPath))
|
||||
{
|
||||
importedSet = await importer.Import(new ImportTask(stream, Path.GetFileName(tempPath)));
|
||||
EnsureLoaded(realmFactory.Context);
|
||||
EnsureLoaded(realm.Realm);
|
||||
}
|
||||
|
||||
Assert.NotNull(importedSet);
|
||||
@ -233,39 +233,39 @@ namespace osu.Game.Tests.Database
|
||||
Assert.IsTrue(File.Exists(tempPath), "Stream source file somehow went missing");
|
||||
File.Delete(tempPath);
|
||||
|
||||
var imported = realmFactory.Context.All<BeatmapSetInfo>().First(beatmapSet => beatmapSet.ID == importedSet.ID);
|
||||
var imported = realm.Realm.All<BeatmapSetInfo>().First(beatmapSet => beatmapSet.ID == importedSet.ID);
|
||||
|
||||
deleteBeatmapSet(imported, realmFactory.Context);
|
||||
deleteBeatmapSet(imported, realm.Realm);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestImportThenImport()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
var imported = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var importedSecondTime = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||
var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
// check the newly "imported" beatmap is actually just the restored previous import. since it matches hash.
|
||||
Assert.IsTrue(imported.ID == importedSecondTime.ID);
|
||||
Assert.IsTrue(imported.Beatmaps.First().ID == importedSecondTime.Beatmaps.First().ID);
|
||||
|
||||
checkBeatmapSetCount(realmFactory.Context, 1);
|
||||
checkSingleReferencedFileCount(realmFactory.Context, 18);
|
||||
checkBeatmapSetCount(realm.Realm, 1);
|
||||
checkSingleReferencedFileCount(realm.Realm, 18);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestImportThenImportWithReZip()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
string? temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -274,7 +274,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
try
|
||||
{
|
||||
var imported = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
string hashBefore = hashFile(temp);
|
||||
|
||||
@ -292,7 +292,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
var importedSecondTime = await importer.Import(new ImportTask(temp));
|
||||
|
||||
EnsureLoaded(realmFactory.Context);
|
||||
EnsureLoaded(realm.Realm);
|
||||
|
||||
Assert.NotNull(importedSecondTime);
|
||||
Debug.Assert(importedSecondTime != null);
|
||||
@ -311,10 +311,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportThenImportWithChangedHashedFile()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
string? temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -323,9 +323,9 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
try
|
||||
{
|
||||
var imported = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
await createScoreForBeatmap(realmFactory.Context, imported.Beatmaps.First());
|
||||
await createScoreForBeatmap(realm.Realm, imported.Beatmaps.First());
|
||||
|
||||
using (var zip = ZipArchive.Open(temp))
|
||||
zip.WriteToDirectory(extractedFolder);
|
||||
@ -343,7 +343,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
var importedSecondTime = await importer.Import(new ImportTask(temp));
|
||||
|
||||
EnsureLoaded(realmFactory.Context);
|
||||
EnsureLoaded(realm.Realm);
|
||||
|
||||
// check the newly "imported" beatmap is not the original.
|
||||
Assert.NotNull(importedSecondTime);
|
||||
@ -363,10 +363,10 @@ namespace osu.Game.Tests.Database
|
||||
[Ignore("intentionally broken by import optimisations")]
|
||||
public void TestImportThenImportWithChangedFile()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
string? temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -375,7 +375,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
try
|
||||
{
|
||||
var imported = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
using (var zip = ZipArchive.Open(temp))
|
||||
zip.WriteToDirectory(extractedFolder);
|
||||
@ -392,7 +392,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
var importedSecondTime = await importer.Import(new ImportTask(temp));
|
||||
|
||||
EnsureLoaded(realmFactory.Context);
|
||||
EnsureLoaded(realm.Realm);
|
||||
|
||||
Assert.NotNull(importedSecondTime);
|
||||
Debug.Assert(importedSecondTime != null);
|
||||
@ -411,10 +411,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportThenImportWithDifferentFilename()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
string? temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -423,7 +423,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
try
|
||||
{
|
||||
var imported = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
using (var zip = ZipArchive.Open(temp))
|
||||
zip.WriteToDirectory(extractedFolder);
|
||||
@ -440,7 +440,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
var importedSecondTime = await importer.Import(new ImportTask(temp));
|
||||
|
||||
EnsureLoaded(realmFactory.Context);
|
||||
EnsureLoaded(realm.Realm);
|
||||
|
||||
Assert.NotNull(importedSecondTime);
|
||||
Debug.Assert(importedSecondTime != null);
|
||||
@ -460,12 +460,12 @@ namespace osu.Game.Tests.Database
|
||||
[Ignore("intentionally broken by import optimisations")]
|
||||
public void TestImportCorruptThenImport()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
var imported = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
var firstFile = imported.Files.First();
|
||||
|
||||
@ -476,7 +476,7 @@ namespace osu.Game.Tests.Database
|
||||
using (var stream = storage.GetStream(firstFile.File.GetStoragePath(), FileAccess.Write, FileMode.Create))
|
||||
stream.WriteByte(0);
|
||||
|
||||
var importedSecondTime = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
using (var stream = storage.GetStream(firstFile.File.GetStoragePath()))
|
||||
Assert.AreEqual(stream.Length, originalLength, "Corruption was not fixed on second import");
|
||||
@ -485,18 +485,18 @@ namespace osu.Game.Tests.Database
|
||||
Assert.IsTrue(imported.ID == importedSecondTime.ID);
|
||||
Assert.IsTrue(imported.Beatmaps.First().ID == importedSecondTime.Beatmaps.First().ID);
|
||||
|
||||
checkBeatmapSetCount(realmFactory.Context, 1);
|
||||
checkSingleReferencedFileCount(realmFactory.Context, 18);
|
||||
checkBeatmapSetCount(realm.Realm, 1);
|
||||
checkSingleReferencedFileCount(realm.Realm, 18);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestModelCreationFailureDoesntReturn()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
var progressNotification = new ImportProgressNotification();
|
||||
|
||||
@ -510,8 +510,8 @@ namespace osu.Game.Tests.Database
|
||||
new ImportTask(zipStream, string.Empty)
|
||||
);
|
||||
|
||||
checkBeatmapSetCount(realmFactory.Context, 0);
|
||||
checkBeatmapCount(realmFactory.Context, 0);
|
||||
checkBeatmapSetCount(realm.Realm, 0);
|
||||
checkBeatmapCount(realm.Realm, 0);
|
||||
|
||||
Assert.IsEmpty(imported);
|
||||
Assert.AreEqual(ProgressNotificationState.Cancelled, progressNotification.State);
|
||||
@ -521,7 +521,7 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestRollbackOnFailure()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
int loggedExceptionCount = 0;
|
||||
|
||||
@ -531,16 +531,16 @@ namespace osu.Game.Tests.Database
|
||||
Interlocked.Increment(ref loggedExceptionCount);
|
||||
};
|
||||
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
var imported = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
realmFactory.Context.Write(() => imported.Hash += "-changed");
|
||||
realm.Realm.Write(() => imported.Hash += "-changed");
|
||||
|
||||
checkBeatmapSetCount(realmFactory.Context, 1);
|
||||
checkBeatmapCount(realmFactory.Context, 12);
|
||||
checkSingleReferencedFileCount(realmFactory.Context, 18);
|
||||
checkBeatmapSetCount(realm.Realm, 1);
|
||||
checkBeatmapCount(realm.Realm, 12);
|
||||
checkSingleReferencedFileCount(realm.Realm, 18);
|
||||
|
||||
string? brokenTempFilename = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -565,10 +565,10 @@ namespace osu.Game.Tests.Database
|
||||
{
|
||||
}
|
||||
|
||||
checkBeatmapSetCount(realmFactory.Context, 1);
|
||||
checkBeatmapCount(realmFactory.Context, 12);
|
||||
checkBeatmapSetCount(realm.Realm, 1);
|
||||
checkBeatmapCount(realm.Realm, 12);
|
||||
|
||||
checkSingleReferencedFileCount(realmFactory.Context, 18);
|
||||
checkSingleReferencedFileCount(realm.Realm, 18);
|
||||
|
||||
Assert.AreEqual(1, loggedExceptionCount);
|
||||
|
||||
@ -579,18 +579,18 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportThenDeleteThenImportOptimisedPath()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
var imported = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
deleteBeatmapSet(imported, realmFactory.Context);
|
||||
deleteBeatmapSet(imported, realm.Realm);
|
||||
|
||||
Assert.IsTrue(imported.DeletePending);
|
||||
|
||||
var importedSecondTime = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
// check the newly "imported" beatmap is actually just the restored previous import. since it matches hash.
|
||||
Assert.IsTrue(imported.ID == importedSecondTime.ID);
|
||||
@ -635,18 +635,18 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportThenDeleteThenImportNonOptimisedPath()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new NonOptimisedBeatmapImporter(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new NonOptimisedBeatmapImporter(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
var imported = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
deleteBeatmapSet(imported, realmFactory.Context);
|
||||
deleteBeatmapSet(imported, realm.Realm);
|
||||
|
||||
Assert.IsTrue(imported.DeletePending);
|
||||
|
||||
var importedSecondTime = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
// check the newly "imported" beatmap is actually just the restored previous import. since it matches hash.
|
||||
Assert.IsTrue(imported.ID == importedSecondTime.ID);
|
||||
@ -659,22 +659,22 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportThenDeleteThenImportWithOnlineIDsMissing()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
var imported = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var imported = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
realmFactory.Context.Write(() =>
|
||||
realm.Realm.Write(() =>
|
||||
{
|
||||
foreach (var b in imported.Beatmaps)
|
||||
b.OnlineID = -1;
|
||||
});
|
||||
|
||||
deleteBeatmapSet(imported, realmFactory.Context);
|
||||
deleteBeatmapSet(imported, realm.Realm);
|
||||
|
||||
var importedSecondTime = await LoadOszIntoStore(importer, realmFactory.Context);
|
||||
var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm);
|
||||
|
||||
// check the newly "imported" beatmap has been reimported due to mismatch (even though hashes matched)
|
||||
Assert.IsTrue(imported.ID != importedSecondTime.ID);
|
||||
@ -685,10 +685,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportWithDuplicateBeatmapIDs()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
var metadata = new BeatmapMetadata
|
||||
{
|
||||
@ -699,7 +699,7 @@ namespace osu.Game.Tests.Database
|
||||
}
|
||||
};
|
||||
|
||||
var ruleset = realmFactory.Context.All<RulesetInfo>().First();
|
||||
var ruleset = realm.Realm.All<RulesetInfo>().First();
|
||||
|
||||
var toImport = new BeatmapSetInfo
|
||||
{
|
||||
@ -731,15 +731,15 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportWhenFileOpen()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
string? temp = TestResources.GetTestBeatmapForImport();
|
||||
using (File.OpenRead(temp))
|
||||
await importer.Import(temp);
|
||||
EnsureLoaded(realmFactory.Context);
|
||||
EnsureLoaded(realm.Realm);
|
||||
File.Delete(temp);
|
||||
Assert.IsFalse(File.Exists(temp), "We likely held a read lock on the file when we shouldn't");
|
||||
});
|
||||
@ -748,10 +748,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportWithDuplicateHashes()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
string? temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -772,7 +772,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
await importer.Import(temp);
|
||||
|
||||
EnsureLoaded(realmFactory.Context);
|
||||
EnsureLoaded(realm.Realm);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -784,10 +784,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportNestedStructure()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
string? temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -812,7 +812,7 @@ namespace osu.Game.Tests.Database
|
||||
Assert.NotNull(imported);
|
||||
Debug.Assert(imported != null);
|
||||
|
||||
EnsureLoaded(realmFactory.Context);
|
||||
EnsureLoaded(realm.Realm);
|
||||
|
||||
Assert.IsFalse(imported.PerformRead(s => s.Files.Any(f => f.Filename.Contains("subfolder"))), "Files contain common subfolder");
|
||||
}
|
||||
@ -826,10 +826,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportWithIgnoredDirectoryInArchive()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
string? temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
@ -862,7 +862,7 @@ namespace osu.Game.Tests.Database
|
||||
Assert.NotNull(imported);
|
||||
Debug.Assert(imported != null);
|
||||
|
||||
EnsureLoaded(realmFactory.Context);
|
||||
EnsureLoaded(realm.Realm);
|
||||
|
||||
Assert.IsFalse(imported.PerformRead(s => s.Files.Any(f => f.Filename.Contains("__MACOSX"))), "Files contain resource fork folder, which should be ignored");
|
||||
Assert.IsFalse(imported.PerformRead(s => s.Files.Any(f => f.Filename.Contains("actual_data"))), "Files contain common subfolder");
|
||||
@ -877,22 +877,22 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestUpdateBeatmapInfo()
|
||||
{
|
||||
RunTestWithRealmAsync(async (realmFactory, storage) =>
|
||||
RunTestWithRealmAsync(async (realm, storage) =>
|
||||
{
|
||||
using var importer = new BeatmapModelManager(realmFactory, storage);
|
||||
using var store = new RulesetStore(realmFactory, storage);
|
||||
using var importer = new BeatmapModelManager(realm, storage);
|
||||
using var store = new RulesetStore(realm, storage);
|
||||
|
||||
string? temp = TestResources.GetTestBeatmapForImport();
|
||||
await importer.Import(temp);
|
||||
|
||||
// Update via the beatmap, not the beatmap info, to ensure correct linking
|
||||
BeatmapSetInfo setToUpdate = realmFactory.Context.All<BeatmapSetInfo>().First();
|
||||
BeatmapSetInfo setToUpdate = realm.Realm.All<BeatmapSetInfo>().First();
|
||||
|
||||
var beatmapToUpdate = setToUpdate.Beatmaps.First();
|
||||
|
||||
realmFactory.Context.Write(() => beatmapToUpdate.DifficultyName = "updated");
|
||||
realm.Realm.Write(() => beatmapToUpdate.DifficultyName = "updated");
|
||||
|
||||
BeatmapInfo updatedInfo = realmFactory.Context.All<BeatmapInfo>().First(b => b.ID == beatmapToUpdate.ID);
|
||||
BeatmapInfo updatedInfo = realm.Realm.All<BeatmapInfo>().First(b => b.ID == beatmapToUpdate.ID);
|
||||
Assert.That(updatedInfo.DifficultyName, Is.EqualTo("updated"));
|
||||
});
|
||||
}
|
||||
@ -1036,8 +1036,8 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
public class NonOptimisedBeatmapImporter : BeatmapImporter
|
||||
{
|
||||
public NonOptimisedBeatmapImporter(RealmContextFactory realmFactory, Storage storage)
|
||||
: base(realmFactory, storage)
|
||||
public NonOptimisedBeatmapImporter(RealmAccess realm, Storage storage)
|
||||
: base(realm, storage)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -19,10 +19,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportFile()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, storage) =>
|
||||
RunTestWithRealm((realmAccess, storage) =>
|
||||
{
|
||||
var realm = realmFactory.Context;
|
||||
var files = new RealmFileStore(realmFactory, storage);
|
||||
var realm = realmAccess.Realm;
|
||||
var files = new RealmFileStore(realmAccess, storage);
|
||||
|
||||
var testData = new MemoryStream(new byte[] { 0, 1, 2, 3 });
|
||||
|
||||
@ -36,10 +36,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestImportSameFileTwice()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, storage) =>
|
||||
RunTestWithRealm((realmAccess, storage) =>
|
||||
{
|
||||
var realm = realmFactory.Context;
|
||||
var files = new RealmFileStore(realmFactory, storage);
|
||||
var realm = realmAccess.Realm;
|
||||
var files = new RealmFileStore(realmAccess, storage);
|
||||
|
||||
var testData = new MemoryStream(new byte[] { 0, 1, 2, 3 });
|
||||
|
||||
@ -53,10 +53,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestDontPurgeReferenced()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, storage) =>
|
||||
RunTestWithRealm((realmAccess, storage) =>
|
||||
{
|
||||
var realm = realmFactory.Context;
|
||||
var files = new RealmFileStore(realmFactory, storage);
|
||||
var realm = realmAccess.Realm;
|
||||
var files = new RealmFileStore(realmAccess, storage);
|
||||
|
||||
var file = realm.Write(() => files.Add(new MemoryStream(new byte[] { 0, 1, 2, 3 }), realm));
|
||||
|
||||
@ -92,10 +92,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestPurgeUnreferenced()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, storage) =>
|
||||
RunTestWithRealm((realmAccess, storage) =>
|
||||
{
|
||||
var realm = realmFactory.Context;
|
||||
var files = new RealmFileStore(realmFactory, storage);
|
||||
var realm = realmAccess.Realm;
|
||||
var files = new RealmFileStore(realmAccess, storage);
|
||||
|
||||
var file = realm.Write(() => files.Add(new MemoryStream(new byte[] { 0, 1, 2, 3 }), realm));
|
||||
|
||||
|
@ -21,15 +21,15 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestConstructRealm()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) => { realmFactory.Run(realm => realm.Refresh()); });
|
||||
RunTestWithRealm((realm, _) => { realm.Run(r => r.Refresh()); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBlockOperations()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
using (realmFactory.BlockAllOperations())
|
||||
using (realm.BlockAllOperations())
|
||||
{
|
||||
}
|
||||
});
|
||||
@ -42,22 +42,22 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestNestedContextCreationWithSubscription()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
bool callbackRan = false;
|
||||
|
||||
realmFactory.RegisterCustomSubscription(realm =>
|
||||
realm.RegisterCustomSubscription(r =>
|
||||
{
|
||||
var subscription = realm.All<BeatmapInfo>().QueryAsyncWithNotifications((sender, changes, error) =>
|
||||
var subscription = r.All<BeatmapInfo>().QueryAsyncWithNotifications((sender, changes, error) =>
|
||||
{
|
||||
realmFactory.Run(_ =>
|
||||
realm.Run(_ =>
|
||||
{
|
||||
callbackRan = true;
|
||||
});
|
||||
});
|
||||
|
||||
// Force the callback above to run.
|
||||
realmFactory.Run(r => r.Refresh());
|
||||
realm.Run(rr => rr.Refresh());
|
||||
|
||||
subscription?.Dispose();
|
||||
return null;
|
||||
@ -70,14 +70,14 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestBlockOperationsWithContention()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
ManualResetEventSlim stopThreadedUsage = new ManualResetEventSlim();
|
||||
ManualResetEventSlim hasThreadedUsage = new ManualResetEventSlim();
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
realmFactory.Run(_ =>
|
||||
realm.Run(_ =>
|
||||
{
|
||||
hasThreadedUsage.Set();
|
||||
|
||||
@ -89,7 +89,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
Assert.Throws<TimeoutException>(() =>
|
||||
{
|
||||
using (realmFactory.BlockAllOperations())
|
||||
using (realm.BlockAllOperations())
|
||||
{
|
||||
}
|
||||
});
|
||||
|
@ -21,11 +21,11 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestLiveEquality()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
ILive<BeatmapInfo> beatmap = realmFactory.Run(realm => realm.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata()))).ToLive(realmFactory));
|
||||
ILive<BeatmapInfo> beatmap = realm.Run(r => r.Write(_ => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata()))).ToLive(realm));
|
||||
|
||||
ILive<BeatmapInfo> beatmap2 = realmFactory.Run(realm => realm.All<BeatmapInfo>().First().ToLive(realmFactory));
|
||||
ILive<BeatmapInfo> beatmap2 = realm.Run(r => r.All<BeatmapInfo>().First().ToLive(realm));
|
||||
|
||||
Assert.AreEqual(beatmap, beatmap2);
|
||||
});
|
||||
@ -34,20 +34,20 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestAccessAfterStorageMigrate()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, storage) =>
|
||||
RunTestWithRealm((realm, storage) =>
|
||||
{
|
||||
var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
|
||||
|
||||
ILive<BeatmapInfo>? liveBeatmap = null;
|
||||
|
||||
realmFactory.Run(realm =>
|
||||
realm.Run(r =>
|
||||
{
|
||||
realm.Write(r => r.Add(beatmap));
|
||||
r.Write(_ => r.Add(beatmap));
|
||||
|
||||
liveBeatmap = beatmap.ToLive(realmFactory);
|
||||
liveBeatmap = beatmap.ToLive(realm);
|
||||
});
|
||||
|
||||
using (realmFactory.BlockAllOperations())
|
||||
using (realm.BlockAllOperations())
|
||||
{
|
||||
// recycle realm before migrating
|
||||
}
|
||||
@ -66,13 +66,13 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestAccessAfterAttach()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
|
||||
|
||||
var liveBeatmap = beatmap.ToLive(realmFactory);
|
||||
var liveBeatmap = beatmap.ToLive(realm);
|
||||
|
||||
realmFactory.Run(realm => realm.Write(r => r.Add(beatmap)));
|
||||
realm.Run(r => r.Write(_ => r.Add(beatmap)));
|
||||
|
||||
Assert.IsFalse(liveBeatmap.PerformRead(l => l.Hidden));
|
||||
});
|
||||
@ -98,16 +98,16 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestScopedReadWithoutContext()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
ILive<BeatmapInfo>? liveBeatmap = null;
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
realmFactory.Run(threadContext =>
|
||||
realm.Run(threadContext =>
|
||||
{
|
||||
var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata())));
|
||||
|
||||
liveBeatmap = beatmap.ToLive(realmFactory);
|
||||
liveBeatmap = beatmap.ToLive(realm);
|
||||
});
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).WaitSafely();
|
||||
|
||||
@ -127,16 +127,16 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestScopedWriteWithoutContext()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
ILive<BeatmapInfo>? liveBeatmap = null;
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
realmFactory.Run(threadContext =>
|
||||
realm.Run(threadContext =>
|
||||
{
|
||||
var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata())));
|
||||
|
||||
liveBeatmap = beatmap.ToLive(realmFactory);
|
||||
liveBeatmap = beatmap.ToLive(realm);
|
||||
});
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).WaitSafely();
|
||||
|
||||
@ -153,10 +153,10 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestValueAccessNonManaged()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
var beatmap = new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata());
|
||||
var liveBeatmap = beatmap.ToLive(realmFactory);
|
||||
var liveBeatmap = beatmap.ToLive(realm);
|
||||
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
@ -168,17 +168,17 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestValueAccessWithOpenContextFails()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
ILive<BeatmapInfo>? liveBeatmap = null;
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
realmFactory.Run(threadContext =>
|
||||
realm.Run(threadContext =>
|
||||
{
|
||||
var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata())));
|
||||
|
||||
liveBeatmap = beatmap.ToLive(realmFactory);
|
||||
liveBeatmap = beatmap.ToLive(realm);
|
||||
});
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).WaitSafely();
|
||||
|
||||
@ -193,7 +193,7 @@ namespace osu.Game.Tests.Database
|
||||
});
|
||||
|
||||
// Can't be used, even from within a valid context.
|
||||
realmFactory.Run(threadContext =>
|
||||
realm.Run(threadContext =>
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
{
|
||||
@ -207,16 +207,16 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestValueAccessWithoutOpenContextFails()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
ILive<BeatmapInfo>? liveBeatmap = null;
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
realmFactory.Run(threadContext =>
|
||||
realm.Run(threadContext =>
|
||||
{
|
||||
var beatmap = threadContext.Write(r => r.Add(new BeatmapInfo(CreateRuleset(), new BeatmapDifficulty(), new BeatmapMetadata())));
|
||||
|
||||
liveBeatmap = beatmap.ToLive(realmFactory);
|
||||
liveBeatmap = beatmap.ToLive(realm);
|
||||
});
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).WaitSafely();
|
||||
|
||||
@ -235,18 +235,18 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestLiveAssumptions()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
int changesTriggered = 0;
|
||||
|
||||
realmFactory.RegisterCustomSubscription(outerRealm =>
|
||||
realm.RegisterCustomSubscription(outerRealm =>
|
||||
{
|
||||
outerRealm.All<BeatmapInfo>().QueryAsyncWithNotifications(gotChange);
|
||||
ILive<BeatmapInfo>? liveBeatmap = null;
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
realmFactory.Run(innerRealm =>
|
||||
realm.Run(innerRealm =>
|
||||
{
|
||||
var ruleset = CreateRuleset();
|
||||
var beatmap = innerRealm.Write(r => r.Add(new BeatmapInfo(ruleset, new BeatmapDifficulty(), new BeatmapMetadata())));
|
||||
@ -255,7 +255,7 @@ namespace osu.Game.Tests.Database
|
||||
// not just a refresh from the resolved Live.
|
||||
innerRealm.Write(r => r.Add(new BeatmapInfo(ruleset, new BeatmapDifficulty(), new BeatmapMetadata())));
|
||||
|
||||
liveBeatmap = beatmap.ToLive(realmFactory);
|
||||
liveBeatmap = beatmap.ToLive(realm);
|
||||
});
|
||||
}, TaskCreationOptions.LongRunning | TaskCreationOptions.HideScheduler).WaitSafely();
|
||||
|
||||
|
@ -24,11 +24,11 @@ namespace osu.Game.Tests.Database
|
||||
IEnumerable<BeatmapSetInfo>? resolvedItems = null;
|
||||
ChangeSet? lastChanges = null;
|
||||
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
realmFactory.Write(realm => realm.Add(TestResources.CreateTestBeatmapSetInfo()));
|
||||
realm.Write(r => r.Add(TestResources.CreateTestBeatmapSetInfo()));
|
||||
|
||||
var registration = realmFactory.RegisterForNotifications(realm => realm.All<BeatmapSetInfo>(), onChanged);
|
||||
var registration = realm.RegisterForNotifications(r => r.All<BeatmapSetInfo>(), onChanged);
|
||||
|
||||
testEventsArriving(true);
|
||||
|
||||
@ -37,10 +37,10 @@ namespace osu.Game.Tests.Database
|
||||
resolvedItems = null;
|
||||
lastChanges = null;
|
||||
|
||||
using (realmFactory.BlockAllOperations())
|
||||
using (realm.BlockAllOperations())
|
||||
Assert.That(resolvedItems, Is.Empty);
|
||||
|
||||
realmFactory.Write(realm => realm.Add(TestResources.CreateTestBeatmapSetInfo()));
|
||||
realm.Write(r => r.Add(TestResources.CreateTestBeatmapSetInfo()));
|
||||
|
||||
testEventsArriving(true);
|
||||
|
||||
@ -50,34 +50,34 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
registration.Dispose();
|
||||
|
||||
realmFactory.Write(realm => realm.Add(TestResources.CreateTestBeatmapSetInfo()));
|
||||
realm.Write(r => r.Add(TestResources.CreateTestBeatmapSetInfo()));
|
||||
|
||||
testEventsArriving(false);
|
||||
|
||||
// And make sure even after another context loss we don't get firings.
|
||||
using (realmFactory.BlockAllOperations())
|
||||
using (realm.BlockAllOperations())
|
||||
Assert.That(resolvedItems, Is.Null);
|
||||
|
||||
realmFactory.Write(realm => realm.Add(TestResources.CreateTestBeatmapSetInfo()));
|
||||
realm.Write(r => r.Add(TestResources.CreateTestBeatmapSetInfo()));
|
||||
|
||||
testEventsArriving(false);
|
||||
|
||||
void testEventsArriving(bool shouldArrive)
|
||||
{
|
||||
realmFactory.Run(realm => realm.Refresh());
|
||||
realm.Run(r => r.Refresh());
|
||||
|
||||
if (shouldArrive)
|
||||
Assert.That(resolvedItems, Has.One.Items);
|
||||
else
|
||||
Assert.That(resolvedItems, Is.Null);
|
||||
|
||||
realmFactory.Write(realm =>
|
||||
realm.Write(r =>
|
||||
{
|
||||
realm.RemoveAll<BeatmapSetInfo>();
|
||||
realm.RemoveAll<RulesetInfo>();
|
||||
r.RemoveAll<BeatmapSetInfo>();
|
||||
r.RemoveAll<RulesetInfo>();
|
||||
});
|
||||
|
||||
realmFactory.Run(realm => realm.Refresh());
|
||||
realm.Run(r => r.Refresh());
|
||||
|
||||
if (shouldArrive)
|
||||
Assert.That(lastChanges?.DeletedIndices, Has.One.Items);
|
||||
@ -98,39 +98,39 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestCustomRegisterWithContextLoss()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, _) =>
|
||||
RunTestWithRealm((realm, _) =>
|
||||
{
|
||||
BeatmapSetInfo? beatmapSetInfo = null;
|
||||
|
||||
realmFactory.Write(realm => realm.Add(TestResources.CreateTestBeatmapSetInfo()));
|
||||
realm.Write(r => r.Add(TestResources.CreateTestBeatmapSetInfo()));
|
||||
|
||||
var subscription = realmFactory.RegisterCustomSubscription(realm =>
|
||||
var subscription = realm.RegisterCustomSubscription(r =>
|
||||
{
|
||||
beatmapSetInfo = realm.All<BeatmapSetInfo>().First();
|
||||
beatmapSetInfo = r.All<BeatmapSetInfo>().First();
|
||||
|
||||
return new InvokeOnDisposal(() => beatmapSetInfo = null);
|
||||
});
|
||||
|
||||
Assert.That(beatmapSetInfo, Is.Not.Null);
|
||||
|
||||
using (realmFactory.BlockAllOperations())
|
||||
using (realm.BlockAllOperations())
|
||||
{
|
||||
// custom disposal action fired when context lost.
|
||||
Assert.That(beatmapSetInfo, Is.Null);
|
||||
}
|
||||
|
||||
// re-registration after context restore.
|
||||
realmFactory.Run(realm => realm.Refresh());
|
||||
realm.Run(r => r.Refresh());
|
||||
Assert.That(beatmapSetInfo, Is.Not.Null);
|
||||
|
||||
subscription.Dispose();
|
||||
|
||||
Assert.That(beatmapSetInfo, Is.Null);
|
||||
|
||||
using (realmFactory.BlockAllOperations())
|
||||
using (realm.BlockAllOperations())
|
||||
Assert.That(beatmapSetInfo, Is.Null);
|
||||
|
||||
realmFactory.Run(realm => realm.Refresh());
|
||||
realm.Run(r => r.Refresh());
|
||||
Assert.That(beatmapSetInfo, Is.Null);
|
||||
});
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace osu.Game.Tests.Database
|
||||
storage.DeleteDirectory(string.Empty);
|
||||
}
|
||||
|
||||
protected void RunTestWithRealm(Action<RealmContextFactory, OsuStorage> testAction, [CallerMemberName] string caller = "")
|
||||
protected void RunTestWithRealm(Action<RealmAccess, OsuStorage> testAction, [CallerMemberName] string caller = "")
|
||||
{
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(callingMethodName: caller))
|
||||
{
|
||||
@ -39,22 +39,22 @@ namespace osu.Game.Tests.Database
|
||||
// ReSharper disable once AccessToDisposedClosure
|
||||
var testStorage = new OsuStorage(host, storage.GetStorageForDirectory(caller));
|
||||
|
||||
using (var realmFactory = new RealmContextFactory(testStorage, "client"))
|
||||
using (var realm = new RealmAccess(testStorage, "client"))
|
||||
{
|
||||
Logger.Log($"Running test using realm file {testStorage.GetFullPath(realmFactory.Filename)}");
|
||||
testAction(realmFactory, testStorage);
|
||||
Logger.Log($"Running test using realm file {testStorage.GetFullPath(realm.Filename)}");
|
||||
testAction(realm, testStorage);
|
||||
|
||||
realmFactory.Dispose();
|
||||
realm.Dispose();
|
||||
|
||||
Logger.Log($"Final database size: {getFileSize(testStorage, realmFactory)}");
|
||||
realmFactory.Compact();
|
||||
Logger.Log($"Final database size after compact: {getFileSize(testStorage, realmFactory)}");
|
||||
Logger.Log($"Final database size: {getFileSize(testStorage, realm)}");
|
||||
realm.Compact();
|
||||
Logger.Log($"Final database size after compact: {getFileSize(testStorage, realm)}");
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
protected void RunTestWithRealmAsync(Func<RealmContextFactory, Storage, Task> testAction, [CallerMemberName] string caller = "")
|
||||
protected void RunTestWithRealmAsync(Func<RealmAccess, Storage, Task> testAction, [CallerMemberName] string caller = "")
|
||||
{
|
||||
using (HeadlessGameHost host = new CleanRunHeadlessGameHost(callingMethodName: caller))
|
||||
{
|
||||
@ -62,15 +62,15 @@ namespace osu.Game.Tests.Database
|
||||
{
|
||||
var testStorage = storage.GetStorageForDirectory(caller);
|
||||
|
||||
using (var realmFactory = new RealmContextFactory(testStorage, "client"))
|
||||
using (var realm = new RealmAccess(testStorage, "client"))
|
||||
{
|
||||
Logger.Log($"Running test using realm file {testStorage.GetFullPath(realmFactory.Filename)}");
|
||||
await testAction(realmFactory, testStorage);
|
||||
Logger.Log($"Running test using realm file {testStorage.GetFullPath(realm.Filename)}");
|
||||
await testAction(realm, testStorage);
|
||||
|
||||
realmFactory.Dispose();
|
||||
realm.Dispose();
|
||||
|
||||
Logger.Log($"Final database size: {getFileSize(testStorage, realmFactory)}");
|
||||
realmFactory.Compact();
|
||||
Logger.Log($"Final database size: {getFileSize(testStorage, realm)}");
|
||||
realm.Compact();
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -138,11 +138,11 @@ namespace osu.Game.Tests.Database
|
||||
}
|
||||
}
|
||||
|
||||
private static long getFileSize(Storage testStorage, RealmContextFactory realmFactory)
|
||||
private static long getFileSize(Storage testStorage, RealmAccess realm)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var stream = testStorage.GetStream(realmFactory.Filename))
|
||||
using (var stream = testStorage.GetStream(realm.Filename))
|
||||
return stream?.Length ?? 0;
|
||||
}
|
||||
catch
|
||||
|
@ -12,37 +12,37 @@ namespace osu.Game.Tests.Database
|
||||
[Test]
|
||||
public void TestCreateStore()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, storage) =>
|
||||
RunTestWithRealm((realm, storage) =>
|
||||
{
|
||||
var rulesets = new RulesetStore(realmFactory, storage);
|
||||
var rulesets = new RulesetStore(realm, storage);
|
||||
|
||||
Assert.AreEqual(4, rulesets.AvailableRulesets.Count());
|
||||
Assert.AreEqual(4, realmFactory.Context.All<RulesetInfo>().Count());
|
||||
Assert.AreEqual(4, realm.Realm.All<RulesetInfo>().Count());
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCreateStoreTwiceDoesntAddRulesetsAgain()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, storage) =>
|
||||
RunTestWithRealm((realm, storage) =>
|
||||
{
|
||||
var rulesets = new RulesetStore(realmFactory, storage);
|
||||
var rulesets2 = new RulesetStore(realmFactory, storage);
|
||||
var rulesets = new RulesetStore(realm, storage);
|
||||
var rulesets2 = new RulesetStore(realm, storage);
|
||||
|
||||
Assert.AreEqual(4, rulesets.AvailableRulesets.Count());
|
||||
Assert.AreEqual(4, rulesets2.AvailableRulesets.Count());
|
||||
|
||||
Assert.AreEqual(rulesets.AvailableRulesets.First(), rulesets2.AvailableRulesets.First());
|
||||
Assert.AreEqual(4, realmFactory.Context.All<RulesetInfo>().Count());
|
||||
Assert.AreEqual(4, realm.Realm.All<RulesetInfo>().Count());
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRetrievedRulesetsAreDetached()
|
||||
{
|
||||
RunTestWithRealm((realmFactory, storage) =>
|
||||
RunTestWithRealm((realm, storage) =>
|
||||
{
|
||||
var rulesets = new RulesetStore(realmFactory, storage);
|
||||
var rulesets = new RulesetStore(realm, storage);
|
||||
|
||||
Assert.IsFalse(rulesets.AvailableRulesets.First().IsManaged);
|
||||
Assert.IsFalse(rulesets.GetRuleset(0)?.IsManaged);
|
||||
|
@ -24,7 +24,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
private RealmKeyBindingStore keyBindingStore;
|
||||
|
||||
private RealmContextFactory realmContextFactory;
|
||||
private RealmAccess realm;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
@ -33,8 +33,8 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
storage = new NativeStorage(directory.FullName);
|
||||
|
||||
realmContextFactory = new RealmContextFactory(storage, "test");
|
||||
keyBindingStore = new RealmKeyBindingStore(realmContextFactory, new ReadableKeyCombinationProvider());
|
||||
realm = new RealmAccess(storage, "test");
|
||||
keyBindingStore = new RealmKeyBindingStore(realm, new ReadableKeyCombinationProvider());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -60,11 +60,11 @@ namespace osu.Game.Tests.Database
|
||||
KeyBindingContainer testContainer = new TestKeyBindingContainer();
|
||||
|
||||
// Add some excess bindings for an action which only supports 1.
|
||||
realmContextFactory.Write(realm =>
|
||||
realm.Write(r =>
|
||||
{
|
||||
realm.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.A)));
|
||||
realm.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.S)));
|
||||
realm.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.D)));
|
||||
r.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.A)));
|
||||
r.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.S)));
|
||||
r.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.D)));
|
||||
});
|
||||
|
||||
Assert.That(queryCount(GlobalAction.Back), Is.EqualTo(3));
|
||||
@ -76,9 +76,9 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
private int queryCount(GlobalAction? match = null)
|
||||
{
|
||||
return realmContextFactory.Run(realm =>
|
||||
return realm.Run(r =>
|
||||
{
|
||||
var results = realm.All<RealmKeyBinding>();
|
||||
var results = r.All<RealmKeyBinding>();
|
||||
if (match.HasValue)
|
||||
results = results.Where(k => k.ActionInt == (int)match.Value);
|
||||
return results.Count();
|
||||
@ -92,7 +92,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
keyBindingStore.Register(testContainer, Enumerable.Empty<RulesetInfo>());
|
||||
|
||||
realmContextFactory.Run(outerRealm =>
|
||||
realm.Run(outerRealm =>
|
||||
{
|
||||
var backBinding = outerRealm.All<RealmKeyBinding>().Single(k => k.ActionInt == (int)GlobalAction.Back);
|
||||
|
||||
@ -100,7 +100,7 @@ namespace osu.Game.Tests.Database
|
||||
|
||||
var tsr = ThreadSafeReference.Create(backBinding);
|
||||
|
||||
realmContextFactory.Run(innerRealm =>
|
||||
realm.Run(innerRealm =>
|
||||
{
|
||||
var binding = innerRealm.ResolveReference(tsr);
|
||||
innerRealm.Write(() => binding.KeyCombination = new KeyCombination(InputKey.BackSpace));
|
||||
@ -117,7 +117,7 @@ namespace osu.Game.Tests.Database
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
realmContextFactory.Dispose();
|
||||
realm.Dispose();
|
||||
storage.DeleteDirectory(string.Empty);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user