.NET: Persistent Store test
namespace Apache.Ignite.Core.Tests.Cache
{
+ using System.IO;
using Apache.Ignite.Core.Common;
+ using Apache.Ignite.Core.Impl;
using Apache.Ignite.Core.PersistentStore;
using NUnit.Framework;
@@ -26,6 +28,78 @@ namespace Apache.Ignite.Core.Tests.Cache
/// </summary>
public class PersistentStoreTest
{
+ /** Temp dir for WAL. */
+ private readonly string _tempDir = IgniteUtils.GetTempDirectoryName();
+
+ /// <summary>
+ /// Tears down the test.
+ /// </summary>
+ [TearDown]
+ public void TearDown()
+ {
+ Ignition.StopAll(true);
+
+ if (Directory.Exists(_tempDir))
+ {
+ Directory.Delete(_tempDir, true);
+ }
+ }
+
+ /// <summary>
+ /// Tests that cache data survives node restart.
+ /// </summary>
+ [Test]
+ public void TestCacheDataSurvivesNodeRestart()
+ {
+ var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
+ {
+ PersistentStoreConfiguration = new PersistentStoreConfiguration
+ {
+ PersistentStorePath = Path.Combine(_tempDir, "Store"),
+ WalStorePath = Path.Combine(_tempDir, "WalStore"),
+ WalArchivePath = Path.Combine(_tempDir, "WalArchive")
+ }
+ };
+
+ const string cacheName = "persistentCache";
+
+ // Start Ignite, put data, stop.
+ using (var ignite = Ignition.Start(cfg))
+ {
+ ignite.SetActive(true);
+
+ var cache = ignite.CreateCache<int, int>(cacheName);
+
+ cache[1] = 1;
+ }
+
+ // Verify directories.
+ Assert.IsTrue(Directory.Exists(cfg.PersistentStoreConfiguration.PersistentStorePath));
+ Assert.IsTrue(Directory.Exists(cfg.PersistentStoreConfiguration.WalStorePath));
+ Assert.IsTrue(Directory.Exists(cfg.PersistentStoreConfiguration.WalArchivePath));
+
+ // Start Ignite, verify data survival.
+ using (var ignite = Ignition.Start(cfg))
+ {
+ ignite.SetActive(true);
+
+ var cache = ignite.GetCache<int, int>(cacheName);
+
+ Assert.AreEqual(1, cache[1]);
+ }
+
+ // Delete store directory.
+ Directory.Delete(_tempDir, true);
+
+ // Start Ignite, verify data loss.
+ using (var ignite = Ignition.Start(cfg))
+ {
+ ignite.SetActive(true);
+
+ Assert.IsFalse(ignite.GetCacheNames().Contains(cacheName));
+ }
+ }
+
/// <summary>
/// Tests the grid activation with persistence (inactive by default).
/// </summary>
