Skip to content

Commit

Permalink
Make Tsavorite.test path handling OS-aware (#308)
Browse files Browse the repository at this point in the history
Co-authored-by: Tal Zaccai <[email protected]>
  • Loading branch information
PaulusParssinen and TalZaccai authored Apr 23, 2024
1 parent 22369e5 commit 4f4891d
Show file tree
Hide file tree
Showing 68 changed files with 351 additions and 396 deletions.
7 changes: 4 additions & 3 deletions libs/storage/Tsavorite/cs/test/AdvancedLockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
Expand Down Expand Up @@ -136,7 +137,7 @@ internal class ChainComparer : ITsavoriteEqualityComparer<int>
public void Setup()
{
DeleteDirectory(MethodTestDir, wait: true);
log = Devices.CreateLogDevice(MethodTestDir + "/GenericStringTests.log", deleteOnClose: true);
log = Devices.CreateLogDevice(Path.Join(MethodTestDir, "GenericStringTests.log"), deleteOnClose: true);
var readCacheSettings = new ReadCacheSettings { MemorySizeBits = 15, PageSizeBits = 9 };

var concurrencyControlMode = ConcurrencyControlMode.None;
Expand Down Expand Up @@ -310,8 +311,8 @@ class LockRecoveryTests
public void Setup()
{
DeleteDirectory(MethodTestDir, wait: true);
checkpointDir = MethodTestDir + $"/checkpoints";
log = Devices.CreateLogDevice(MethodTestDir + "/test.log", deleteOnClose: true);
checkpointDir = Path.Join(MethodTestDir, "checkpoints");
log = Devices.CreateLogDevice(Path.Join(MethodTestDir, "test.log"), deleteOnClose: true);

store1 = new TsavoriteKV<int, int>(128,
logSettings: new LogSettings { LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29 },
Expand Down
19 changes: 9 additions & 10 deletions libs/storage/Tsavorite/cs/test/AsyncLargeObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using System;
using System.IO;
using System.Threading.Tasks;
using NUnit.Framework;
using Tsavorite.core;
Expand All @@ -14,20 +15,18 @@ internal class LargeObjectTests
private TsavoriteKV<MyKey, MyLargeValue> store1;
private TsavoriteKV<MyKey, MyLargeValue> store2;
private IDevice log, objlog;
private string test_path;
private readonly MyLargeFunctions functions = new();

[SetUp]
public void Setup()
{
test_path = TestUtils.MethodTestDir;
TestUtils.RecreateDirectory(test_path);
TestUtils.RecreateDirectory(TestUtils.MethodTestDir);
}

[TearDown]
public void TearDown()
{
TestUtils.DeleteDirectory(test_path);
TestUtils.DeleteDirectory(TestUtils.MethodTestDir);
}

[Test]
Expand All @@ -37,12 +36,12 @@ public async Task LargeObjectTest([Values] CheckpointType checkpointType)
MyInput input = default;
MyLargeOutput output = new();

log = Devices.CreateLogDevice(test_path + "/LargeObjectTest.log");
objlog = Devices.CreateLogDevice(test_path + "/LargeObjectTest.obj.log");
log = Devices.CreateLogDevice(Path.Join(TestUtils.MethodTestDir, "LargeObjectTest.log"));
objlog = Devices.CreateLogDevice(Path.Join(TestUtils.MethodTestDir, "LargeObjectTest.obj.log"));

store1 = new(128,
new LogSettings { LogDevice = log, ObjectLogDevice = objlog, MutableFraction = 0.1, PageSizeBits = 21, MemorySizeBits = 26 },
new CheckpointSettings { CheckpointDir = test_path },
new CheckpointSettings { CheckpointDir = TestUtils.MethodTestDir },
new SerializerSettings<MyKey, MyLargeValue> { keySerializer = () => new MyKeySerializer(), valueSerializer = () => new MyLargeValueSerializer() }
);

Expand All @@ -67,12 +66,12 @@ public async Task LargeObjectTest([Values] CheckpointType checkpointType)
log.Dispose();
objlog.Dispose();

log = Devices.CreateLogDevice(test_path + "/LargeObjectTest.log");
objlog = Devices.CreateLogDevice(test_path + "/LargeObjectTest.obj.log");
log = Devices.CreateLogDevice(Path.Join(TestUtils.MethodTestDir, "LargeObjectTest.log"));
objlog = Devices.CreateLogDevice(Path.Join(TestUtils.MethodTestDir, "LargeObjectTest.obj.log"));

store2 = new(128,
new LogSettings { LogDevice = log, ObjectLogDevice = objlog, MutableFraction = 0.1, PageSizeBits = 21, MemorySizeBits = 26 },
new CheckpointSettings { CheckpointDir = test_path },
new CheckpointSettings { CheckpointDir = TestUtils.MethodTestDir },
new SerializerSettings<MyKey, MyLargeValue> { keySerializer = () => new MyKeySerializer(), valueSerializer = () => new MyLargeValueSerializer() }
);

Expand Down
4 changes: 2 additions & 2 deletions libs/storage/Tsavorite/cs/test/AsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class AsyncRecoveryTests
public async Task AsyncRecoveryTest1(CheckpointType checkpointType)
{
TestUtils.DeleteDirectory(TestUtils.MethodTestDir, wait: true);
log = Devices.CreateLogDevice(TestUtils.MethodTestDir + "/AsyncRecoveryTest1.log", deleteOnClose: true);
log = Devices.CreateLogDevice(Path.Join(TestUtils.MethodTestDir, "AsyncRecoveryTest1.log"), deleteOnClose: true);

string testPath = TestUtils.MethodTestDir + "/checkpoints4";
string testPath = Path.Join(TestUtils.MethodTestDir, "checkpoints4");
Directory.CreateDirectory(testPath);

store1 = new TsavoriteKV<AdId, NumClicks>
Expand Down
3 changes: 2 additions & 1 deletion libs/storage/Tsavorite/cs/test/BasicLockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -80,7 +81,7 @@ internal class LocalComparer : ITsavoriteEqualityComparer<int>
public void Setup()
{
DeleteDirectory(MethodTestDir, wait: true);
log = Devices.CreateLogDevice(MethodTestDir + "/GenericStringTests.log", deleteOnClose: true);
log = Devices.CreateLogDevice(Path.Join(MethodTestDir, "GenericStringTests.log"), deleteOnClose: true);
store = new TsavoriteKV<int, int>(1L << 20, new LogSettings { LogDevice = log, ObjectLogDevice = null }, comparer: new LocalComparer(), concurrencyControlMode: ConcurrencyControlMode.RecordIsolation);
session = store.NewSession<int, int, Empty, Functions>(new Functions());
}
Expand Down
13 changes: 7 additions & 6 deletions libs/storage/Tsavorite/cs/test/BasicStorageTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.IO;
using NUnit.Framework;
using Tsavorite.core;
using Tsavorite.devices;
Expand All @@ -16,7 +17,7 @@ internal class BasicStorageTests
[Category("TsavoriteKV")]
public void LocalStorageWriteRead()
{
TestDeviceWriteRead(Devices.CreateLogDevice(TestUtils.MethodTestDir + "/BasicDiskTests.log", deleteOnClose: true));
TestDeviceWriteRead(Devices.CreateLogDevice(Path.Join(TestUtils.MethodTestDir, "BasicDiskTests.log"), deleteOnClose: true));
}

[Test]
Expand Down Expand Up @@ -44,7 +45,7 @@ public void TieredWriteRead()
{
TestUtils.DeleteDirectory(TestUtils.MethodTestDir);
IDevice tested;
IDevice localDevice = Devices.CreateLogDevice(TestUtils.MethodTestDir + "/BasicDiskTests.log", deleteOnClose: true, capacity: 1 << 30);
IDevice localDevice = Devices.CreateLogDevice(Path.Join(TestUtils.MethodTestDir, "BasicDiskTests.log"), deleteOnClose: true, capacity: 1 << 30);
if (TestUtils.IsRunningAzureTests)
{
IDevice cloudDevice = new AzureStorageDevice(TestUtils.AzureEmulatedStorageString, TestUtils.AzureTestContainer, TestUtils.AzureTestDirectory, "BasicDiskTests", logger: TestUtils.TestLoggerFactory.CreateLogger("asd"));
Expand All @@ -53,7 +54,7 @@ public void TieredWriteRead()
else
{
// If no Azure is enabled, just use another disk
IDevice localDevice2 = Devices.CreateLogDevice(TestUtils.MethodTestDir + "/BasicDiskTests2.log", deleteOnClose: true, capacity: 1 << 30);
IDevice localDevice2 = Devices.CreateLogDevice(Path.Join(TestUtils.MethodTestDir, "BasicDiskTests2.log"), deleteOnClose: true, capacity: 1 << 30);
tested = new TieredStorageDevice(1, localDevice, localDevice2);

}
Expand All @@ -65,8 +66,8 @@ public void TieredWriteRead()
[Category("Smoke")]
public void ShardedWriteRead()
{
IDevice localDevice1 = Devices.CreateLogDevice(TestUtils.MethodTestDir + "/BasicDiskTests1.log", deleteOnClose: true, capacity: 1 << 30);
IDevice localDevice2 = Devices.CreateLogDevice(TestUtils.MethodTestDir + "/BasicDiskTests2.log", deleteOnClose: true, capacity: 1 << 30);
IDevice localDevice1 = Devices.CreateLogDevice(Path.Join(TestUtils.MethodTestDir, "BasicDiskTests1.log"), deleteOnClose: true, capacity: 1 << 30);
IDevice localDevice2 = Devices.CreateLogDevice(Path.Join(TestUtils.MethodTestDir, "BasicDiskTests2.log"), deleteOnClose: true, capacity: 1 << 30);
var device = new ShardedStorageDevice(new UniformPartitionScheme(512, localDevice1, localDevice2));
TestDeviceWriteRead(device);
}
Expand All @@ -76,7 +77,7 @@ public void ShardedWriteRead()
[Category("Smoke")]
public void OmitSegmentIdTest([Values] TestUtils.DeviceType deviceType)
{
var filename = TestUtils.MethodTestDir + "/test.log";
var filename = Path.Join(TestUtils.MethodTestDir, "test.log");
var omit = false;
for (var ii = 0; ii < 2; ++ii)
{
Expand Down
23 changes: 10 additions & 13 deletions libs/storage/Tsavorite/cs/test/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
Expand All @@ -20,21 +21,18 @@ internal class BasicTests
private TsavoriteKV<KeyStruct, ValueStruct> store;
private ClientSession<KeyStruct, ValueStruct, InputStruct, OutputStruct, Empty, Functions> session;
private IDevice log;
private string path;
DeviceType deviceType;

[SetUp]
public void Setup()
{
path = MethodTestDir + "/";

// Clean up log files from previous test runs in case they weren't cleaned up
DeleteDirectory(path, wait: true);
DeleteDirectory(TestUtils.MethodTestDir, wait: true);
}

private void Setup(long size, LogSettings logSettings, DeviceType deviceType, int latencyMs = DefaultLocalMemoryDeviceLatencyMs)
{
string filename = path + TestContext.CurrentContext.Test.Name + deviceType.ToString() + ".log";
string filename = Path.Join(MethodTestDir, TestContext.CurrentContext.Test.Name + deviceType.ToString() + ".log");
log = CreateTestDevice(deviceType, filename, latencyMs: latencyMs);
logSettings.LogDevice = log;
store = new TsavoriteKV<KeyStruct, ValueStruct>(size, logSettings);
Expand All @@ -50,7 +48,7 @@ public void TearDown()
store = null;
log?.Dispose();
log = null;
DeleteDirectory(path);
DeleteDirectory(TestUtils.MethodTestDir);
}

private void AssertCompleted(Status expected, Status actual)
Expand Down Expand Up @@ -785,8 +783,7 @@ public void UpsertSerialNumberTest()
[Category("TsavoriteKV")]
public static void KVBasicsSampleEndToEndInDocs()
{
string testDir = MethodTestDir;
using var log = Devices.CreateLogDevice($"{testDir}/hlog.log", deleteOnClose: false);
using var log = Devices.CreateLogDevice(Path.Join(MethodTestDir, "hlog.log"), deleteOnClose: false);
using var store = new TsavoriteKV<long, long>(1L << 20, new LogSettings { LogDevice = log });
using var s = store.NewSession<long, long, Empty, SimpleFunctions<long, long>>(new SimpleFunctions<long, long>());
long key = 1, value = 1, input = 10, output = 0;
Expand All @@ -805,16 +802,16 @@ public static void KVBasicsSampleEndToEndInDocs()
public static void LogPathtooLong()
{
string testDir = new('x', Native32.WIN32_MAX_PATH - 11); // As in LSD, -11 for ".<segment>"
using var log = Devices.CreateLogDevice($"{testDir}", deleteOnClose: true); // Should succeed
Assert.Throws(typeof(TsavoriteException), () => Devices.CreateLogDevice($"{testDir}y", deleteOnClose: true));
using var log = Devices.CreateLogDevice(testDir, deleteOnClose: true); // Should succeed
Assert.Throws(typeof(TsavoriteException), () => Devices.CreateLogDevice(testDir + "y", deleteOnClose: true));
}
#endif

[Test]
[Category("TsavoriteKV")]
public static void UshortKeyByteValueTest()
{
using var log = Devices.CreateLogDevice($"{MethodTestDir}/hlog.log", deleteOnClose: false);
using var log = Devices.CreateLogDevice(Path.Join(MethodTestDir, "hlog.log"), deleteOnClose: false);
using var store = new TsavoriteKV<ushort, byte>(1L << 20, new LogSettings { LogDevice = log });
using var s = store.NewSession<byte, byte, Empty, SimpleFunctions<ushort, byte>>(new SimpleFunctions<ushort, byte>());
ushort key = 1024;
Expand Down Expand Up @@ -849,7 +846,7 @@ public static void UshortKeyByteValueTest()
[Category("TsavoriteKV")]
public static void BasicSyncOperationsTest()
{
using var log = Devices.CreateLogDevice($"{MethodTestDir}/hlog.log", deleteOnClose: false);
using var log = Devices.CreateLogDevice(Path.Join(MethodTestDir, "hlog.log"), deleteOnClose: false);
using var store = new TsavoriteKV<long, long>(1L << 20, new LogSettings { LogDevice = log });
using var session = store.NewSession<long, long, Empty, SimpleFunctions<long, long>>(new SimpleFunctions<long, long>());
const int numRecords = 500;
Expand Down Expand Up @@ -941,7 +938,7 @@ void doUpdate(bool useRMW)
[Category("TsavoriteKV")]
public static async Task BasicAsyncOperationsTest()
{
using var log = Devices.CreateLogDevice($"{MethodTestDir}/hlog.log", deleteOnClose: false);
using var log = Devices.CreateLogDevice(Path.Join(MethodTestDir, "hlog.log"), deleteOnClose: false);
using var store = new TsavoriteKV<long, long>(1L << 20, new LogSettings { LogDevice = log });
using var session = store.NewSession<long, long, Empty, SimpleFunctions<long, long>>(new SimpleFunctions<long, long>());
const int numRecords = 500;
Expand Down
14 changes: 6 additions & 8 deletions libs/storage/Tsavorite/cs/test/BlittableIterationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using NUnit.Framework;
using Tsavorite.core;
Expand All @@ -15,15 +16,12 @@ internal class BlittableIterationTests
{
private TsavoriteKV<KeyStruct, ValueStruct> store;
private IDevice log;
private string path;

[SetUp]
public void Setup()
{
path = MethodTestDir + "/";

// Clean up log files from previous test runs in case they weren't cleaned up
DeleteDirectory(path, wait: true);
DeleteDirectory(MethodTestDir, wait: true);
}

[TearDown]
Expand All @@ -33,7 +31,7 @@ public void TearDown()
store = null;
log?.Dispose();
log = null;
DeleteDirectory(path);
DeleteDirectory(MethodTestDir);
}

internal struct BlittablePushIterationTestFunctions : IScanIteratorFunctions<KeyStruct, ValueStruct>
Expand Down Expand Up @@ -62,7 +60,7 @@ public void OnStop(bool completed, long numberOfRecords) { }
[Category(SmokeTestCategory)]
public void BlittableIterationBasicTest([Values] DeviceType deviceType, [Values] ScanIteratorType scanIteratorType)
{
log = CreateTestDevice(deviceType, $"{path}{deviceType}.log");
log = CreateTestDevice(deviceType, Path.Join(MethodTestDir, $"{deviceType}.log"));
store = new TsavoriteKV<KeyStruct, ValueStruct>
(1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 9, SegmentSizeBits = 22 },
concurrencyControlMode: scanIteratorType == ScanIteratorType.Pull ? ConcurrencyControlMode.None : ConcurrencyControlMode.LockTable);
Expand Down Expand Up @@ -146,7 +144,7 @@ void iterateAndVerify(int keyMultToValue, int expectedRecs)
[Category(SmokeTestCategory)]
public void BlittableIterationPushStopTest()
{
log = Devices.CreateLogDevice($"{path}stop_test.log");
log = Devices.CreateLogDevice(Path.Join(MethodTestDir, "stop_test.log"));
store = new TsavoriteKV<KeyStruct, ValueStruct>
(1L << 20, new LogSettings { LogDevice = log, MemorySizeBits = 15, PageSizeBits = 9, SegmentSizeBits = 22 });

Expand Down Expand Up @@ -184,7 +182,7 @@ void scanAndVerify(int stopAt, bool useScan)
[Category(SmokeTestCategory)]
public unsafe void BlittableIterationPushLockTest([Values(1, 4)] int scanThreads, [Values(1, 4)] int updateThreads, [Values] ConcurrencyControlMode concurrencyControlMode, [Values] ScanMode scanMode)
{
log = Devices.CreateLogDevice($"{path}lock_test.log");
log = Devices.CreateLogDevice(Path.Join(MethodTestDir, "lock_test.log"));
// Must be large enough to contain all records in memory to exercise locking
store = new TsavoriteKV<KeyStruct, ValueStruct>(1L << 20,
new LogSettings { LogDevice = log, MemorySizeBits = 25, PageSizeBits = 20, SegmentSizeBits = 22 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Diagnostics;
using System.IO;
using NUnit.Framework;
using Tsavorite.core;
using static Tsavorite.test.TestUtils;
Expand Down Expand Up @@ -37,7 +38,7 @@ public long GetHashCode64(ref KeyStruct k)
public void Setup()
{
DeleteDirectory(MethodTestDir, wait: true);
log = Devices.CreateLogDevice(MethodTestDir + "/BlittableLogCompactionTests.log", deleteOnClose: true);
log = Devices.CreateLogDevice(Path.Join(MethodTestDir, "BlittableLogCompactionTests.log"), deleteOnClose: true);

var concurrencyControlMode = ConcurrencyControlMode.LockTable;
var hashMod = HashModulo.NoMod;
Expand Down
3 changes: 2 additions & 1 deletion libs/storage/Tsavorite/cs/test/BlittableLogScanTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using System;
using System.IO;
using NUnit.Framework;
using Tsavorite.core;
using static Tsavorite.test.TestUtils;
Expand Down Expand Up @@ -50,7 +51,7 @@ public void Setup()
}
}

log = Devices.CreateLogDevice(MethodTestDir + "/test.log", deleteOnClose: true);
log = Devices.CreateLogDevice(Path.Join(MethodTestDir, "test.log"), deleteOnClose: true);
store = new TsavoriteKV<KeyStruct, ValueStruct>(1L << 20,
new LogSettings { LogDevice = log, MemorySizeBits = 24, PageSizeBits = PageSizeBits }, concurrencyControlMode: ConcurrencyControlMode.None, comparer: comparer);
}
Expand Down
3 changes: 2 additions & 1 deletion libs/storage/Tsavorite/cs/test/CancellationTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.IO;
using NUnit.Framework;
using Tsavorite.core;
using static Tsavorite.test.TestUtils;
Expand Down Expand Up @@ -127,7 +128,7 @@ public void Setup()
{
DeleteDirectory(MethodTestDir, wait: true);

log = Devices.CreateLogDevice(MethodTestDir + "/hlog.log", deleteOnClose: true);
log = Devices.CreateLogDevice(Path.Join(MethodTestDir, "hlog.log"), deleteOnClose: true);
store = new TsavoriteKV<int, int>
(128,
new LogSettings { LogDevice = log, MemorySizeBits = 17, PageSizeBits = 12 },
Expand Down
Loading

0 comments on commit 4f4891d

Please sign in to comment.