diff --git a/.github/workflows/create-checks.yml b/.github/workflows/create-checks.yml index 7d0ff7a16..d333d843a 100644 --- a/.github/workflows/create-checks.yml +++ b/.github/workflows/create-checks.yml @@ -239,7 +239,7 @@ jobs: # see https://github.com/marketplace/actions/codecov - name: Publish to Codecov if: inputs.coverage && inputs.conclusion == 'success' && (steps.unzip.outputs.coverage == 'true' || steps.move.outputs.coverage == 'true') - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} files: ./temp/test-coverage/windows/cover-net6.0.xml diff --git a/src/Hazelcast.Net.Tests/Models/CacheSimpleEntryListenerOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/CacheSimpleEntryListenerOptionsTests.cs new file mode 100644 index 000000000..af1c860f3 --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/CacheSimpleEntryListenerOptionsTests.cs @@ -0,0 +1,72 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +namespace Hazelcast.Tests.Models +{ +using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Core; +using Hazelcast.Serialization; + +[TestFixture] +public class CacheSimpleEntryListenerOptionsTests +{ + [Test] + public void DefaultConstructor_SetsPropertiesToDefault() + { + var options = new CacheSimpleEntryListenerOptions(); + + Assert.IsNull(options.CacheEntryListenerFactory); + Assert.IsNull(options.CacheEntryEventFilterFactory); + Assert.IsFalse(options.OldValueRequired); + Assert.IsFalse(options.Synchronous); + } + + [Test] + public void Constructor_WithCacheSimpleEntryListenerOptionsArgument_CopiesProperties() + { + var originalOptions = new CacheSimpleEntryListenerOptions + { + CacheEntryListenerFactory = "TestFactory", + CacheEntryEventFilterFactory = "TestFilterFactory", + OldValueRequired = true, + Synchronous = true + }; + var copiedOptions = new CacheSimpleEntryListenerOptions(originalOptions); + + Assert.AreEqual(originalOptions.CacheEntryListenerFactory, copiedOptions.CacheEntryListenerFactory); + Assert.AreEqual(originalOptions.CacheEntryEventFilterFactory, copiedOptions.CacheEntryEventFilterFactory); + Assert.AreEqual(originalOptions.OldValueRequired, copiedOptions.OldValueRequired); + Assert.AreEqual(originalOptions.Synchronous, copiedOptions.Synchronous); + } + + [Test] + public void ToString_ReturnsExpectedFormat() + { + var options = new CacheSimpleEntryListenerOptions + { + CacheEntryListenerFactory = "TestFactory", + CacheEntryEventFilterFactory = "TestFilterFactory", + OldValueRequired = true, + Synchronous = true + }; + + var result = options.ToString(); + + StringAssert.Contains("cacheEntryListenerFactory='TestFactory'", result); + StringAssert.Contains("cacheEntryEventFilterFactory='TestFilterFactory'", result); + StringAssert.Contains("oldValueRequired=True", result); + StringAssert.Contains("synchronous=True", result); + } +} +} diff --git a/src/Hazelcast.Net.Tests/Models/DataPersistenceOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/DataPersistenceOptionsTests.cs new file mode 100644 index 000000000..cdc7bec8e --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/DataPersistenceOptionsTests.cs @@ -0,0 +1,80 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using Hazelcast.Core; +using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Serialization; +using NSubstitute; +namespace Hazelcast.Tests.Models +{ + [TestFixture] + public class DataPersistenceOptionsTests + { + [Test] + public void Constructor_WithValidParameters_InitializesPropertiesCorrectly() + { + var enabled = true; + var fsync = true; + + var dataPersistenceOptions = new DataPersistenceOptions + { + Enabled = enabled, + Fsync = fsync + }; + + Assert.AreEqual(enabled, dataPersistenceOptions.Enabled); + Assert.AreEqual(fsync, dataPersistenceOptions.Fsync); + } + + [Test] + public void WriteData_ReadData_WritesAndReadsDataCorrectly() + { + var enabled = true; + var fsync = true; + + var dataPersistenceOptions = new DataPersistenceOptions + { + Enabled = enabled, + Fsync = fsync + }; + + var output = new ObjectDataOutput(1024, null, Endianness.LittleEndian); + dataPersistenceOptions.WriteData(output); + + var input = new ObjectDataInput(output.Buffer, null, Endianness.LittleEndian); + var readDataPersistenceOptions = new DataPersistenceOptions(); + readDataPersistenceOptions.ReadData(input); + + Assert.AreEqual(dataPersistenceOptions.Enabled, readDataPersistenceOptions.Enabled); + Assert.AreEqual(dataPersistenceOptions.Fsync, readDataPersistenceOptions.Fsync); + } + + [Test] + public void ToString_ReturnsCorrectFormat() + { + var enabled = true; + var fsync = true; + + var dataPersistenceOptions = new DataPersistenceOptions + { + Enabled = enabled, + Fsync = fsync + }; + + var expectedString = $"DataPersistenceConfig{{enabled={enabled}, fsync={fsync}}}"; + + Assert.AreEqual(expectedString, dataPersistenceOptions.ToString()); + } + } +} \ No newline at end of file diff --git a/src/Hazelcast.Net.Tests/Models/DiskTierOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/DiskTierOptionsTests.cs new file mode 100644 index 000000000..7b8ac01a3 --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/DiskTierOptionsTests.cs @@ -0,0 +1,66 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using Hazelcast.Core; +using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Serialization; +using NSubstitute; +namespace Hazelcast.Tests.Models +{ + [TestFixture] + public class DiskTierOptionsTests + { + [Test] + public void Constructor_WithValidParameters_InitializesPropertiesCorrectly() + { + var enabled = true; + var deviceName = "TestDevice"; + + var diskTierOptions = new DiskTierOptions { Enabled = enabled, DeviceName = deviceName }; + + Assert.AreEqual(enabled, diskTierOptions.Enabled); + Assert.AreEqual(deviceName, diskTierOptions.DeviceName); + } + + [Test] + public void WriteData_ReadData_WritesAndReadsDataCorrectly() + { + var enabled = true; + var deviceName = "TestDevice"; + var diskTierOptions = new DiskTierOptions { Enabled = enabled, DeviceName = deviceName }; + + var output = new ObjectDataOutput(1024, null, Endianness.LittleEndian); + diskTierOptions.WriteData(output); + + var input = new ObjectDataInput(output.Buffer, null, Endianness.LittleEndian); + var readDiskTierOptions = new DiskTierOptions(); + readDiskTierOptions.ReadData(input); + + Assert.AreEqual(diskTierOptions.Enabled, readDiskTierOptions.Enabled); + Assert.AreEqual(diskTierOptions.DeviceName, readDiskTierOptions.DeviceName); + } + + [Test] + public void ToString_ReturnsCorrectFormat() + { + var enabled = true; + var deviceName = "TestDevice"; + var diskTierOptions = new DiskTierOptions { Enabled = enabled, DeviceName = deviceName }; + + var expectedString = $"DiskTierConfig{{enabled={enabled}, deviceName='{deviceName}'}}"; + + Assert.AreEqual(expectedString, diskTierOptions.ToString()); + } + } +} diff --git a/src/Hazelcast.Net.Tests/Models/HotRestartOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/HotRestartOptionsTests.cs new file mode 100644 index 000000000..02abb38cb --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/HotRestartOptionsTests.cs @@ -0,0 +1,80 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using Hazelcast.Core; +using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Serialization; +using NSubstitute; +namespace Hazelcast.Tests.Models +{ + [TestFixture] + public class HotRestartOptionsTests + { + [Test] + public void Constructor_WithValidParameters_InitializesPropertiesCorrectly() + { + var enabled = true; + var fsync = true; + + var hotRestartOptions = new HotRestartOptions + { + Enabled = enabled, + Fsync = fsync + }; + + Assert.AreEqual(enabled, hotRestartOptions.Enabled); + Assert.AreEqual(fsync, hotRestartOptions.Fsync); + } + + [Test] + public void WriteData_ReadData_WritesAndReadsDataCorrectly() + { + var enabled = true; + var fsync = true; + + var hotRestartOptions = new HotRestartOptions + { + Enabled = enabled, + Fsync = fsync + }; + + var output = new ObjectDataOutput(1024, null, Endianness.LittleEndian); + hotRestartOptions.WriteData(output); + + var input = new ObjectDataInput(output.Buffer, null, Endianness.LittleEndian); + var readHotRestartOptions = new HotRestartOptions(); + readHotRestartOptions.ReadData(input); + + Assert.AreEqual(hotRestartOptions.Enabled, readHotRestartOptions.Enabled); + Assert.AreEqual(hotRestartOptions.Fsync, readHotRestartOptions.Fsync); + } + + [Test] + public void ToString_ReturnsCorrectFormat() + { + var enabled = true; + var fsync = true; + + var hotRestartOptions = new HotRestartOptions + { + Enabled = enabled, + Fsync = fsync + }; + + var expectedString = $"HotRestartConfig{{enabled={enabled}, fsync={fsync}}}"; + + Assert.AreEqual(expectedString, hotRestartOptions.ToString()); + } + } +} \ No newline at end of file diff --git a/src/Hazelcast.Net.Tests/Models/MapOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/MapOptionsTests.cs new file mode 100644 index 000000000..35f2c1f31 --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/MapOptionsTests.cs @@ -0,0 +1,163 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using System; +using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Serialization; +using System.Collections.Generic; +using Hazelcast.Configuration; +using Hazelcast.Core; +using Hazelcast.NearCaching; +using Hazelcast.Serialization.ConstantSerializers; +using Hazelcast.Tests.Serialization.Compact; +using Microsoft.Extensions.Logging.Abstractions; +using NSubstitute; + +namespace Hazelcast.Tests.Models +{ + [TestFixture] + public class MapOptionsTests + { + [Test] + public void Constructor_WithValidParameters_InitializesPropertiesCorrectly() + { + var name = "TestMap"; + var backupCount = 2; + var asyncBackupCount = 1; + + var mapOptions = new MapOptions(name) + { + BackupCount = backupCount, + AsyncBackupCount = asyncBackupCount + }; + + Assert.AreEqual(name, mapOptions.Name); + Assert.AreEqual(backupCount, mapOptions.BackupCount); + Assert.AreEqual(asyncBackupCount, mapOptions.AsyncBackupCount); + } + [Test] + public void Constructor_WithMapOptionsArgument_CopiesProperties() + { + var originalOptions = new MapOptions("TestMap") + { + BackupCount = 2, + AsyncBackupCount = 1, + TimeToLiveSeconds = 3600, + MaxIdleSeconds = 1800, + Eviction = new EvictionOptions(), + MapStore = new MapStoreOptions(), + NearCache = new NearCacheOptions(), + ReadBackupData = true, + CacheDeserializedValues = CacheDeserializedValues.Never, + MergePolicy = new MergePolicyOptions(), + InMemoryFormat = InMemoryFormat.Binary, + WanReplicationRef = new WanReplicationRef(), + EntryListeners = new List(), + PartitionLostListeners = new List(), + Indexes = new List(), + Attributes = new List(), + QueryCaches = new List(), + StatisticsEnabled = true, + PartitioningStrategy = new PartitioningStrategyOptions(), + SplitBrainProtectionName = "TestProtection", + HotRestart = new HotRestartOptions(), + MerkleTree = new MerkleTreeOptions(), + EventJournal = new EventJournalOptions(), + MetadataPolicy = MetadataPolicy.CreateOnUpdate, + PerEntryStatsEnabled = true, + DataPersistence = new DataPersistenceOptions(), + TieredStore = new TieredStoreOptions(), + PartitioningAttributes = new List() + }; + + var copiedOptions = new MapOptions(originalOptions); + + Assert.AreEqual(originalOptions.Name, copiedOptions.Name); + Assert.AreEqual(originalOptions.BackupCount, copiedOptions.BackupCount); + Assert.AreEqual(originalOptions.AsyncBackupCount, copiedOptions.AsyncBackupCount); + Assert.AreEqual(originalOptions.TimeToLiveSeconds, copiedOptions.TimeToLiveSeconds); + Assert.AreEqual(originalOptions.MaxIdleSeconds, copiedOptions.MaxIdleSeconds); + Assert.AreEqual(originalOptions.Eviction.Size, copiedOptions.Eviction.Size); + Assert.AreEqual(originalOptions.MapStore.Enabled, copiedOptions.MapStore.Enabled); + Assert.AreEqual(originalOptions.NearCache.Name, copiedOptions.NearCache.Name); + Assert.AreEqual(originalOptions.ReadBackupData, copiedOptions.ReadBackupData); + Assert.AreEqual(originalOptions.CacheDeserializedValues, copiedOptions.CacheDeserializedValues); + Assert.AreEqual(originalOptions.MergePolicy.Policy, copiedOptions.MergePolicy.Policy); + Assert.AreEqual(originalOptions.InMemoryFormat, copiedOptions.InMemoryFormat); + Assert.AreEqual(originalOptions.WanReplicationRef.Name, copiedOptions.WanReplicationRef.Name); + Assert.AreEqual(originalOptions.EntryListeners.Count, copiedOptions.EntryListeners.Count); + Assert.AreEqual(originalOptions.PartitionLostListeners.Capacity, copiedOptions.PartitionLostListeners.Count); + Assert.AreEqual(originalOptions.Indexes.Count, copiedOptions.Indexes.Count); + Assert.AreEqual(originalOptions.Attributes.Count, copiedOptions.Attributes.Count); + Assert.AreEqual(originalOptions.QueryCaches.Count, copiedOptions.QueryCaches.Count); + Assert.AreEqual(originalOptions.StatisticsEnabled, copiedOptions.StatisticsEnabled); + Assert.AreEqual(originalOptions.SplitBrainProtectionName, copiedOptions.SplitBrainProtectionName); + Assert.AreEqual(originalOptions.HotRestart.Enabled, copiedOptions.HotRestart.Enabled); + Assert.AreEqual(originalOptions.MerkleTree.Enabled, copiedOptions.MerkleTree.Enabled); + Assert.AreEqual(originalOptions.EventJournal.Enabled, copiedOptions.EventJournal.Enabled); + Assert.AreEqual(originalOptions.MetadataPolicy, copiedOptions.MetadataPolicy); + Assert.AreEqual(originalOptions.PerEntryStatsEnabled, copiedOptions.PerEntryStatsEnabled); + Assert.AreEqual(originalOptions.DataPersistence.Enabled, copiedOptions.DataPersistence.Enabled); + Assert.AreEqual(originalOptions.TieredStore.Enabled, copiedOptions.TieredStore.Enabled); + Assert.AreEqual(originalOptions.PartitioningAttributes.Count, copiedOptions.PartitioningAttributes.Count); + } + [Test] + public void WriteData_ReadData_WritesAndReadsDataCorrectly() + { + var name = "TestMap"; + var backupCount = 2; + var asyncBackupCount = 1; + + var mapOptions = new MapOptions(name) + { + BackupCount = backupCount, + AsyncBackupCount = asyncBackupCount + }; + + var orw = Substitute.For(); + orw.Read(Arg.Any()).Returns(new HotRestartOptions()); + orw.Read(Arg.Any()).Returns(new DataPersistenceOptions()); + orw.Read(Arg.Any()).Returns(new TieredStoreOptions()); + + var output = new ObjectDataOutput(1024, orw, Endianness.LittleEndian); + mapOptions.WriteData(output); + + var input = new ObjectDataInput(output.Buffer, orw, Endianness.LittleEndian); + var readMapOptions = new MapOptions(); + readMapOptions.ReadData(input); + + Assert.AreEqual(mapOptions.Name, readMapOptions.Name); + Assert.AreEqual(mapOptions.BackupCount, readMapOptions.BackupCount); + Assert.AreEqual(mapOptions.AsyncBackupCount, readMapOptions.AsyncBackupCount); + } + + [Test] + public void ToString_ReturnsCorrectFormat() + { + var name = "TestMap"; + var backupCount = 2; + var asyncBackupCount = 1; + + var mapOptions = new MapOptions(name) + { + BackupCount = backupCount, + AsyncBackupCount = asyncBackupCount + }; + + var expectedString = $"MapConfig{{name='{name}'"; + + Assert.IsTrue(mapOptions.ToString().StartsWith(expectedString)); + } + } +} diff --git a/src/Hazelcast.Net.Tests/Models/MapStoreOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/MapStoreOptionsTests.cs new file mode 100644 index 000000000..88312f159 --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/MapStoreOptionsTests.cs @@ -0,0 +1,144 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Serialization; +using System.Collections.Generic; +using Hazelcast.Configuration; +using Hazelcast.Core; +using Hazelcast.Query; +using Hazelcast.Serialization.ConstantSerializers; +using Hazelcast.Tests.Serialization.Compact; +using Microsoft.Extensions.Logging.Abstractions; +using NSubstitute; + +namespace Hazelcast.Tests.Models +{ + [TestFixture] + public class MapStoreOptionsTests + { + [Test] + public void Constructor_WithValidParameters_InitializesPropertiesCorrectly() + { + var enabled = true; + var className = "TestClassName"; + var factoryClassName = "TestFactoryClassName"; + var writeDelaySeconds = 10; + var writeBatchSize = 5; + var properties = new Dictionary { { "key1", "value1" }, { "key2", "value2" } }; + var initialLoadMode = LoadMode.Eager; + var writeCoalescing = true; + var offload = true; + + var mapStoreOptions = new MapStoreOptions + { + Enabled = enabled, + ClassName = className, + FactoryClassName = factoryClassName, + WriteDelaySeconds = writeDelaySeconds, + WriteBatchSize = writeBatchSize, + Properties = properties, + InitialLoadMode = initialLoadMode, + WriteCoalescing = writeCoalescing, + Offload = offload + }; + + Assert.AreEqual(enabled, mapStoreOptions.Enabled); + Assert.AreEqual(className, mapStoreOptions.ClassName); + Assert.AreEqual(factoryClassName, mapStoreOptions.FactoryClassName); + Assert.AreEqual(writeDelaySeconds, mapStoreOptions.WriteDelaySeconds); + Assert.AreEqual(writeBatchSize, mapStoreOptions.WriteBatchSize); + Assert.AreEqual(properties, mapStoreOptions.Properties); + Assert.AreEqual(initialLoadMode, mapStoreOptions.InitialLoadMode); + Assert.AreEqual(writeCoalescing, mapStoreOptions.WriteCoalescing); + Assert.AreEqual(offload, mapStoreOptions.Offload); + } + + [Test] + public void WriteData_ReadData_WritesAndReadsDataCorrectly() + { + var enabled = true; + var className = "TestClassName"; + var factoryClassName = "TestFactoryClassName"; + var writeDelaySeconds = 10; + var writeBatchSize = 5; + var properties = new Dictionary { { "key1", "value1" }, { "key2", "value2" } }; + var initialLoadMode = LoadMode.Eager; + var writeCoalescing = true; + var offload = true; + + var mapStoreOptions = new MapStoreOptions + { + Enabled = enabled, + ClassName = className, + FactoryClassName = factoryClassName, + WriteDelaySeconds = writeDelaySeconds, + WriteBatchSize = writeBatchSize, + Properties = properties, + InitialLoadMode = initialLoadMode, + WriteCoalescing = writeCoalescing, + Offload = offload + }; + + var orw = Substitute.For(); + + var output = new ObjectDataOutput(1024, orw, Endianness.LittleEndian); + mapStoreOptions.WriteData(output); + + var input = new ObjectDataInput(output.Buffer, orw, Endianness.LittleEndian); + var readMapStoreOptions = new MapStoreOptions(); + readMapStoreOptions.ReadData(input); + + Assert.AreEqual(mapStoreOptions.Enabled, readMapStoreOptions.Enabled); + Assert.AreEqual(mapStoreOptions.ClassName, readMapStoreOptions.ClassName); + Assert.AreEqual(mapStoreOptions.FactoryClassName, readMapStoreOptions.FactoryClassName); + Assert.AreEqual(mapStoreOptions.WriteDelaySeconds, readMapStoreOptions.WriteDelaySeconds); + Assert.AreEqual(mapStoreOptions.WriteBatchSize, readMapStoreOptions.WriteBatchSize); + Assert.AreEqual(mapStoreOptions.InitialLoadMode, readMapStoreOptions.InitialLoadMode); + Assert.AreEqual(mapStoreOptions.WriteCoalescing, readMapStoreOptions.WriteCoalescing); + Assert.AreEqual(mapStoreOptions.Offload, readMapStoreOptions.Offload); + } + + [Test] + public void ToString_ReturnsCorrectFormat() + { + var enabled = true; + var className = "TestClassName"; + var factoryClassName = "TestFactoryClassName"; + var writeDelaySeconds = 10; + var writeBatchSize = 5; + var properties = new Dictionary { { "key1", "value1" }, { "key2", "value2" } }; + var initialLoadMode = LoadMode.Eager; + var writeCoalescing = true; + var offload = true; + + var mapStoreOptions = new MapStoreOptions + { + Enabled = enabled, + ClassName = className, + FactoryClassName = factoryClassName, + WriteDelaySeconds = writeDelaySeconds, + WriteBatchSize = writeBatchSize, + Properties = properties, + InitialLoadMode = initialLoadMode, + WriteCoalescing = writeCoalescing, + Offload = offload + }; + + var expectedString = $"MapStoreConfig{{enabled={enabled}, className='{className}', factoryClassName='{factoryClassName}', writeDelaySeconds={writeDelaySeconds}, writeBatchSize={writeBatchSize}, properties={properties}, initialLoadMode={initialLoadMode}, writeCoalescing={writeCoalescing}, offload={offload}}}"; + + Assert.AreEqual(expectedString, mapStoreOptions.ToString()); + } + } +} \ No newline at end of file diff --git a/src/Hazelcast.Net.Tests/Models/MergePolicyOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/MergePolicyOptionsTests.cs new file mode 100644 index 000000000..ecbab1979 --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/MergePolicyOptionsTests.cs @@ -0,0 +1,67 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using Hazelcast.Core; +using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Serialization; +using NSubstitute; + +namespace Hazelcast.Tests.Models +{ + [TestFixture] + public class MergePolicyOptionsTests + { + [Test] + public void Constructor_WithValidParameters_InitializesPropertiesCorrectly() + { + var policy = "TestPolicy"; + var batchSize = 200; + + var mergePolicyOptions = new MergePolicyOptions(policy, batchSize); + + Assert.AreEqual(policy, mergePolicyOptions.Policy); + Assert.AreEqual(batchSize, mergePolicyOptions.BatchSize); + } + + [Test] + public void WriteData_ReadData_WritesAndReadsDataCorrectly() + { + var policy = "TestPolicy"; + var batchSize = 200; + var mergePolicyOptions = new MergePolicyOptions(policy, batchSize); + + var output = new ObjectDataOutput(1024, null, Endianness.LittleEndian); + mergePolicyOptions.WriteData(output); + + var input = new ObjectDataInput(output.Buffer, null, Endianness.LittleEndian); + var readMergePolicyOptions = new MergePolicyOptions(); + readMergePolicyOptions.ReadData(input); + + Assert.AreEqual(mergePolicyOptions.Policy, readMergePolicyOptions.Policy); + Assert.AreEqual(mergePolicyOptions.BatchSize, readMergePolicyOptions.BatchSize); + } + + [Test] + public void ToString_ReturnsCorrectFormat() + { + var policy = "TestPolicy"; + var batchSize = 200; + var mergePolicyOptions = new MergePolicyOptions(policy, batchSize); + + var expectedString = $"MergePolicyConfig{{policy='{policy}', batchSize={batchSize}}}"; + + Assert.AreEqual(expectedString, mergePolicyOptions.ToString()); + } + } +} \ No newline at end of file diff --git a/src/Hazelcast.Net.Tests/Models/MerkleTreeOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/MerkleTreeOptionsTests.cs new file mode 100644 index 000000000..93cbd3b3b --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/MerkleTreeOptionsTests.cs @@ -0,0 +1,81 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using Hazelcast.Core; +using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Serialization; +using NSubstitute; + +namespace Hazelcast.Tests.Models +{ + [TestFixture] + public class MerkleTreeOptionsTests + { + [Test] + public void Constructor_WithValidParameters_InitializesPropertiesCorrectly() + { + var depth = 5; + var enabled = true; + + var merkleTreeOptions = new MerkleTreeOptions + { + Depth = depth, + Enabled = enabled + }; + + Assert.AreEqual(depth, merkleTreeOptions.Depth); + Assert.AreEqual(enabled, merkleTreeOptions.Enabled); + } + + [Test] + public void WriteData_ReadData_WritesAndReadsDataCorrectly() + { + var depth = 5; + var enabled = true; + + var merkleTreeOptions = new MerkleTreeOptions + { + Depth = depth, + Enabled = enabled + }; + + var output = new ObjectDataOutput(1024, null, Endianness.LittleEndian); + merkleTreeOptions.WriteData(output); + + var input = new ObjectDataInput(output.Buffer, null, Endianness.LittleEndian); + var readMerkleTreeOptions = new MerkleTreeOptions(); + readMerkleTreeOptions.ReadData(input); + + Assert.AreEqual(merkleTreeOptions.Depth, readMerkleTreeOptions.Depth); + Assert.AreEqual(merkleTreeOptions.Enabled, readMerkleTreeOptions.Enabled); + } + + [Test] + public void ToString_ReturnsCorrectFormat() + { + var depth = 5; + var enabled = true; + + var merkleTreeOptions = new MerkleTreeOptions + { + Depth = depth, + Enabled = enabled + }; + + var expectedString = $"MerkleTreeConfig{{enabled={enabled}, depth={depth}}}"; + + Assert.AreEqual(expectedString, merkleTreeOptions.ToString()); + } + } +} \ No newline at end of file diff --git a/src/Hazelcast.Net.Tests/Models/PartitioningAttributeOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/PartitioningAttributeOptionsTests.cs new file mode 100644 index 000000000..2577a81b3 --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/PartitioningAttributeOptionsTests.cs @@ -0,0 +1,61 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using Hazelcast.Core; +using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Serialization; +using NSubstitute; + +namespace Hazelcast.Tests.Models +{ + public class PartitioningAttributeOptionsTests + { + [Test] + public void Constructor_WithValidParameter_InitializesPropertiesCorrectly() + { + var attributeName = "TestAttribute"; + + var partitioningAttributeOptions = new PartitioningAttributeOptions(attributeName); + + Assert.AreEqual(attributeName, partitioningAttributeOptions.AttributeName); + } + + [Test] + public void WriteData_ReadData_WritesAndReadsDataCorrectly() + { + var attributeName = "TestAttribute"; + var partitioningAttributeOptions = new PartitioningAttributeOptions(attributeName); + + var output = new ObjectDataOutput(1024, null, Endianness.LittleEndian); + partitioningAttributeOptions.WriteData(output); + + var input = new ObjectDataInput(output.Buffer, null, Endianness.LittleEndian); + var readPartitioningAttributeOptions = new PartitioningAttributeOptions(); + readPartitioningAttributeOptions.ReadData(input); + + Assert.AreEqual(partitioningAttributeOptions.AttributeName, readPartitioningAttributeOptions.AttributeName); + } + + [Test] + public void ToString_ReturnsCorrectFormat() + { + var attributeName = "TestAttribute"; + var partitioningAttributeOptions = new PartitioningAttributeOptions(attributeName); + + var expectedString = $"PartitioningAttributeConfig{{attributeName='{attributeName}'}}"; + + Assert.AreEqual(expectedString, partitioningAttributeOptions.ToString()); + } + } +} \ No newline at end of file diff --git a/src/Hazelcast.Net.Tests/Models/PartitioningStrategyOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/PartitioningStrategyOptionsTests.cs new file mode 100644 index 000000000..78b1f93b3 --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/PartitioningStrategyOptionsTests.cs @@ -0,0 +1,81 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Hazelcast.Models; +using Hazelcast.Serialization; +using NUnit.Framework; +using NSubstitute; + +[TestFixture] +public class PartitioningStrategyOptionsTests +{ + [Test] + public void Constructor_WithNoArguments_SetsPartitioningStrategyClassToNull() + { + var options = new PartitioningStrategyOptions(); + + Assert.IsNull(options.PartitioningStrategyClass); + } + + [Test] + public void Constructor_WithPartitioningStrategyOptionsArgument_CopiesPartitioningStrategyClass() + { + var originalOptions = new PartitioningStrategyOptions { PartitioningStrategyClass = "OriginalClass" }; + var copiedOptions = new PartitioningStrategyOptions(originalOptions); + + Assert.AreEqual("OriginalClass", copiedOptions.PartitioningStrategyClass); + } + + [Test] + public void Constructor_WithStringArgument_SetsPartitioningStrategyClass() + { + var options = new PartitioningStrategyOptions("TestClass"); + + Assert.AreEqual("TestClass", options.PartitioningStrategyClass); + } + + [Test] + public void ToString_ReturnsExpectedFormat() + { + var options = new PartitioningStrategyOptions("TestClass"); + + var result = options.ToString(); + + StringAssert.Contains("partitioningStrategyClass='TestClass'", result); + StringAssert.Contains("partitioningStrategy=", result); + } + + [Test] + public void WriteData_WritesPartitioningStrategyClass() + { + var options = new PartitioningStrategyOptions("TestClass"); + var output = Substitute.For(); + + options.WriteData(output); + + output.Received().WriteString("TestClass"); + } + + [Test] + public void ReadData_ReadsPartitioningStrategyClass() + { + var options = new PartitioningStrategyOptions(); + var input = Substitute.For(); + input.ReadString().Returns("TestClass"); + + options.ReadData(input); + + Assert.AreEqual("TestClass", options.PartitioningStrategyClass); + } +} diff --git a/src/Hazelcast.Net.Tests/Models/QueryCacheOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/QueryCacheOptionsTests.cs new file mode 100644 index 000000000..dd9f90e74 --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/QueryCacheOptionsTests.cs @@ -0,0 +1,82 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +namespace Hazelcast.Tests.Models +{ + using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Core; +using Hazelcast.Configuration; + +[TestFixture] +public class QueryCacheOptionsTests +{ + [Test] + public void DefaultConstructor_SetsPropertiesToDefault() + { + var options = new QueryCacheOptions(); + + Assert.AreEqual(QueryCacheOptions.Defaults.BatchSize, options.BatchSize); + Assert.AreEqual(QueryCacheOptions.Defaults.BufferSize, options.BufferSize); + Assert.AreEqual(QueryCacheOptions.Defaults.DelaySeconds, options.DelaySeconds); + Assert.AreEqual(QueryCacheOptions.Defaults.IncludeValue, options.IncludeValue); + Assert.AreEqual(QueryCacheOptions.Defaults.Populate, options.Populate); + Assert.AreEqual(QueryCacheOptions.Defaults.Coalesce, options.Coalesce); + Assert.AreEqual(QueryCacheOptions.Defaults.SerializeKeys, options.SerializeKeys); + Assert.AreEqual(QueryCacheOptions.Defaults.InMemoryFormat, options.InMemoryFormat); + } + + [Test] + public void Constructor_WithName_SetsName() + { + var options = new QueryCacheOptions("TestName"); + + Assert.AreEqual("TestName", options.Name); + } + + [Test] + public void Constructor_WithQueryCacheOptionsArgument_CopiesProperties() + { + var originalOptions = new QueryCacheOptions("TestName"); + var copiedOptions = new QueryCacheOptions(originalOptions); + + Assert.AreEqual(originalOptions.Name, copiedOptions.Name); + Assert.AreEqual(originalOptions.BatchSize, copiedOptions.BatchSize); + Assert.AreEqual(originalOptions.BufferSize, copiedOptions.BufferSize); + Assert.AreEqual(originalOptions.DelaySeconds, copiedOptions.DelaySeconds); + Assert.AreEqual(originalOptions.IncludeValue, copiedOptions.IncludeValue); + Assert.AreEqual(originalOptions.Populate, copiedOptions.Populate); + Assert.AreEqual(originalOptions.Coalesce, copiedOptions.Coalesce); + Assert.AreEqual(originalOptions.SerializeKeys, copiedOptions.SerializeKeys); + Assert.AreEqual(originalOptions.InMemoryFormat, copiedOptions.InMemoryFormat); + } + + [Test] + public void ToString_ReturnsExpectedFormat() + { + var options = new QueryCacheOptions("TestName"); + + var result = options.ToString(); + + StringAssert.Contains("batchSize=", result); + StringAssert.Contains("bufferSize=", result); + StringAssert.Contains("delaySeconds=", result); + StringAssert.Contains("includeValue=", result); + StringAssert.Contains("populate=", result); + StringAssert.Contains("coalesce=", result); + StringAssert.Contains("serializeKeys=", result); + StringAssert.Contains("inMemoryFormat=", result); + StringAssert.Contains("name='TestName'", result); + } +} +} diff --git a/src/Hazelcast.Net.Tests/Models/RingbufferOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/RingbufferOptionsTests.cs new file mode 100644 index 000000000..3096cc998 --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/RingbufferOptionsTests.cs @@ -0,0 +1,73 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +namespace Hazelcast.Tests.Models +{ + using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Core; +using Hazelcast.Serialization; + +[TestFixture] +public class RingbufferOptionsTests +{ + [Test] + public void DefaultConstructor_SetsPropertiesToDefault() + { + var options = new RingbufferOptions(); + + Assert.AreEqual(RingbufferOptions.Defaults.Capacity, options.Capacity); + Assert.AreEqual(RingbufferOptions.Defaults.SyncBackupCount, options.BackupCount); + Assert.AreEqual(RingbufferOptions.Defaults.AsyncBackupCount, options.AsyncBackupCount); + Assert.AreEqual(RingbufferOptions.Defaults.TtlSeconds, options.TimeToLiveSeconds); + Assert.AreEqual(RingbufferOptions.Defaults.InMemoryFormat, options.InMemoryFormat); + } + + [Test] + public void Constructor_WithName_SetsName() + { + var options = new RingbufferOptions("TestName"); + + Assert.AreEqual("TestName", options.Name); + } + + [Test] + public void Constructor_WithRingbufferOptionsArgument_CopiesProperties() + { + var originalOptions = new RingbufferOptions("TestName"); + var copiedOptions = new RingbufferOptions(originalOptions); + + Assert.AreEqual(originalOptions.Name, copiedOptions.Name); + Assert.AreEqual(originalOptions.Capacity, copiedOptions.Capacity); + Assert.AreEqual(originalOptions.BackupCount, copiedOptions.BackupCount); + Assert.AreEqual(originalOptions.AsyncBackupCount, copiedOptions.AsyncBackupCount); + Assert.AreEqual(originalOptions.TimeToLiveSeconds, copiedOptions.TimeToLiveSeconds); + Assert.AreEqual(originalOptions.InMemoryFormat, copiedOptions.InMemoryFormat); + } + + [Test] + public void ToString_ReturnsExpectedFormat() + { + var options = new RingbufferOptions("TestName"); + + var result = options.ToString(); + + StringAssert.Contains("name='TestName'", result); + StringAssert.Contains("capacity=", result); + StringAssert.Contains("backupCount=", result); + StringAssert.Contains("asyncBackupCount=", result); + StringAssert.Contains("timeToLiveSeconds=", result); + StringAssert.Contains("inMemoryFormat=", result); + } +} +} diff --git a/src/Hazelcast.Net.Tests/Models/RingbufferStoreOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/RingbufferStoreOptionsTests.cs new file mode 100644 index 000000000..4727dccab --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/RingbufferStoreOptionsTests.cs @@ -0,0 +1,99 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Serialization; +using System.Collections.Generic; +using Hazelcast.Core; +using Hazelcast.Tests.Serialization.Compact; +using NSubstitute; + +namespace Hazelcast.Tests.Models +{ + [TestFixture] + public class RingbufferStoreOptionsTests + { + [Test] + public void Constructor_WithValidParameters_InitializesPropertiesCorrectly() + { + var enabled = true; + var className = "TestClassName"; + var factoryClassName = "TestFactoryClassName"; + var properties = new Dictionary { { "key1", "value1" }, { "key2", "value2" } }; + + var ringbufferStoreOptions = new RingbufferStoreOptions + { + Enabled = enabled, + ClassName = className, + FactoryClassName = factoryClassName, + Properties = properties + }; + + Assert.AreEqual(enabled, ringbufferStoreOptions.Enabled); + Assert.AreEqual(className, ringbufferStoreOptions.ClassName); + Assert.AreEqual(factoryClassName, ringbufferStoreOptions.FactoryClassName); + Assert.AreEqual(properties, ringbufferStoreOptions.Properties); + } + + [Test] + public void WriteData_ReadData_WritesAndReadsDataCorrectly() + { + var enabled = true; + var className = "TestClassName"; + var factoryClassName = "TestFactoryClassName"; + var properties = new Dictionary { { "key1", "value1" }, { "key2", "value2" } }; + + var ringbufferStoreOptions = new RingbufferStoreOptions + { + Enabled = enabled, + ClassName = className, + FactoryClassName = factoryClassName, + Properties = properties + }; + + var orw = Substitute.For(); + var output = new ObjectDataOutput(1024, orw, Endianness.LittleEndian); + ringbufferStoreOptions.WriteData(output); + + var input = new ObjectDataInput(output.Buffer, orw, Endianness.LittleEndian); + var readRingbufferStoreOptions = new RingbufferStoreOptions(); + readRingbufferStoreOptions.ReadData(input); + + Assert.AreEqual(ringbufferStoreOptions.Enabled, readRingbufferStoreOptions.Enabled); + Assert.AreEqual(ringbufferStoreOptions.ClassName, readRingbufferStoreOptions.ClassName); + Assert.AreEqual(ringbufferStoreOptions.FactoryClassName, readRingbufferStoreOptions.FactoryClassName); + } + + [Test] + public void ToString_ReturnsCorrectFormat() + { + var enabled = true; + var className = "TestClassName"; + var factoryClassName = "TestFactoryClassName"; + var properties = new Dictionary { { "key1", "value1" }, { "key2", "value2" } }; + + var ringbufferStoreOptions = new RingbufferStoreOptions + { + Enabled = enabled, + ClassName = className, + FactoryClassName = factoryClassName, + Properties = properties + }; + + var expectedString = $"RingbufferStoreConfig{{enabled={enabled}, className='{className}', factoryClassName='{factoryClassName}', properties={properties}}}"; + + Assert.AreEqual(expectedString, ringbufferStoreOptions.ToString()); + } + } +} \ No newline at end of file diff --git a/src/Hazelcast.Net.Tests/Models/TestOptionModelsTests.cs b/src/Hazelcast.Net.Tests/Models/TestOptionModelsTests.cs new file mode 100644 index 000000000..8556d6e42 --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/TestOptionModelsTests.cs @@ -0,0 +1,243 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using System; +using Hazelcast.Core; +using Hazelcast.Models; +using Hazelcast.NearCaching; +using Hazelcast.Serialization; +using Hazelcast.Tests.Serialization.Compact; +using NSubstitute; +using NUnit.Framework; +namespace Hazelcast.Tests.Models +{ + public class TestOptionModelsTests + { + [Test] + public void TestTimedExpiryPolicyFactoryOptions() + { + // Arrange + var expiryPolicyType = ExpiryPolicyType.Accessed; + var durationConfig = new DurationOptions(1, TimeUnit.Seconds); + var options = new TimedExpiryPolicyFactoryOptions(expiryPolicyType, durationConfig); + + // Act + var actualExpiryPolicyType = options.ExpiryPolicyType; + var actualDurationConfig = options.DurationConfig; + + // Assert + Assert.AreEqual(expiryPolicyType, actualExpiryPolicyType); + Assert.AreEqual(durationConfig.TimeUnit, actualDurationConfig.TimeUnit); + Assert.AreEqual(durationConfig.DurationAmount, actualDurationConfig.DurationAmount); + } + + [TestFixture] + public class MemoryUnitExtensionsTests + { + [Test] + public void TestToBytes() + { + // Arrange + var valueInKiloBytes = 5; + var expectedValueInBytes = 5 * 1000; + + // Act + var actualValueInBytes = MemoryUnitExtensions.Convert(MemoryUnit.Bytes, MemoryUnit.KiloBytes, valueInKiloBytes); + + // Assert + Assert.AreEqual(expectedValueInBytes, actualValueInBytes); + } + } + + [Test] + public void Abbrev_ShouldReturnCorrectAbbreviation() + { + Assert.AreEqual("B", MemoryUnit.Bytes.Abbrev()); + Assert.AreEqual("KB", MemoryUnit.KiloBytes.Abbrev()); + Assert.AreEqual("MB", MemoryUnit.MegaBytes.Abbrev()); + Assert.AreEqual("GB", MemoryUnit.GigaBytes.Abbrev()); + } + + [Test] + public void Abbrev_ShouldThrowExceptionForInvalidMemoryUnit() + { + Assert.Throws(() => ((MemoryUnit)999).Abbrev()); + } + + [Test] + public void TestCacheSimpleEntryListenerOptions() + { + // Arrange + var cacheEntryListenerFactory = "TestFactory"; + var cacheEntryEventFilterFactory = "TestFilterFactory"; + var oldValueRequired = true; + var synchronous = true; + + var options = new CacheSimpleEntryListenerOptions + { + CacheEntryListenerFactory = cacheEntryListenerFactory, + CacheEntryEventFilterFactory = cacheEntryEventFilterFactory, + OldValueRequired = oldValueRequired, + Synchronous = synchronous + }; + + // Act + var actualCacheEntryListenerFactory = options.CacheEntryListenerFactory; + var actualCacheEntryEventFilterFactory = options.CacheEntryEventFilterFactory; + var actualOldValueRequired = options.OldValueRequired; + var actualSynchronous = options.Synchronous; + + // Assert + Assert.AreEqual(cacheEntryListenerFactory, actualCacheEntryListenerFactory); + Assert.AreEqual(cacheEntryEventFilterFactory, actualCacheEntryEventFilterFactory); + Assert.AreEqual(oldValueRequired, actualOldValueRequired); + Assert.AreEqual(synchronous, actualSynchronous); + } + + [Test] + public void TestHotRestartOptions() + { + // Arrange + var enabled = true; + var fsync = true; + + var options = new HotRestartOptions + { + Enabled = enabled, + Fsync = fsync + }; + + // Act + var actualEnabled = options.Enabled; + var actualFsync = options.Fsync; + + // Assert + Assert.AreEqual(enabled, actualEnabled); + Assert.AreEqual(fsync, actualFsync); + } + + [Test] + public void TestPartitioningStrategyOptions() + { + // Arrange + var partitioningStrategyClass = "TestStrategyClass"; + + var options = new PartitioningStrategyOptions + { + PartitioningStrategyClass = partitioningStrategyClass + }; + + // Act + var actualPartitioningStrategyClass = options.PartitioningStrategyClass; + + // Assert + Assert.AreEqual(partitioningStrategyClass, actualPartitioningStrategyClass); + } + + [Test] + public void TestDataPersistenceOptions() + { + // Arrange + var enabled = true; + var fsync = true; + + var options = new DataPersistenceOptions + { + Enabled = enabled, + Fsync = fsync + }; + + // Act + var actualEnabled = options.Enabled; + var actualFsync = options.Fsync; + + // Assert + Assert.AreEqual(enabled, actualEnabled); + Assert.AreEqual(fsync, actualFsync); + } + + [Test] + public void TestReadDataAndWriteData() + { + + var eviction = new EvictionOptions { Size = 100, EvictionPolicy = EvictionPolicy.Lru }; + var preloader = new NearCachePreloaderOptions { Enabled = true, Directory = "TestDirectory", StoreInitialDelaySeconds = 5, StoreIntervalSeconds = 10 }; + // Arrange + var originalOptions = new NearCacheOptions + { + Name = "Test", + InvalidateOnChange = true, + TimeToLiveSeconds = 60, + MaxIdleSeconds = 30, + InMemoryFormat = InMemoryFormat.Binary, + LocalUpdatePolicy = UpdatePolicy.Invalidate, + Eviction = eviction, + Preloader = preloader + }; + + var orw = Substitute.For(); + orw.Read(Arg.Any()).Returns(eviction); + orw.Read(Arg.Any()).Returns(preloader); + + var output = new ObjectDataOutput(1000, orw, Endianness.LittleEndian); + var input = new ObjectDataInput(output.Buffer, orw, Endianness.LittleEndian); + + // Act + originalOptions.WriteData(output); + var newOptions = new NearCacheOptions(); + newOptions.ReadData(input); + + // Assert + Assert.AreEqual(originalOptions.Name, newOptions.Name); + Assert.AreEqual(originalOptions.InvalidateOnChange, newOptions.InvalidateOnChange); + Assert.AreEqual(originalOptions.TimeToLiveSeconds, newOptions.TimeToLiveSeconds); + Assert.AreEqual(originalOptions.MaxIdleSeconds, newOptions.MaxIdleSeconds); + Assert.AreEqual(originalOptions.InMemoryFormat, newOptions.InMemoryFormat); + Assert.AreEqual(originalOptions.LocalUpdatePolicy, newOptions.LocalUpdatePolicy); + Assert.AreEqual(originalOptions.Eviction.Size, newOptions.Eviction.Size); + Assert.AreEqual(originalOptions.Eviction.EvictionPolicy, newOptions.Eviction.EvictionPolicy); + Assert.AreEqual(originalOptions.Preloader.Enabled, newOptions.Preloader.Enabled); + Assert.AreEqual(originalOptions.Preloader.Directory, newOptions.Preloader.Directory); + Assert.AreEqual(originalOptions.Preloader.StoreInitialDelaySeconds, newOptions.Preloader.StoreInitialDelaySeconds); + Assert.AreEqual(originalOptions.Preloader.StoreIntervalSeconds, newOptions.Preloader.StoreIntervalSeconds); + } + + [Test] + public void ReadDataAndWriteData_ShouldPreserveState() + { + // Arrange + var originalOptions = new NearCachePreloaderOptions + { + Enabled = true, + Directory = "TestDirectory", + StoreInitialDelaySeconds = 5, + StoreIntervalSeconds = 10 + }; + + var orw = Substitute.For(); + var output = new ObjectDataOutput(1000, orw, Endianness.LittleEndian); + var input = new ObjectDataInput(output.Buffer, orw, Endianness.LittleEndian); + + // Act + originalOptions.WriteData(output); + var newOptions = new NearCachePreloaderOptions(); + newOptions.ReadData(input); + + // Assert + Assert.AreEqual(originalOptions.Enabled, newOptions.Enabled); + Assert.AreEqual(originalOptions.Directory, newOptions.Directory); + Assert.AreEqual(originalOptions.StoreInitialDelaySeconds, newOptions.StoreInitialDelaySeconds); + Assert.AreEqual(originalOptions.StoreIntervalSeconds, newOptions.StoreIntervalSeconds); + } + } +} diff --git a/src/Hazelcast.Net.Tests/Models/TieredStoreOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/TieredStoreOptionsTests.cs new file mode 100644 index 000000000..eb98aa19e --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/TieredStoreOptionsTests.cs @@ -0,0 +1,68 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +namespace Hazelcast.Tests.Models +{ +using NUnit.Framework; +using Hazelcast.Models; +using Hazelcast.Core; +using Hazelcast.Serialization; + +[TestFixture] +public class TieredStoreOptionsTests +{ + [Test] + public void DefaultConstructor_SetsPropertiesToDefault() + { + var options = new TieredStoreOptions(); + + Assert.IsFalse(options.Enabled); + Assert.IsNotNull(options.MemoryTier); + Assert.IsNotNull(options.DiskTier); + } + + [Test] + public void Constructor_WithTieredStoreOptionsArgument_CopiesProperties() + { + var originalOptions = new TieredStoreOptions + { + Enabled = true, + MemoryTier = new MemoryTierOptions(), + DiskTier = new DiskTierOptions() + }; + var copiedOptions = new TieredStoreOptions(originalOptions); + + Assert.AreEqual(originalOptions.Enabled, copiedOptions.Enabled); + Assert.AreEqual(originalOptions.MemoryTier.Capacity, copiedOptions.MemoryTier.Capacity); + Assert.AreEqual(originalOptions.DiskTier.DeviceName, copiedOptions.DiskTier.DeviceName); + Assert.AreEqual(originalOptions.DiskTier.Enabled, copiedOptions.DiskTier.Enabled); + } + + [Test] + public void ToString_ReturnsExpectedFormat() + { + var options = new TieredStoreOptions + { + Enabled = true, + MemoryTier = new MemoryTierOptions(), + DiskTier = new DiskTierOptions() + }; + + var result = options.ToString(); + + StringAssert.Contains("enabled=True", result); + StringAssert.Contains("memoryTierConfig=", result); + StringAssert.Contains("diskTierConfig=", result); + } +} +} diff --git a/src/Hazelcast.Net.Tests/Models/TimedExpiryPolicyFactoryOptionsTests.cs b/src/Hazelcast.Net.Tests/Models/TimedExpiryPolicyFactoryOptionsTests.cs new file mode 100644 index 000000000..a767e7493 --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/TimedExpiryPolicyFactoryOptionsTests.cs @@ -0,0 +1,83 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using Hazelcast.Core; +using Hazelcast.Models; +using Hazelcast.Serialization; +namespace Hazelcast.Tests.Models +{ + using NUnit.Framework; + using NSubstitute; + + [TestFixture] + public class TimedExpiryPolicyFactoryOptionsTests + { + [Test] + public void DefaultConstructor_SetsPropertiesToDefault() + { + var options = new TimedExpiryPolicyFactoryOptions(); + + Assert.AreEqual(ExpiryPolicyType.Created, options.ExpiryPolicyType); + } + + [Test] + public void Constructor_WithArguments_SetsProperties() + { + var durationConfig = new DurationOptions(); + var options = new TimedExpiryPolicyFactoryOptions(ExpiryPolicyType.Created, durationConfig); + + Assert.AreEqual(ExpiryPolicyType.Created, options.ExpiryPolicyType); + Assert.AreEqual(durationConfig, options.DurationConfig); + } + + [Test] + public void WriteData_WritesProperties() + { + var output = Substitute.For(); + var durationConfig = new DurationOptions(); + var options = new TimedExpiryPolicyFactoryOptions(ExpiryPolicyType.Created, durationConfig); + + options.WriteData(output); + + output.Received().WriteString(ExpiryPolicyType.Created.ToJavaString()); + output.Received().WriteObject(durationConfig); + } + + [Test] + public void ReadData_ReadsProperties() + { + var input = Substitute.For(); + var options = new TimedExpiryPolicyFactoryOptions(); + + input.ReadString().Returns(ExpiryPolicyType.Created.ToJavaString()); + input.ReadObject().Returns(new DurationOptions()); + + options.ReadData(input); + + Assert.AreEqual(ExpiryPolicyType.Created, options.ExpiryPolicyType); + Assert.IsNotNull(options.DurationConfig); + } + + [Test] + public void ToString_ReturnsExpectedFormat() + { + var durationConfig = new DurationOptions(); + var options = new TimedExpiryPolicyFactoryOptions(ExpiryPolicyType.Created, durationConfig); + + var result = options.ToString(); + + StringAssert.Contains("expiryPolicyType=Created", result); + StringAssert.Contains("durationConfig=", result); + } + } +} diff --git a/src/Hazelcast.Net.Tests/Models/WanReplicationRefTests.cs b/src/Hazelcast.Net.Tests/Models/WanReplicationRefTests.cs new file mode 100644 index 000000000..af958c24c --- /dev/null +++ b/src/Hazelcast.Net.Tests/Models/WanReplicationRefTests.cs @@ -0,0 +1,63 @@ +// Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using System.Collections.Generic; +using Hazelcast.Models; +using NUnit.Framework; +namespace Hazelcast.Tests.Models +{ + public class WanReplicationRefTests + { + [Test] + public void Constructor_WithValidParameters_InitializesPropertiesCorrectly() + { + var name = "TestName"; + var mergePolicyClassName = "MergePolicy"; + var filters = new List { "Filter1", "Filter2" }; + var republishingEnabled = true; + + var wanReplicationRef = new WanReplicationRef(name, mergePolicyClassName, filters, republishingEnabled); + + Assert.AreEqual(name, wanReplicationRef.Name); + Assert.AreEqual(mergePolicyClassName, wanReplicationRef.MergePolicyClassName); + Assert.AreEqual(filters, wanReplicationRef.Filters); + Assert.AreEqual(republishingEnabled, wanReplicationRef.RepublishingEnabled); + } + + [Test] + public void AddFilter_WithValidFilter_AddsFilterToList() + { + var wanReplicationRef = new WanReplicationRef(); + var filter = "TestFilter"; + + wanReplicationRef.AddFilter(filter); + + Assert.Contains(filter, wanReplicationRef.Filters); + } + + + [Test] + public void ToString_ReturnsCorrectFormat() + { + var name = "TestName"; + var mergePolicyClassName = "MergePolicy"; + var filters = new List { "Filter1", "Filter2" }; + var republishingEnabled = true; + var wanReplicationRef = new WanReplicationRef(name, mergePolicyClassName, filters, republishingEnabled); + + var expectedString = $"WanReplicationRef{{name='{name}', mergePolicy='{mergePolicyClassName}', filters='{string.Join(",", filters)}', republishingEnabled='{republishingEnabled}'}}"; + + Assert.AreEqual(expectedString, wanReplicationRef.ToString()); + } + } +} diff --git a/src/Hazelcast.Net/Models/QueryCacheOptions.cs b/src/Hazelcast.Net/Models/QueryCacheOptions.cs index fc7778f7a..adcd3267f 100644 --- a/src/Hazelcast.Net/Models/QueryCacheOptions.cs +++ b/src/Hazelcast.Net/Models/QueryCacheOptions.cs @@ -99,7 +99,7 @@ public QueryCacheOptions() /// public QueryCacheOptions(string name) { - name = name; + _name = name; } ///