Skip to content

Commit

Permalink
CLIENT-2184 test ordered maps expression
Browse files Browse the repository at this point in the history
* Add test for ordered map with expression

* Update copyright year
  • Loading branch information
shannonklaus authored Mar 28, 2023
1 parent 1fe79a7 commit f449c65
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 9 deletions.
16 changes: 12 additions & 4 deletions AerospikeClient/Exp/Exp.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 Aerospike, Inc.
* Copyright 2012-2023 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
Expand Down Expand Up @@ -537,9 +537,9 @@ public static Exp Val(IList list)
/// <summary>
/// Create map value.
/// </summary>
public static Exp Val(IDictionary map)
public static Exp Val(IDictionary map, MapOrder order)
{
return new MapVal(map);
return new MapVal(map, order);
}

/// <summary>
Expand Down Expand Up @@ -1653,15 +1653,23 @@ public override void Pack(Packer packer)
private sealed class MapVal : Exp
{
internal readonly IDictionary map;
internal readonly MapOrder order;

internal MapVal(IDictionary map)
{
this.map = map;
this.order = MapOrder.UNORDERED;
}

internal MapVal(IDictionary map, MapOrder order)
{
this.map = map;
this.order = order;
}

public override void Pack(Packer packer)
{
packer.PackMap(map);
packer.PackMap(map, order);
}
}

Expand Down
78 changes: 78 additions & 0 deletions AerospikeTest/Sync/Basic/TestMapExp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2012-2023 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
*
* 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 System.Collections;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Aerospike.Client;
using System.Diagnostics;

namespace Aerospike.Test
{
[TestClass]
public class TestMapExp : TestSync
{
private bool InstanceFieldsInitialized = false;

public TestMapExp()
{
if (!InstanceFieldsInitialized)
{
InitializeInstanceFields();
InstanceFieldsInitialized = true;
}
}

private void InitializeInstanceFields()
{
key = new Key(args.ns, args.set, bin);
}

private string bin = "m";

private Key key;

private Policy policy;

[TestInitialize()]
public void SetUp()
{
client.Delete(null, key);
policy = new Policy();
}

[TestMethod]
public void PutSortedDictionary()
{
var map = new SortedDictionary<string, string>();
map["key1"] = "e";
map["key2"] = "d";
map["key3"] = "c";
map["key4"] = "b";
map["key5"] = "a";

client.Operate(null, key,
MapOperation.PutItems(new MapPolicy(MapOrder.KEY_ORDERED, MapWriteFlags.DEFAULT), bin, map)
);

policy.filterExp = Exp.Build(Exp.EQ(Exp.MapBin("m"), Exp.Val(map, MapOrder.KEY_ORDERED)));

Record record = client.Get(policy, key, bin);
AssertRecordFound(key, record);
}
}
}
8 changes: 3 additions & 5 deletions AerospikeTest/Sync/Basic/TestOperateMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@ public void OperateMapPutItems()
MapOperation.PutItems(updateMode, binName, replaceMap),
MapOperation.GetByKey(binName, Value.Get(1), MapReturnType.VALUE),
MapOperation.GetByKey(binName, Value.Get(-8734), MapReturnType.VALUE),
MapOperation.GetByKeyRange(binName, Value.Get(12), Value.Get(15), MapReturnType.KEY_VALUE)
/* Enable when server 6.3 is released.
MapOperation.GetByKeyRange(binName, Value.Get(12), Value.Get(15), MapReturnType.KEY_VALUE),
MapOperation.GetByKeyRange(binName, Value.Get(12), Value.Get(15), MapReturnType.UNORDERED_MAP),
MapOperation.GetByKeyRange(binName, Value.Get(12), Value.Get(15), MapReturnType.ORDERED_MAP)
*/

);

AssertRecordFound(key, record);
Expand Down Expand Up @@ -147,15 +146,14 @@ public void OperateMapPutItems()
IList list = (IList)results[i++];
Assert.AreEqual(2, list.Count);

/* Enable when server 6.3 is released.
IDictionary dict = (IDictionary)results[i++];
Assert.AreEqual(2, dict.Count);
Assert.IsTrue(dict is Dictionary<object, object>);

dict = (IDictionary)results[i++];
Assert.AreEqual(2, dict.Count);
Assert.IsTrue(dict is SortedDictionary<object, object>);
*/

}

[TestMethod]
Expand Down

0 comments on commit f449c65

Please sign in to comment.