Skip to content

Commit

Permalink
Apply IDE0300 & IDE0028 on Garnet.test (#295)
Browse files Browse the repository at this point in the history
* Apply IDE0300 to Garnet.test: Collection initialization can be simplified

* Apply IDE0028 to Garnet.test: Collection initialization can be simplified

* Simplify GetSigned in GarnetBitmapTests

* This table is unnecessary

* Also it resulted the dotnet format bug

* dotnet format

---------

Co-authored-by: Tal Zaccai <talzacc@microsoft.com>
  • Loading branch information
PaulusParssinen and TalZaccai committed Apr 23, 2024
1 parent c140aa1 commit 06eb6f8
Show file tree
Hide file tree
Showing 25 changed files with 383 additions and 375 deletions.
6 changes: 3 additions & 3 deletions test/Garnet.test/CacheSizeTrackerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void HeapSizeValidationTest()

using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig());
var db = redis.GetDatabase(0);
db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Faster") });
db.HashSet("user:user1", [new HashEntry("Title", "Faster")]);
string r = db.HashGet("user:user1", "Title");
Assert.AreEqual("Faster", r);

Expand All @@ -60,7 +60,7 @@ public void IncreaseEmptyPageCountTest()

using var redis = ConnectionMultiplexer.Connect(TestUtils.GetConfig());
var db = redis.GetDatabase(0);
db.HashSet("user:user1", new HashEntry[] { new HashEntry("Title", "Faster") });
db.HashSet("user:user1", [new HashEntry("Title", "Faster")]);
string r = db.HashGet("user:user1", "Title");
Assert.AreEqual("Faster", r);

Expand All @@ -70,7 +70,7 @@ public void IncreaseEmptyPageCountTest()
// Have enough records (24 bytes each) to cross a page boundary (512)
for (int i = 2; i <= 24; i++)
{
db.HashSet($"user:user{i}", new HashEntry[] { new HashEntry("Title", "Faster") });
db.HashSet($"user:user{i}", [new HashEntry("Title", "Faster")]);
}

Assert.AreEqual(5952, cacheSizeTracker.mainLogTracker.LogHeapSizeBytes); // 24 * 248 for each hashset object
Expand Down
50 changes: 21 additions & 29 deletions test/Garnet.test/GarnetBitmapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void BitmapSetGetBitTest_LTM(bool preSet)
int keyCount = 8;
int keyIter = 256;
byte[] bitmap = new byte[bitmapBytes];
Dictionary<int, Dictionary<long, bool>> state = new Dictionary<int, Dictionary<long, bool>>();
Dictionary<int, Dictionary<long, bool>> state = [];

if (preSet)
{
Expand Down Expand Up @@ -213,7 +213,7 @@ public void BitmapSetGetBitTest_LTM(bool preSet)
}
else
{
state.Add(key, new Dictionary<long, bool>());
state.Add(key, []);
state[key].Add(offset, set);
}

Expand Down Expand Up @@ -312,7 +312,7 @@ public void BitmapBitCountBetweenOffsetsTest()
int maxBitmapLen = 1 << 12;
int iter = 1024;

List<long> offsets = new List<long>();
List<long> offsets = [];
long maxOffset = 0;
for (int i = 0; i < iter; i++)
{
Expand Down Expand Up @@ -456,7 +456,7 @@ public void BitmapBitCountTest_LTM()

int keyCount = 64;
byte[] bitmap = new byte[bitmapBytes];
List<long> bitmapList = new List<long>();
List<long> bitmapList = [];

for (int i = 0; i < keyCount; i++)
{
Expand Down Expand Up @@ -653,7 +653,7 @@ public void BitmapBitPosTest_LTM()

int keyCount = 64;
byte[] bitmap = new byte[bitmapBytes];
List<long> bitmapList = new List<long>();
List<long> bitmapList = [];

for (int i = 0; i < keyCount; i++)
{
Expand Down Expand Up @@ -738,8 +738,8 @@ public unsafe void BitmapSimpleBITOP_PCT(int bytesPerSend)

//Test AND, OR, XOR
long srcA, srcB, srcC;
RedisKey[] keys = new RedisKey[] { a, b, c };
Bitwise[] bitwiseOps = new Bitwise[] { Bitwise.And, Bitwise.Or, Bitwise.Xor };
RedisKey[] keys = [a, b, c];
Bitwise[] bitwiseOps = [Bitwise.And, Bitwise.Or, Bitwise.Xor];
for (int j = 0; j < bitwiseOps.Length; j++)
{
for (int i = 0; i < tests; i++)
Expand Down Expand Up @@ -820,8 +820,8 @@ public void BitmapSimpleBitOpTests()

//Test AND, OR, XOR
long srcA, srcB, srcC;
RedisKey[] keys = new RedisKey[] { a, b, c };
Bitwise[] bitwiseOps = new Bitwise[] { Bitwise.And, Bitwise.Or, Bitwise.Xor };
RedisKey[] keys = [a, b, c];
Bitwise[] bitwiseOps = [Bitwise.And, Bitwise.Or, Bitwise.Xor];
for (int j = 0; j < bitwiseOps.Length; j++)
{
for (int i = 0; i < tests; i++)
Expand Down Expand Up @@ -904,8 +904,8 @@ public void BitmapSimpleVarLenBitOpTests()
string d = "d";
string x = "x";

RedisKey[] keys = new RedisKey[] { a, b, c, d };
Bitwise[] bitwiseOps = new Bitwise[] { Bitwise.And, Bitwise.Or, Bitwise.Xor, Bitwise.And, Bitwise.Or, Bitwise.Xor };
RedisKey[] keys = [a, b, c, d];
Bitwise[] bitwiseOps = [Bitwise.And, Bitwise.Or, Bitwise.Xor, Bitwise.And, Bitwise.Or, Bitwise.Xor];

int maxBytes = 512;
byte[] dataA = new byte[r.Next(1, maxBytes)];
Expand Down Expand Up @@ -1016,8 +1016,8 @@ public void BitmapSimpleBitOpVarLenGrowingSizeTests()
byte[] dataA, dataB, dataC, dataD;
byte[] dataX;
int minSize = 512;
Bitwise[] bitwiseOps = new Bitwise[] { Bitwise.And, Bitwise.Or, Bitwise.Xor, Bitwise.And, Bitwise.Or, Bitwise.Xor };
RedisKey[] keys = new RedisKey[] { a, b, c, d };
Bitwise[] bitwiseOps = [Bitwise.And, Bitwise.Or, Bitwise.Xor, Bitwise.And, Bitwise.Or, Bitwise.Xor];
RedisKey[] keys = [a, b, c, d];

//Test NOT
for (int i = 0; i < tests; i++)
Expand Down Expand Up @@ -1094,7 +1094,7 @@ private long GetValueFromBitmap(ref byte[] bitmap, long offset, int bitCount, bo
long indexBit = 0;
long value = 0;
int bI = 63;
byte[] si = { 1, 2, 4, 8, 16, 32, 64, 128 };
byte[] si = [1, 2, 4, 8, 16, 32, 64, 128];
while (indexBit < (bitmap.Length << 3))
{
for (int i = 7; i >= 0; i--)
Expand Down Expand Up @@ -1148,19 +1148,11 @@ private long getSigned(ref byte[] bitmap, ulong offset, ulong bits)
{
ulong value = getUnsigned(ref bitmap, offset, bits);

ulong[] si = {
1L << 0, 1L << 1, 1L << 2, 1L << 3, 1L << 4, 1L << 5, 1L << 6, 1L << 7,//0
1L << 8, 1L << 9, 1L << 10, 1L << 11, 1L << 12, 1L << 13, 1L << 14, 1L << 15,//1
1L << 16, 1L << 17, 1L << 18, 1L << 19, 1L << 20, 1L << 21, 1L << 22, 1L << 23,//2
1L << 24, 1L << 25, 1L << 26, 1L << 27, 1L << 28, 1L << 29, 1L << 30, 1L << 31,//3
1L << 32, 1L << 33, 1L << 34, 1L << 35, 1L << 36, 1L << 37, 1L << 38, 1L << 39,//4
1L << 40, 1L << 41, 1L << 42, 1L << 43, 1L << 44, 1L << 45, 1L << 46, 1L << 47,//5
1L << 48, 1L << 49, 1L << 50, 1L << 51, 1L << 52, 1L << 53, 1L << 54, 1L << 55,//6
1L << 56, 1L << 57, 1L << 58, 1L << 59, 1L << 60, 1L << 61, 1L << 62, (ulong)1 << 63,//7
};

if (bits < 64 && ((value & si[bits - 1]) > 0))
value |= (~(ulong)0) << ((byte)bits);
if (bits < 64 && (value & (1UL << (int)(bits - 1))) != 0)
{
value |= ulong.MaxValue << (byte)bits;
}

return (long)value;
}

Expand Down Expand Up @@ -2098,7 +2090,7 @@ public void BitmapBitfieldGrowingTest()
for (int j = 1; j <= 64; j++)
{
db.KeyDelete(key);
List<long> values = new List<long>();
List<long> values = [];
bitCount = j;
for (int i = 0; i < tests; i++)
{
Expand Down Expand Up @@ -2174,7 +2166,7 @@ public void BitmapBitfieldGrowingTest()
for (int j = 1; j <= 64; j++)
{
bitCount = j;
List<long> values = new List<long>();
List<long> values = [];

db.KeyDelete(key);
for (int i = 0; i < tests; i++)
Expand Down
19 changes: 8 additions & 11 deletions test/Garnet.test/GarnetClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ public async Task SimpleStringArrayTest([Values] bool stringParams)
db.Connect();

long n = stringParams ?
int.Parse(await db.ExecuteForStringResultAsync("INCRBY", new string[] { "myKey", "10" })) :
int.Parse(await db.ExecuteForStringResultAsync(Encoding.ASCII.GetBytes("$6\r\nINCRBY\r\n"), new Memory<byte>[] { Encoding.ASCII.GetBytes("myKey"), Encoding.ASCII.GetBytes("10") }));
int.Parse(await db.ExecuteForStringResultAsync("INCRBY", ["myKey", "10"])) :
int.Parse(await db.ExecuteForStringResultAsync(Encoding.ASCII.GetBytes("$6\r\nINCRBY\r\n"), [Encoding.ASCII.GetBytes("myKey"), Encoding.ASCII.GetBytes("10")]));

Assert.AreEqual(10, n);
}
Expand Down Expand Up @@ -342,10 +342,10 @@ public async Task CanUseSetNxStringResultAsync()
var db = TestUtils.GetGarnetClient();
db.Connect();

var result = await db.ExecuteForStringResultAsync("SET", new string[] { "mykey", "Hello", "NX" });
var result = await db.ExecuteForStringResultAsync("SET", ["mykey", "Hello", "NX"]);
Assert.AreEqual("OK", result);

result = await db.ExecuteForStringResultAsync("SET", new string[] { "mykey", "World", "NX" });
result = await db.ExecuteForStringResultAsync("SET", ["mykey", "World", "NX"]);
Assert.AreEqual(null, result);

var resultMykey = await db.StringGetAsync("mykey");
Expand All @@ -366,7 +366,7 @@ public async Task CanUseMGetTests([Values] bool disableObjectStore)

for (int i = 0; i < nKeys; i++)
{
var result = await db.ExecuteForStringResultAsync("SET", new string[] { worldcities[i, 1], worldcities[i, 0] });
var result = await db.ExecuteForStringResultAsync("SET", [worldcities[i, 1], worldcities[i, 0]]);
keys[i] = worldcities[i, 1];
keysMemory[i] = Encoding.ASCII.GetBytes(keys[i]);
Assert.AreEqual("OK", result);
Expand Down Expand Up @@ -477,7 +477,7 @@ public async Task CanDoBulkDeleteTests([Values] bool useStringType)
for (int i = 0; i < nKeys; i++)
{
// create in the main store
var result = await db.ExecuteForStringResultAsync("SET", new string[] { worldcities[i, 1], worldcities[i, 0] });
var result = await db.ExecuteForStringResultAsync("SET", [worldcities[i, 1], worldcities[i, 0]]);
keys[i] = worldcities[i, 1];
keysMemoryByte[i] = Encoding.ASCII.GetBytes(keys[i]);
Assert.AreEqual("OK", result);
Expand All @@ -486,10 +486,7 @@ public async Task CanDoBulkDeleteTests([Values] bool useStringType)
for (int x = 0; x < nKeysObjectStore; x++)
{
// create in the object store
List<string> parameters = new();
parameters = new List<string>();
parameters.AddRange(new string[] { $"myzset{x}", "1", "KEY1", "2", "KEY2" });
var result = await db.ExecuteForStringResultAsync("ZADD", parameters);
var result = await db.ExecuteForStringResultAsync("ZADD", [$"myzset{x}", "1", "KEY1", "2", "KEY2"]);
Assert.AreEqual("2", result);
keys[nKeys + x] = $"myzset{x}";
keysMemoryByte[nKeys + x] = Encoding.ASCII.GetBytes(keys[nKeys + x]);
Expand Down Expand Up @@ -553,7 +550,7 @@ public async Task CanDoBulkDeleteTests([Values] bool useStringType)
//check that none of the keys exist
foreach (var key in keys)
{
var result = await db.ExecuteForStringResultAsync("EXISTS", new string[] { key });
var result = await db.ExecuteForStringResultAsync("EXISTS", [key]);
Assert.AreEqual("0", result);
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/Garnet.test/GarnetObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task WriteCheckpointRead()

var key = new byte[] { 0 };
var obj = new SortedSetObject();
obj.Add(new byte[] { 15 }, 10);
obj.Add([15], 10);

session.Upsert(key, obj);

Expand Down Expand Up @@ -86,7 +86,7 @@ public async Task CopyUpdate()

var key = new byte[] { 0 };
IGarnetObject obj = new SortedSetObject();
((SortedSetObject)obj).Add(new byte[] { 15 }, 10);
((SortedSetObject)obj).Add([15], 10);

session.Upsert(key, obj);

Expand Down
12 changes: 6 additions & 6 deletions test/Garnet.test/GarnetServerConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void DefaultConfigurationOptionsCoverage()
}
}
// Deserialize default.conf to get all defined default options
Dictionary<string, string> jsonSettings = new Dictionary<string, string>();
Dictionary<string, string> jsonSettings = [];
try
{
jsonSettings = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
Expand Down Expand Up @@ -95,7 +95,7 @@ public void ImportExportConfigLocal()

// Import from previous export command, no command line args
// Check values from import path override values from default.conf
args = new string[] { "--config-import-path", configPath };
args = ["--config-import-path", configPath];
parseSuccessful = ServerSettingsManager.TryParseCommandLineArguments(args, out options, out invalidOptions);
Assert.IsTrue(parseSuccessful);
Assert.AreEqual(invalidOptions.Count, 0);
Expand All @@ -104,7 +104,7 @@ public void ImportExportConfigLocal()

// Import from previous export command, include command line args, export to file
// Check values from import path override values from default.conf, and values from command line override values from default.conf and import path
args = new string[] { "--config-import-path", configPath, "-p", "12m", "-s", "1g", "--recover", "false", "--port", "0", "--no-obj", "--aof" };
args = ["--config-import-path", configPath, "-p", "12m", "-s", "1g", "--recover", "false", "--port", "0", "--no-obj", "--aof"];
parseSuccessful = ServerSettingsManager.TryParseCommandLineArguments(args, out options, out invalidOptions);
Assert.IsTrue(parseSuccessful);
Assert.AreEqual(invalidOptions.Count, 0);
Expand All @@ -118,7 +118,7 @@ public void ImportExportConfigLocal()

// No import path, include command line args
// Check that all invalid options flagged
args = new string[] { "--bind", "1.1.1.257", "-m", "12mg", "--port", "-1", "--mutable-percent", "101", "--acl-file", "nx_dir/nx_file.txt", "--tls", "--reviv-fraction", "1.1", "--cert-file-name", "testcert.crt" };
args = ["--bind", "1.1.1.257", "-m", "12mg", "--port", "-1", "--mutable-percent", "101", "--acl-file", "nx_dir/nx_file.txt", "--tls", "--reviv-fraction", "1.1", "--cert-file-name", "testcert.crt"];
parseSuccessful = ServerSettingsManager.TryParseCommandLineArguments(args, out options, out invalidOptions);
Assert.IsFalse(parseSuccessful);
Assert.IsNull(options);
Expand Down Expand Up @@ -167,7 +167,7 @@ public void ImportExportRedisConfigLocal()

// Import from redis.conf file, include command line args
// Check values from import path override values from default.conf, and values from command line override values from default.conf and import path
args = new[] { "--config-import-path", redisConfigPath, "--config-import-format", "RedisConf", "--config-export-path", garnetConfigPath, "-p", "12m", "--tls", "false", "--minthreads", "6", "--client-certificate-required", "true" };
args = ["--config-import-path", redisConfigPath, "--config-import-format", "RedisConf", "--config-export-path", garnetConfigPath, "-p", "12m", "--tls", "false", "--minthreads", "6", "--client-certificate-required", "true"];
parseSuccessful = ServerSettingsManager.TryParseCommandLineArguments(args, out options, out invalidOptions);
Assert.IsTrue(parseSuccessful);
Assert.AreEqual(invalidOptions.Count, 0);
Expand Down Expand Up @@ -210,7 +210,7 @@ public void ImportExportConfigAzure()
Assert.IsTrue(options.PageSize == "4m");
Assert.IsTrue(options.MemorySize == "8g");

args = new string[] { "--storage-string", AzureEmulatedStorageString, "--use-azure-storage-for-config-import", "true", "--config-import-path", configPath };
args = ["--storage-string", AzureEmulatedStorageString, "--use-azure-storage-for-config-import", "true", "--config-import-path", configPath];
parseSuccessful = ServerSettingsManager.TryParseCommandLineArguments(args, out options, out invalidOptions);
Assert.IsTrue(parseSuccessful);
Assert.AreEqual(invalidOptions.Count, 0);
Expand Down

0 comments on commit 06eb6f8

Please sign in to comment.