You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2017/08/11 23:53:00 UTC
[44/52] [partial] geode-native git commit: GEODE-3165: Reogranized
sources relative to the root for better CMake IDE integration.
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/DistOpsTests.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/DistOpsTests.cs b/clicache/integration-test/DistOpsTests.cs
new file mode 100644
index 0000000..ae6ac4c
--- /dev/null
+++ b/clicache/integration-test/DistOpsTests.cs
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.Threading;
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+
+ [TestFixture]
+ public class DistOpsTests : DistOpsSteps
+ {
+ #region Private statics/constants and members
+
+ private static string[] AckRegionNames = { "DistRegionAck1", "DistRegionNoAck1" };
+ private static string[] ILRegionNames = { "IL_DistRegionAck", "IL_DistRegionNoAck" };
+
+ private UnitProcess m_client1, m_client2, m_client3;
+
+ #endregion
+
+ protected override ClientBase[] GetClients()
+ {
+ m_client1 = new UnitProcess();
+ m_client2 = new UnitProcess();
+ m_client3 = new UnitProcess();
+ return new ClientBase[] { m_client1, m_client2, m_client3 };
+ }
+
+ [Test]
+ public void DistOps()
+ {
+ m_client1.Call(CreateRegions, AckRegionNames);
+ Util.Log("StepOne complete.");
+
+ m_client2.Call(CreateRegions, AckRegionNames);
+ Util.Log("StepTwo complete.");
+
+ m_client1.Call(StepThree);
+ Util.Log("StepThree complete.");
+
+ m_client2.Call(StepFour);
+ Util.Log("StepFour complete.");
+
+ m_client1.Call(StepFive, true);
+ Util.Log("StepFive complete.");
+
+ Util.Log("StepSix commencing.");
+ m_client2.Call(StepSix, true);
+ Util.Log("StepSix complete.");
+
+ m_client1.Call(StepSeven);
+ Util.Log("StepSeven complete.");
+
+ m_client2.Call(StepEight);
+ Util.Log("StepEight complete.");
+
+ m_client1.Call(StepNine);
+ Util.Log("StepNine complete.");
+
+ m_client2.Call(StepTen);
+ Util.Log("StepTen complete.");
+
+ m_client1.Call(StepEleven);
+ Util.Log("StepEleven complete.");
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/DistributedSystemTests.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/DistributedSystemTests.cs b/clicache/integration-test/DistributedSystemTests.cs
new file mode 100644
index 0000000..157eee2
--- /dev/null
+++ b/clicache/integration-test/DistributedSystemTests.cs
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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;
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+
+ [TestFixture]
+ [Category("unicast_only")]
+ public class DistributedSystemTests : UnitTests
+ {
+ protected override ClientBase[] GetClients()
+ {
+ return null;
+ }
+
+ [Test]
+ public void Connect()
+ {
+ try
+ {
+ DistributedSystem.Disconnect(CacheHelper.getCache());
+ Assert.Fail("NotConnectedException should have occurred when "
+ + "disconnecting without having connected.");
+ }
+ catch (NotConnectedException ex)
+ {
+ Util.Log("Got an expected exception in DistributedSystem.disconnect: "
+ + ex);
+ }
+ try
+ {
+ CacheHelper.ConnectName("ConnTest");
+ }
+ finally
+ {
+ CacheHelper.Close();
+ }
+ }
+
+ [Test]
+ public void ConnectToNull()
+ {
+ Util.Log("Creating DistributedSytem with null name...");
+ try
+ {
+ CacheHelper.ConnectName(null);
+ CacheHelper.Close();
+ Assert.Fail("IllegalArgumentException should have occurred when "
+ + "connecting to a null DistributedSystem.");
+ }
+ catch (IllegalArgumentException ex)
+ {
+ Util.Log("Got an expected exception in DistributedSystem.connect: "
+ + ex);
+ }
+ }
+
+ [Test]
+ public void Reconnect()
+ {
+ string[] memberTypes = { "PEER", "SERVER" };
+ foreach (string memberType in memberTypes)
+ {
+ // Connect and disconnect 10 times
+
+ for (int i = 0; i < 10; i++)
+ {
+ CacheHelper.InitConfig(memberType, null);
+
+ try
+ {
+ Region region1 = CacheHelper.CreatePlainRegion("R1");
+ Region region2 = CacheHelper.CreatePlainRegion("R2");
+ }
+ finally
+ {
+ CacheHelper.Close();
+ }
+ }
+ }
+ }
+
+ [Test]
+ public void Example()
+ {
+ CacheableString cVal;
+
+ Region region = CacheHelper.CreateLRURegion("exampleRegion",
+ 1000, ScopeType.DistributedNoAck);
+ try
+ {
+ // put some values into the cache.
+ for (int i = 1; i <= 2000; i++)
+ {
+ region.Put("key-" + i, "value-" + i);
+ }
+
+ // do some gets... printing what we find in the cache.
+ for (int i = 1; i <= 2000; i += 100)
+ {
+ cVal = region.Get("key-" + i) as CacheableString;
+ if (cVal == null)
+ {
+ Util.Log("Didn't find key-{0} in the cache.", i);
+ }
+ else
+ {
+ Util.Log("Found key-{0} with value {1}.", i, cVal.Value);
+ }
+ }
+ }
+ finally
+ {
+ CacheHelper.Close();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/DupListenerN.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/DupListenerN.cs b/clicache/integration-test/DupListenerN.cs
new file mode 100644
index 0000000..74eab9a
--- /dev/null
+++ b/clicache/integration-test/DupListenerN.cs
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.Threading;
+using System.Collections.Generic;
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+ using Apache.Geode.Client;
+ using Region = Apache.Geode.Client.IRegion<Object, Object>;
+
+ class DupListener<TKey, TVal> : ICacheListener<TKey, TVal>
+ {
+ #region Private members
+
+ private int m_ops = 0;
+ private Dictionary<object, object> m_map = new Dictionary<object, object>();
+ //ICacheableKey, IGeodeSerializable
+
+ #endregion
+
+ #region Public accessors
+
+ public int Ops
+ {
+ get
+ {
+ return m_ops;
+ }
+ }
+
+ #endregion
+
+ public static DupListener<TKey, TVal> Create()
+ {
+ return new DupListener<TKey, TVal>();
+ }
+
+ private void check(EntryEvent<TKey, TVal> ev)
+ {
+ m_ops++;
+
+ object key = (object)ev.Key;
+ object value = (object)ev.NewValue;
+
+ //string key = ev.Key();
+ //int value = ev.NewValue;
+ if (m_map.ContainsKey(key))
+ {
+ int old = (int)m_map[key];
+ Assert.AreEqual(value/*.Value*/, old/*.Value*/ + 1, "Duplicate or older value received");
+ }
+
+ m_map[key] = value;
+ }
+
+ public void validate()
+ {
+ Assert.AreEqual(4, m_map.Count, "Expected 4 keys for the region");
+ Assert.AreEqual(400, m_ops, "Expected 400 events (100 per key) for the region");
+
+ foreach (object item in m_map.Values)
+ {
+ //CacheableInt32 checkval = item as CacheableInt32;
+ int checkval = (int)item;
+ Assert.AreEqual(100, checkval, "Expected final value to be 100");
+ }
+ }
+
+ #region ICacheListener Members
+
+ public virtual void AfterCreate(EntryEvent<TKey, TVal> ev)
+ {
+ check(ev);
+ }
+
+ public virtual void AfterUpdate(EntryEvent<TKey, TVal> ev)
+ {
+ check(ev);
+ }
+
+ public virtual void AfterDestroy(EntryEvent<TKey, TVal> ev) { }
+
+ public virtual void AfterInvalidate(EntryEvent<TKey, TVal> ev) { }
+
+ public virtual void AfterRegionDestroy(RegionEvent<TKey, TVal> ev) { }
+
+ public virtual void AfterRegionClear(RegionEvent<TKey, TVal> ev) { }
+
+ public virtual void AfterRegionInvalidate(RegionEvent<TKey, TVal> ev) { }
+
+ public virtual void AfterRegionLive(RegionEvent<TKey, TVal> ev) { }
+
+ public virtual void Close(IRegion<TKey, TVal> region) { }
+ public virtual void AfterRegionDisconnected(IRegion<TKey, TVal> region) { }
+
+ #endregion
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/DurableListenerN.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/DurableListenerN.cs b/clicache/integration-test/DurableListenerN.cs
new file mode 100644
index 0000000..c01211d
--- /dev/null
+++ b/clicache/integration-test/DurableListenerN.cs
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.Threading;
+using System.Collections.Generic;
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+ using Apache.Geode.Client;
+ using Apache.Geode.Client;
+
+ //using Com.Vmware.Cache;
+ //using Region = Com.Vmware.Cache.IRegion<object, object>;
+
+ class DurableListener<TKey, TVal> : ICacheListener<TKey, TVal>
+ {
+ #region Private members
+
+ private int m_ops = 0;
+ private Dictionary<object, object> m_map = new Dictionary<object, object>();
+
+ #endregion
+
+ #region Public accessors
+
+ public int Ops
+ {
+ get
+ {
+ return m_ops;
+ }
+ }
+
+ #endregion
+
+ public static DurableListener<TKey, TVal> Create()
+ {
+ Util.Log(" DurableListener Created");
+
+ return new DurableListener<TKey, TVal>();
+ }
+
+ private void check(EntryEvent<TKey, TVal> ev)
+ {
+ m_ops++;
+
+ //CacheableString key = ev.Key as CacheableString;
+ //ICacheableKey<TKey> key = ev.Key;
+ //TVal value = ev.NewValue;
+ object key = (object)ev.Key;
+ object value = (object)ev.NewValue;
+ //object key = (object)ev.Key;
+ //object value = (object)ev.NewValue;
+ //CacheableInt32 value = ev.NewValue as CacheableInt32;
+ //object value = (object)ev.NewValue;
+ //object key1 = key.Value;
+ //int value1 = (int)value;
+
+ //if (m_map.ContainsKey(key))
+ //{
+ // //CacheableInt32 old = m_map[key] as CacheableInt32;
+ // //TVal old =(TVal) m_map[(TKey)key];
+ // object old = m_map[key];
+ // Assert.AreEqual(value, old /*old + 1*/, "Duplicate or older value received");
+ //}
+
+ Util.Log("key={0} and Value={1}", key, value);
+ Util.Log("key={0} and Value={1}", key.GetType(), value.GetType());
+ m_map[key] = value;
+ }
+
+ // this method for the ThinClientDurableTests
+ public void validate(int keys, int durable, int nondurable)
+ {
+ string msg1 = string.Format("Expected {0} keys but got {1}", keys, m_map.Count);
+ Assert.AreEqual(keys, m_map.Count, msg1);
+
+ int total = keys * (durable + nondurable) / 2;
+
+ string msg2 = string.Format("Expected {0} events but got {1}", total, m_ops);
+ Assert.AreEqual(total, m_ops, msg2);
+
+ foreach (KeyValuePair<object, object> item in m_map)
+ {
+ string key = (string)item.Key;
+ int checkvalue = (int)item.Value;
+ int finalvalue = durable;
+ if (key.StartsWith("Key"))
+ {
+ finalvalue = nondurable;
+ }
+ string msg3 = string.Format("Expected final value for key {0} to be {1} but was {2}", key, finalvalue, checkvalue);
+ Assert.AreEqual(finalvalue, checkvalue, msg3);
+ }
+ }
+
+ // this method for the ThinClientDurableTests
+ public void validate(int keys, int total)
+ {
+ string msg1 = string.Format("Expected {0} keys but got {1}", keys, m_map.Count);
+ Assert.AreEqual(keys, m_map.Count, msg1);
+
+ string msg2 = string.Format("Expected {0} events but got {1}", total, m_ops);
+ Assert.AreEqual(total, m_ops, msg2);
+
+ int finalvalue = total/keys;
+
+ foreach (KeyValuePair<object, object> item in m_map)
+ {
+ string key = (string)item.Key;
+ int checkvalue = (int)item.Value;
+ string msg3 = string.Format("Expected final value for key {0} to be {1} but was {2}", key, finalvalue, checkvalue);
+ Assert.AreEqual(finalvalue, checkvalue, msg3);
+ }
+ }
+ //Used for DurableAndNonDurableBasic
+ public void validateBasic(int keyCount, int eventCount, int durableValue, int nonDurableValue)
+ {
+ string msg1 = string.Format("Expected {0} keys but got {1}", keyCount, m_map.Count);
+ Assert.AreEqual(keyCount, m_map.Count, msg1);
+
+ string msg2 = string.Format("Expected {0} events but got {1}", eventCount, m_ops);
+ Assert.AreEqual(eventCount, m_ops, msg2);
+
+ foreach (KeyValuePair<object, object> item in m_map)
+ {
+ string key = (string)item.Key;
+ int checkvalue = (int)item.Value;
+
+ int finalvalue;
+ if (key.StartsWith("D-") || key.StartsWith("LD-")) { // durable key
+ finalvalue = durableValue;
+ }
+ else {
+ finalvalue = nonDurableValue;
+ }
+
+ string msg3 = string.Format("Expected final value for key {0} to be {1} but was {2}", key, finalvalue, checkvalue);
+
+ Assert.AreEqual(finalvalue, checkvalue, msg3);
+ }
+ }
+
+ #region ICacheListener Members
+
+ public virtual void AfterCreate(EntryEvent<TKey, TVal> ev)
+ {
+ Util.Log("Called AfterCreate()");
+ check(ev);
+ }
+
+ public virtual void AfterUpdate(EntryEvent<TKey, TVal> ev)
+ {
+ Util.Log("Called AfterUpdate()");
+ check(ev);
+ }
+
+ public virtual void AfterDestroy(EntryEvent<TKey, TVal> ev)
+ {
+ //Increment only count
+ Util.Log("Called AfterDestroy()");
+ m_ops++;
+ }
+
+ public virtual void AfterInvalidate(EntryEvent<TKey, TVal> ev) { }
+
+ public virtual void AfterRegionDestroy(RegionEvent<TKey, TVal> ev) { }
+
+ public virtual void AfterRegionClear(RegionEvent<TKey, TVal> ev) { }
+
+ public virtual void AfterRegionInvalidate(RegionEvent<TKey, TVal> ev) { }
+
+ public virtual void AfterRegionLive(RegionEvent<TKey, TVal> ev)
+ {
+ Util.Log("DurableListener: Received AfterRegionLive event of region: {0}", ev.Region.Name);
+ }
+
+ public virtual void Close(IRegion<TKey, TVal> region) { }
+ public void AfterRegionDisconnected(IRegion<TKey, TVal> region) { }
+ #endregion
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/ExpirationTestsN.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/ExpirationTestsN.cs b/clicache/integration-test/ExpirationTestsN.cs
new file mode 100644
index 0000000..419a43e
--- /dev/null
+++ b/clicache/integration-test/ExpirationTestsN.cs
@@ -0,0 +1,339 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.Threading;
+using System.Collections.Generic;
+#pragma warning disable 618
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+ using Apache.Geode.Client;
+
+ [TestFixture]
+ [Category("group2")]
+ [Category("unicast_only")]
+ [Category("generics")]
+ public class ExpirationTests : UnitTests
+ {
+ #region Private members
+
+ private IRegion<object, object> m_region = null;
+ private string m_key = "KeyA - 1";
+ private string m_value = "Value - AAAAAAA";
+ private string m_regionName = "R";
+
+ #endregion
+
+ protected override ClientBase[] GetClients()
+ {
+ return null;
+ }
+
+ [TestFixtureSetUp]
+ public override void InitTests()
+ {
+ base.InitTests();
+ Properties<string, string> config = new Properties<string, string>();
+ CacheHelper.InitConfig(config);
+ }
+
+ [TestFixtureTearDown]
+ public override void EndTests()
+ {
+ try
+ {
+ CacheHelper.Close();
+ }
+ finally
+ {
+ base.EndTests();
+ }
+ }
+
+ [TearDown]
+ public override void EndTest()
+ {
+ base.EndTest();
+ }
+
+ #region Private functions
+
+ private int GetNumOfEntries()
+ {
+ try
+ {
+ ICollection<object> keys = m_region.GetLocalView().Keys;
+
+ if (keys != null)
+ {
+ return keys.Count;
+ }
+ }
+ catch (RegionDestroyedException)
+ {
+ }
+ return 0;
+ }
+
+ private void DoNPuts(int n)
+ {
+ for (int index = 0; index < n; index++)
+ {
+ m_region[string.Format("KeyA - {0}", index + 1)] = m_value;
+ }
+ }
+
+ private void Do1Put()
+ {
+ m_region[m_key] = m_value;
+ }
+
+ private void SetupRegion(uint entryTTL, uint entryIdleTimeout,
+ uint regionTTL, uint regionIdleTimeout)
+ {
+ const ExpirationAction action = ExpirationAction.Destroy;
+
+ RegionFactory rf = CacheHelper.DCache.CreateRegionFactory(RegionShortcut.LOCAL);
+
+ rf.SetEntryTimeToLive(action, entryTTL);
+ rf.SetEntryIdleTimeout(action, entryIdleTimeout);
+ rf.SetRegionTimeToLive(action, regionTTL);
+ rf.SetRegionIdleTimeout(action, regionIdleTimeout);
+
+ CacheHelper.Init();
+ IRegion<object, object> region = CacheHelper.GetRegion<object, object>(m_regionName);
+ if ((region != null) && !region.IsDestroyed)
+ {
+ region.GetLocalView().DestroyRegion();
+ Assert.IsTrue(region.IsDestroyed, "IRegion<object, object> {0} was not destroyed.", m_regionName);
+ }
+ m_region = rf.Create<object, object>(m_regionName);
+ Assert.IsNotNull(m_region, "IRegion<object, object> was not created.");
+
+ }
+ private void PutKeyTouch(int sleepSecs)
+ {
+ Do1Put();
+ Thread.Sleep(sleepSecs * 1000);
+ object val = m_region[m_key];
+ }
+
+ private void PutNKeysNoExpire(int numKeys, int sleepSecs)
+ {
+ int n;
+
+ DoNPuts(numKeys);
+ Thread.Sleep(sleepSecs * 1000);
+ if (numKeys > 0)
+ {
+ n = GetNumOfEntries();
+ Assert.AreEqual(numKeys, n, "Expected " + numKeys + " entries");
+ }
+ }
+
+ private void PutNKeysExpire(int numKeys, int sleepSecs)
+ {
+ int n;
+
+ DoNPuts(numKeys);
+ Thread.Sleep(sleepSecs * 1000);
+ n = GetNumOfEntries();
+ Assert.AreEqual(0, n, "Expected 0 entry");
+ }
+
+ private void CheckRegion(bool expectedDead, int sleepSecs)
+ {
+ if (sleepSecs > 0)
+ {
+ Thread.Sleep(sleepSecs * 1000);
+ }
+ if (expectedDead)
+ {
+ Assert.IsTrue(m_region.IsDestroyed, "Expected {0} to be dead",
+ m_regionName);
+ }
+ else
+ {
+ Assert.IsFalse(m_region.IsDestroyed, "Expected {0} to be alive",
+ m_regionName);
+ }
+ }
+
+ #endregion
+
+ /*
+ [Test]
+ public void KeyDestroy()
+ {
+ m_regionName = "RT1";
+ SetupRegion(0, 0, 0, 0);
+ PutKeyTouch(5);
+ IGeodeSerializable val = m_region.Get(m_key);
+ m_region.Destroy(m_key);
+ val = m_region.Get(m_key);
+ CheckRegion(false, 0);
+
+ m_regionName = "RT2";
+ SetupRegion(0, 0, 0, 0);
+ PutNKeysNoExpire(5, 1);
+ m_region.DestroyRegion();
+ CheckRegion(true, 0);
+
+ m_regionName = "RT3";
+ SetupRegion(0, 0, 0, 0);
+ PutKeyTouch(5);
+ val = m_region.Get(m_key);
+ CheckRegion(false, 0);
+ m_region.DestroyRegion();
+ try
+ {
+ val = m_region.Get(m_key);
+ Util.Log("The key fetched has value: {0}", val);
+ Assert.Fail("The region should have been destroyed.");
+ }
+ catch (RegionDestroyedException)
+ {
+ }
+ CheckRegion(true, 0);
+ }
+ * */
+
+ [Test]
+ public void KeyExpiration()
+ {
+ m_regionName = "R1";
+ SetupRegion(0, 0, 0, 0);
+ PutNKeysNoExpire(100, 10);
+ CheckRegion(false, 0);
+
+ m_regionName = "R2";
+ SetupRegion(20, 2, 0, 0);
+ PutNKeysNoExpire(1, 5);
+ CheckRegion(false, 0);
+
+ m_regionName = "R3";
+ SetupRegion(5, 0, 0, 0);
+ PutNKeysExpire(1, 10);
+ CheckRegion(false, 0);
+
+ m_regionName = "R4";
+ SetupRegion(0, 5, 0, 0);
+ PutKeyTouch(2);
+ Thread.Sleep(3000);
+ Assert.AreEqual(1, GetNumOfEntries(), "Expected 1 entry");
+ Thread.Sleep(5000);
+ Assert.AreEqual(0, GetNumOfEntries(), "Expected 0 entry");
+ CheckRegion(false, 0);
+
+ m_regionName = "R5";
+ SetupRegion(10, 0, 0, 0);
+ PutKeyTouch(5);
+ PutNKeysNoExpire(0, 6);
+ CheckRegion(false, 0);
+
+ m_regionName = "R6";
+ SetupRegion(5, 0, 0, 0);
+ PutNKeysExpire(1, 6);
+ CheckRegion(false, 0);
+
+ m_regionName = "R7";
+ SetupRegion(0, 5, 0, 0);
+ PutKeyTouch(2);
+ m_region.GetLocalView().Remove(m_key);
+ CheckRegion(false, 5);
+
+ m_regionName = "R8";
+ SetupRegion(6, 3, 0, 0);
+ PutNKeysNoExpire(1, 4);
+ Thread.Sleep(4000);
+ Assert.AreEqual(0, GetNumOfEntries(), "ttl is over so it should be 0");
+ CheckRegion(false, 5);
+ }
+
+ [Test]
+ public void RegionExpiration()
+ {
+ m_regionName = "RR1";
+ SetupRegion(0, 0, 20, 2);
+ CheckRegion(false, 5);
+
+ m_regionName = "RR2";
+ SetupRegion(0, 0, 5, 0);
+ PutNKeysNoExpire(1, 2);
+ DoNPuts(1);
+ CheckRegion(true, 7);
+
+ m_regionName = "RR3";
+ SetupRegion(0, 0, 0, 5);
+ PutNKeysNoExpire(1, 2);
+ DoNPuts(1);
+ CheckRegion(true, 10);
+
+ m_regionName = "RR4";
+ SetupRegion(0, 0, 0, 8);
+ PutKeyTouch(5);
+ Thread.Sleep(5000);
+ Assert.AreEqual(1, GetNumOfEntries(), "Expected 1 entry");
+ CheckRegion(false, 0);
+
+ m_regionName = "RR5";
+ SetupRegion(0, 0, 10, 0);
+ Do1Put();
+ CheckRegion(true, 12);
+
+ m_regionName = "RR6";
+ SetupRegion(0, 0, 6, 3);
+ Thread.Sleep(4000);
+ Do1Put();
+ CheckRegion(false, 4);
+ CheckRegion(true, 4);
+ }
+
+ [Test]
+ public void RegionAndKeyExpiration()
+ {
+ /*
+ m_regionName = "RK1";
+ SetupRegion(5, 0, 0, 0);
+ PutNKeysNoExpire(1, 2);
+ m_region.DestroyRegion();
+ CheckRegion(true, 0);
+
+ m_regionName = "RK2";
+ SetupRegion(0, 5, 0, 0);
+ PutNKeysNoExpire(1, 1);
+ m_region.DestroyRegion();
+ CheckRegion(true, 6);
+ * */
+
+ m_regionName = "RK3";
+ SetupRegion(6, 0, 0, 12);
+ PutNKeysExpire(1, 10);
+ CheckRegion(true, 11);
+
+ m_regionName = "RK4";
+ SetupRegion(0, 4, 0, 7);
+ PutNKeysNoExpire(1, 3);
+ object val = m_region[m_key];
+ CheckRegion(false, 5);
+ CheckRegion(true, 5);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/LogTests.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/LogTests.cs b/clicache/integration-test/LogTests.cs
new file mode 100644
index 0000000..45f2ec8
--- /dev/null
+++ b/clicache/integration-test/LogTests.cs
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.IO;
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+
+
+ [TestFixture]
+ [Category("unicast_only")]
+ public class LogTests : UnitTests
+ {
+ #region constants
+ const int LENGTH_OF_BANNER = 53;
+ #endregion
+
+ #region Private functions
+
+ private int NumOfLinesInFile(string fName)
+ {
+ try
+ {
+ int numLines = 0;
+ FileStream fs = new FileStream(fName, FileMode.Open,
+ FileAccess.Read, FileShare.ReadWrite);
+ if (fs == null)
+ {
+ return -1;
+ }
+ StreamReader sr = new StreamReader(fs);
+ string s;
+ while ((s = sr.ReadLine()) != null && s.Length > 0)
+ {
+ numLines++;
+ }
+ sr.Close();
+ fs.Close();
+ return numLines;
+ }
+ catch
+ {
+ return -1;
+ }
+ }
+
+ private int LinesAtLevel(LogLevel level)
+ {
+ int expected = (int)level;
+ if ( level != LogLevel.Null ) {
+ expected += LENGTH_OF_BANNER;
+ }
+ if (level >= LogLevel.Default)
+ {
+ expected--;
+ }
+ return expected;
+ }
+
+ private void LogAll(string logFileName,
+ LogLevel level, int expectedLines)
+ {
+ string logFile = logFileName + ".log";
+
+ Log.Close();
+ File.Delete(logFile);
+ Log.Init(level, logFileName);
+
+ Log.Write(LogLevel.Error, "Error Message");
+ Log.Write(LogLevel.Warning, "Warning Message");
+ Log.Write(LogLevel.Info, "Info Message");
+ Log.Write(LogLevel.Config, "Config Message");
+ Log.Write(LogLevel.Fine, "Fine Message");
+ Log.Write(LogLevel.Finer, "Finer Message");
+ Log.Write(LogLevel.Finest, "Finest Message");
+ Log.Write(LogLevel.Debug, "Debug Message");
+
+ Log.Close();
+ int lines = NumOfLinesInFile(logFile);
+ Assert.AreEqual(expectedLines, lines, "Expected " + expectedLines.ToString() + " lines");
+
+ File.Delete(logFile);
+ }
+
+ private void LogSome(string logFileName,
+ LogLevel level, int expectedLines)
+ {
+ string logFile = logFileName + ".log";
+
+ Log.Close();
+ File.Delete(logFile);
+ Log.Init(level, logFileName);
+
+ Log.Write(LogLevel.Debug, "Debug Message");
+ Log.Write(LogLevel.Config, "Config Message");
+ Log.Write(LogLevel.Info, "Info Message");
+ Log.Write(LogLevel.Warning, "Warning Message");
+ Log.Write(LogLevel.Error, "Error Message");
+
+ Log.Close();
+ int lines = NumOfLinesInFile(logFile);
+ Assert.AreEqual(expectedLines, lines, "Expected " + expectedLines.ToString() + " lines");
+
+ File.Delete(logFile);
+ }
+
+ #endregion
+
+ protected override ClientBase[] GetClients()
+ {
+ return null;
+ }
+
+ [Test]
+ public void AllLevels()
+ {
+ for (LogLevel level = LogLevel.Error;
+ level <= LogLevel.Debug; level = (LogLevel)((int)level + 1))
+ {
+ LogAll("all_logfile", level, LinesAtLevel(level));
+ }
+ }
+
+ [Test]
+ public void AllLevelsMacro()
+ {
+ for (LogLevel level = LogLevel.Error;
+ level <= LogLevel.Debug; level = (LogLevel)((int)level + 1))
+ {
+ LogAll("logleveltest" + (int)level,
+ level, LinesAtLevel(level));
+ }
+ }
+
+ [Test]
+ public void ConfigOnwards()
+ {
+ LogSome("logfile", LogLevel.Config, 4 + LENGTH_OF_BANNER );
+ }
+
+ [Test]
+ public void InfoOnwards()
+ {
+ LogSome("logfile", LogLevel.Info, 3 + LENGTH_OF_BANNER );
+ }
+
+ [Test]
+ public void WarningOnwards()
+ {
+ LogSome("logfile", LogLevel.Warning, 2 + LENGTH_OF_BANNER );
+ }
+
+ [Test]
+ public void ErrorOnwards()
+ {
+ LogSome("logfile", LogLevel.Error, 1 + LENGTH_OF_BANNER );
+ }
+
+ [Test]
+ public void NoLog()
+ {
+ LogSome("logfile", LogLevel.Null, 0);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/NetTests.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/NetTests.cs b/clicache/integration-test/NetTests.cs
new file mode 100644
index 0000000..e31d9b4
--- /dev/null
+++ b/clicache/integration-test/NetTests.cs
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.Threading;
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+
+ [TestFixture]
+ public class NetTests : UnitTests
+ {
+ private const string TestRegion = "TestRegion";
+ private const string TestRegionWrite = "TestRegionWrite";
+ private const int NumEntries = 200;
+
+ private Region m_region;
+ private Region m_netWriteRegion;
+
+ private TallyLoader m_ldr = new TallyLoader();
+ private TallyWriter m_lwr = new TallyWriter();
+
+ private UnitProcess m_client1, m_client2, m_client3;
+
+ protected override ClientBase[] GetClients()
+ {
+ m_client1 = new UnitProcess();
+ m_client2 = new UnitProcess();
+ m_client3 = new UnitProcess();
+ return new ClientBase[] { m_client1, m_client2, m_client3 };
+ }
+
+ #region Functions invoked by the tests
+
+ public void DoGets(Region region, int num)
+ {
+ for(int i = 0; i < num; i++)
+ {
+ CacheableInt32 val = region.Get(i) as CacheableInt32;
+ Assert.AreEqual(i, val.Value);
+ }
+ }
+
+ public void CreateRegionWithTallyLoader(ScopeType scope)
+ {
+ AttributesFactory af = new AttributesFactory();
+ af.SetCacheLoader(m_ldr);
+ af.SetScope(scope);
+ af.SetCachingEnabled(true);
+
+ m_region = CacheHelper.CreateRegion(TestRegion,
+ af.CreateRegionAttributes());
+ }
+
+ public void CreateRegionAndGetNEntries(int num)
+ {
+ CacheHelper.CreateDistribRegion(TestRegion, false, true);
+ m_region = CacheHelper.GetVerifyRegion(TestRegion);
+ DoGets(m_region, num);
+ IGeodeSerializable[] arr = m_region.GetKeys();
+ Assert.AreEqual(num, arr.Length);
+ }
+
+ public void VerifyLoaderCallsAfterGets(int num)
+ {
+ Assert.AreEqual(num, m_ldr.Loads);
+ Util.Log("Calling doGets for verify");
+ //Thread.Sleep(2000);
+ //doGets(m_region, load);
+ IGeodeSerializable[] arr = m_region.GetKeys();
+ Assert.AreEqual(num, arr.Length);
+ }
+
+ public void RegionThreeLoadEntries(int num)
+ {
+ AttributesFactory af = new AttributesFactory();
+ af.SetScope(ScopeType.Local);
+ af.SetCacheLoader(m_ldr);
+ m_region = CacheHelper.CreateRegion(TestRegion, af.CreateRegionAttributes());
+ m_ldr.Reset();
+ Thread.Sleep(100);
+ DoGets(m_region, num);
+ Assert.AreEqual(num, m_ldr.Loads);
+ IGeodeSerializable[] arr = m_region.GetKeys();
+ Assert.AreEqual(num, arr.Length);
+ }
+
+ public void CreateRegionWithTallyWriter(ScopeType scope)
+ {
+ AttributesFactory af = new AttributesFactory();
+ af.SetCacheWriter(m_lwr);
+ af.SetScope(scope);
+ af.SetCachingEnabled(true);
+
+ m_netWriteRegion = CacheHelper.CreateRegion(TestRegionWrite,
+ af.CreateRegionAttributes());
+ }
+
+ public void RegionTwoCreateEntries(int num)
+ {
+ CacheHelper.CreateDistribRegion(TestRegionWrite, false, true);
+ m_netWriteRegion = CacheHelper.GetVerifyRegion(TestRegionWrite);
+ Thread.Sleep(100);
+ TestCreateEntryActions(num);
+ }
+
+ public void TestCreateEntryActions(int num)
+ {
+ for (int i = 0; i < num; i++)
+ {
+ CacheableInt32 key = new CacheableInt32(i);
+ m_netWriteRegion.Put(key, key);
+ }
+ }
+
+ public void TestUpdateActions(int num)
+ {
+ for (int i = 0; i < num; i++)
+ {
+ CacheableInt32 key = new CacheableInt32(i);
+ m_netWriteRegion.Put(key, key);
+ }
+ }
+
+ public void VerifyWriterCallsAfterCreate(int num)
+ {
+ Assert.AreEqual(num, m_lwr.Creates);
+ }
+
+ public void VerifyWriterCallsAfterUpdates(int num)
+ {
+ Assert.AreEqual(num, m_lwr.Creates);
+ Assert.AreEqual(num, m_lwr.Updates);
+ }
+
+ #endregion
+
+ [Test]
+ public void LoaderTest()
+ {
+ m_client1.Call(CreateRegionWithTallyLoader, ScopeType.DistributedNoAck);
+ m_client2.Call(CreateRegionAndGetNEntries, NumEntries);
+ m_client1.Call(VerifyLoaderCallsAfterGets, NumEntries);
+ m_client3.Call(RegionThreeLoadEntries, NumEntries);
+ }
+
+ [Test]
+ public void WriterTest()
+ {
+ m_client1.Call(CreateRegionWithTallyWriter, ScopeType.DistributedNoAck);
+ m_client2.Call(RegionTwoCreateEntries, NumEntries);
+ m_client1.Call(VerifyWriterCallsAfterCreate, NumEntries);
+ m_client2.Call(TestUpdateActions, NumEntries);
+ m_client1.Call(VerifyWriterCallsAfterUpdates, NumEntries);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/OverflowTestsN.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/OverflowTestsN.cs b/clicache/integration-test/OverflowTestsN.cs
new file mode 100644
index 0000000..8980ab6
--- /dev/null
+++ b/clicache/integration-test/OverflowTestsN.cs
@@ -0,0 +1,664 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.IO;
+using System.Threading;
+using System.Collections.Generic;
+using System.Diagnostics;
+
+#pragma warning disable 618
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+ using Apache.Geode.Client;
+
+ [TestFixture]
+ [Category("group4")]
+ [Category("unicast_only")]
+ [Category("generics")]
+
+ public class OverflowTests : UnitTests
+ {
+ private DistributedSystem m_dsys = null;
+
+ private const string DSYSName = "OverflowTest";
+
+ protected override ClientBase[] GetClients()
+ {
+ return null;
+ }
+
+ [TestFixtureSetUp]
+ public override void InitTests()
+ {
+ base.InitTests();
+ m_dsys = CacheHelper.DSYS;
+ }
+
+ [TestFixtureTearDown]
+ public override void EndTests()
+ {
+ try
+ {
+ CacheHelper.Close();
+ }
+ finally
+ {
+ base.EndTests();
+ }
+ }
+
+ [SetUp]
+ public void StartTest()
+ {
+ CacheHelper.Init();
+ }
+
+ [TearDown]
+ public override void EndTest()
+ {
+ CacheHelper.Close();
+ base.EndTest();
+ }
+
+ #region Private functions used by the tests
+
+ private IRegion<object, object> CreateOverflowRegion(string regionName, string libraryName, string factoryFunctionName)
+ {
+
+ RegionFactory rf = CacheHelper.DCache.CreateRegionFactory(RegionShortcut.LOCAL);
+ rf.SetCachingEnabled(true);
+ rf.SetLruEntriesLimit(20);
+ rf.SetInitialCapacity(1000);
+ rf.SetDiskPolicy(DiskPolicyType.Overflows);
+
+ Properties<string, string> sqliteProperties = new Properties<string, string>();
+ sqliteProperties.Insert("PageSize", "65536");
+ sqliteProperties.Insert("MaxFileSize", "512000000");
+ String sqlite_dir = "SqLiteDir" + Process.GetCurrentProcess().Id.ToString();
+ sqliteProperties.Insert("PersistenceDirectory", sqlite_dir);
+
+ rf.SetPersistenceManager(libraryName, factoryFunctionName, sqliteProperties);
+
+ CacheHelper.Init();
+ IRegion<object, object> region = CacheHelper.GetRegion<object, object>(regionName);
+ if ((region != null) && !region.IsDestroyed)
+ {
+ region.GetLocalView().DestroyRegion();
+ Assert.IsTrue(region.IsDestroyed, "IRegion<object, object> {0} was not destroyed.", regionName);
+ }
+ region = rf.Create<object, object>(regionName);
+ Assert.IsNotNull(region, "IRegion<object, object> was not created.");
+
+ return region;
+
+ }
+
+ // Testing for attibute validation.
+ private void ValidateAttributes(IRegion<object, object> region)
+ {
+ Apache.Geode.Client.RegionAttributes<object, object> regAttr = region.Attributes;
+ int initialCapacity = regAttr.InitialCapacity;
+ Assert.AreEqual(1000, initialCapacity, "Expected initial capacity to be 1000");
+ Assert.AreEqual(DiskPolicyType.Overflows, regAttr.DiskPolicy,
+ "Expected Action to be overflow to disk");
+ }
+
+
+ private string GetSqLiteFileName(string sqliteDir, string regionName)
+ {
+ return Path.Combine(Directory.GetCurrentDirectory(), sqliteDir, regionName, regionName + ".db");
+ }
+
+ private IRegion<object, object> CreateSubRegion(IRegion<object, object> region, string subRegionName, string libraryName, string factoryFunctionName)
+ {
+ AttributesFactory<object, object> attrsFact = new AttributesFactory<object, object>(region.Attributes);
+ Properties<string, string> sqliteProperties = new Properties<string, string>();
+ sqliteProperties.Insert("PageSize", "65536");
+ sqliteProperties.Insert("MaxPageCount", "512000000");
+ String sqlite_dir = "SqLiteDir" + Process.GetCurrentProcess().Id.ToString();
+ sqliteProperties.Insert("PersistenceDirectory", sqlite_dir);
+ attrsFact.SetPersistenceManager(libraryName, factoryFunctionName, sqliteProperties);
+ IRegion<object, object> subRegion = region.CreateSubRegion(subRegionName,
+ attrsFact.CreateRegionAttributes());
+ Assert.IsNotNull(subRegion, "Expected region to be non null");
+ Assert.IsTrue(File.Exists(GetSqLiteFileName(sqlite_dir, subRegionName)), "Persistence file is not present");
+ DoNput(subRegion, 50);
+ DoNget(subRegion, 50);
+ return subRegion;
+ }
+
+ private void DoNput(IRegion<object, object> region, int num)
+ {
+ //CacheableString cVal = new CacheableString(new string('A', 1024));
+ string cVal = new string('A', 1024);
+ for (int i = 0; i < num; i++)
+ {
+ Util.Log("Putting key = key-{0}", i);
+ region["key-" + i.ToString()] = cVal;
+ }
+ }
+
+ private void DoNget(IRegion<object, object> region, int num)
+ {
+ string cVal;
+ string expectVal = new string('A', 1024);
+ for (int i = 0; i < num; i++)
+ {
+ cVal = region["key-" + i.ToString()] as string;
+ Util.Log("Getting key = key-{0}", i);
+ Assert.IsNotNull(cVal, "Key[key-{0}] not found.", i);
+ Assert.AreEqual(expectVal, cVal, "Did not find the expected value.");
+ }
+ }
+
+ private bool IsOverflowed(/*IGeodeSerializable*/ object cVal)
+ {
+ //Util.Log("IsOverflowed:: value is: {0}; type is: {1}", cVal.ToString(), cVal.GetType());
+ return cVal.ToString() == "CacheableToken::OVERFLOWED";
+ }
+
+ private void CheckOverflowToken(IRegion<object, object> region, int num, int lruLimit)
+ {
+ //IGeodeSerializable cVal;
+ //ICacheableKey[] cKeys = region.GetKeys();
+
+ object cVal;
+ ICollection<object> cKeys = region.GetLocalView().Keys;
+ Assert.AreEqual(num, cKeys.Count, "Number of keys does not match.");
+ int count = 0;
+ foreach (object cKey in cKeys)
+ {
+ RegionEntry<object, object> entry = region.GetEntry(cKey);
+ cVal = entry.Value;
+ if (IsOverflowed(cVal))
+ {
+ count++;
+ }
+ }
+ Assert.AreEqual(0, count, "Number of overflowed entries should be zero");
+ }
+
+ private void CheckNumOfEntries(IRegion<object, object> region, int lruLimit)
+ {
+ //ICollection<object> cVals = region.GetLocalView().Values;
+ ICollection<object> cVals = region.Values;
+ Assert.AreEqual(lruLimit, cVals.Count, "Number of values does not match.");
+ }
+
+ private void TestGetOp(IRegion<object, object> region, int num)
+ {
+ DoNput(region, num);
+
+ ICollection<object> cKeys = region.GetLocalView().Keys;
+ object cVal;
+
+ Assert.AreEqual(num, cKeys.Count, "Number of keys does not match.");
+ foreach (object cKey in cKeys)
+ {
+ RegionEntry<object, object> entry = region.GetEntry(cKey);
+ cVal = entry.Value;
+ if (IsOverflowed(cVal))
+ {
+ cVal = region[cKey];
+ Assert.IsFalse(IsOverflowed(cVal), "Overflow token even after a Region.Get");
+ }
+ }
+ }
+
+ private void TestEntryDestroy(IRegion<object, object> region)
+ {
+ //ICollection<object> cKeys = region.Keys;
+ ICollection<object> cKeys = region.GetLocalView().Keys;
+ string[] arrKeys = new string[cKeys.Count];
+ cKeys.CopyTo(arrKeys, 0);
+
+ for (int i = 50; i < 60; i++)
+ {
+ try
+ {
+ region.GetLocalView().Remove(arrKeys[i]);
+ }
+ catch (Exception ex)
+ {
+ Util.Log("Entry missing for {0}. Exception: {1}", arrKeys[i], ex.ToString());
+ }
+ }
+ cKeys = region.GetLocalView().Keys;
+
+ Assert.AreEqual(90, cKeys.Count, "Number of keys is not correct.");
+ }
+
+ #endregion
+
+ [Test]
+ public void OverflowPutGet()
+ {
+ IRegion<object, object> region = CreateOverflowRegion("OverFlowRegion", "SqLiteImpl", "createSqLiteInstance");
+ ValidateAttributes(region);
+
+ //Console.WriteLine("TEST-2");
+ // put some values into the cache.
+ DoNput(region, 100);
+ //Console.WriteLine("TEST-2.1 All PUts Donee");
+
+ CheckNumOfEntries(region, 100);
+
+ //Console.WriteLine("TEST-3");
+ // check whether value get evicted and token gets set as overflow
+ CheckOverflowToken(region, 100, 20);
+ // do some gets... printing what we find in the cache.
+ DoNget(region, 100);
+ TestEntryDestroy(region);
+ TestGetOp(region, 100);
+
+ //Console.WriteLine("TEST-4");
+ // test to verify same region repeatedly to ensure that the persistece
+ // files are created and destroyed correctly
+
+ IRegion<object, object> subRegion;
+ String sqlite_dir = "SqLiteDir" + Process.GetCurrentProcess().Id.ToString();
+ for (int i = 0; i < 1; i++)
+ {
+ subRegion = CreateSubRegion(region, "SubRegion", "SqLiteImpl", "createSqLiteInstance");
+ subRegion.DestroyRegion();
+ Assert.IsTrue(subRegion.IsDestroyed, "Expected region to be destroyed");
+ Assert.IsFalse(File.Exists(GetSqLiteFileName(sqlite_dir, "SubRegion")), "Persistence file present after region destroy");
+ }
+ //Console.WriteLine("TEST-5");
+ }
+
+ [Test]
+ public void OverflowPutGetManaged()
+ {
+ IRegion<object, object> region = CreateOverflowRegion("OverFlowRegion", "Apache.Geode.Plugins.SqLite",
+ "Apache.Geode.Plugins.SqLite.SqLiteImpl<System.Object,System.Object>.Create");
+ ValidateAttributes(region);
+
+ //Console.WriteLine("TEST-2");
+ // put some values into the cache.
+ DoNput(region, 100);
+ //Console.WriteLine("TEST-2.1 All PUts Donee");
+
+ CheckNumOfEntries(region, 100);
+
+ //Console.WriteLine("TEST-3");
+ // check whether value get evicted and token gets set as overflow
+ CheckOverflowToken(region, 100, 20);
+ // do some gets... printing what we find in the cache.
+ DoNget(region, 100);
+ TestEntryDestroy(region);
+ TestGetOp(region, 100);
+
+ //Console.WriteLine("TEST-4");
+ // test to verify same region repeatedly to ensure that the persistece
+ // files are created and destroyed correctly
+
+ IRegion<object, object> subRegion;
+ String sqlite_dir = "SqLiteDir" + Process.GetCurrentProcess().Id.ToString();
+ for (int i = 0; i < 10; i++)
+ {
+ subRegion = CreateSubRegion(region, "SubRegion", "Apache.Geode.Plugins.SqLite",
+ "Apache.Geode.Plugins.SqLite.SqLiteImpl<System.Object,System.Object>.Create");
+ subRegion.DestroyRegion();
+ Assert.IsTrue(subRegion.IsDestroyed, "Expected region to be destroyed");
+ Assert.IsFalse(File.Exists(GetSqLiteFileName(sqlite_dir, "SubRegion")), "Persistence file present after region destroy");
+ }
+ //Console.WriteLine("TEST-5");
+ }
+
+ [Test]
+ public void OverflowPutGetManagedMT()
+ {
+ IRegion<object, object> region = CreateOverflowRegion("OverFlowRegion", "Apache.Geode.Plugins.SqLite",
+ "Apache.Geode.Plugins.SqLite.SqLiteImpl<System.Object,System.Object>.Create");
+ ValidateAttributes(region);
+
+ List<Thread> threadsList = new List<Thread>();
+ for (int i = 0; i < 10; i++)
+ {
+ Thread t = new Thread(delegate()
+ {
+ // put some values into the cache.
+ DoNput(region, 100);
+ CheckNumOfEntries(region, 100);
+
+ // check whether value get evicted and token gets set as overflow
+ CheckOverflowToken(region, 100, 20);
+ // do some gets... printing what we find in the cache.
+ DoNget(region, 100);
+ TestEntryDestroy(region);
+ TestGetOp(region, 100);
+ });
+ threadsList.Add(t);
+ t.Start();
+ }
+
+ for (int i = 0; i < 10; i++)
+ {
+ threadsList[i].Join();
+ }
+ region.DestroyRegion();
+ //Console.WriteLine("TEST-5");
+ }
+
+ [Test]
+ public void OverflowPutGetManagedSetInstance()
+ {
+ RegionFactory rf = CacheHelper.DCache.CreateRegionFactory(RegionShortcut.LOCAL);
+ rf.SetCachingEnabled(true);
+ rf.SetLruEntriesLimit(20);
+ rf.SetInitialCapacity(1000);
+ rf.SetDiskPolicy(DiskPolicyType.Overflows);
+
+ Properties<string, string> sqliteProperties = new Properties<string, string>();
+ sqliteProperties.Insert("PageSize", "65536");
+ sqliteProperties.Insert("MaxFileSize", "512000000");
+ String sqlite_dir = "SqLiteDir" + Process.GetCurrentProcess().Id.ToString();
+ sqliteProperties.Insert("PersistenceDirectory", sqlite_dir);
+
+ //rf.SetPersistenceManager(new Apache.Geode.Plugins.SQLite.SqLiteImpl<object, object>(), sqliteProperties);
+ rf.SetPersistenceManager("SqLiteImpl", "createSqLiteInstance", sqliteProperties);
+
+ CacheHelper.Init();
+ IRegion<object, object> region = CacheHelper.GetRegion<object, object>("OverFlowRegion");
+ if ((region != null) && !region.IsDestroyed)
+ {
+ region.GetLocalView().DestroyRegion();
+ Assert.IsTrue(region.IsDestroyed, "IRegion<object, object> OverFlowRegion was not destroyed.");
+ }
+ region = rf.Create<object, object>("OverFlowRegion");
+ Assert.IsNotNull(region, "IRegion<object, object> was not created.");
+ ValidateAttributes(region);
+
+ //Console.WriteLine("TEST-2");
+ // put some values into the cache.
+ DoNput(region, 100);
+ //Console.WriteLine("TEST-2.1 All PUts Donee");
+
+ CheckNumOfEntries(region, 100);
+
+ //Console.WriteLine("TEST-3");
+ // check whether value get evicted and token gets set as overflow
+ CheckOverflowToken(region, 100, 20);
+ // do some gets... printing what we find in the cache.
+ DoNget(region, 100);
+ TestEntryDestroy(region);
+ TestGetOp(region, 100);
+
+ //Console.WriteLine("TEST-4");
+ // test to verify same region repeatedly to ensure that the persistece
+ // files are created and destroyed correctly
+
+ IRegion<object, object> subRegion;
+ for (int i = 0; i < 1; i++)
+ {
+ subRegion = CreateSubRegion(region, "SubRegion", "Apache.Geode.Plugins.SqLite", "SqLiteImpl<object,object>.Create()");
+ subRegion.DestroyRegion();
+ Assert.IsTrue(subRegion.IsDestroyed, "Expected region to be destroyed");
+ Assert.IsFalse(File.Exists(GetSqLiteFileName(sqlite_dir, "SubRegion")), "Persistence file present after region destroy");
+ }
+ //Console.WriteLine("TEST-5");
+ }
+
+
+ [Test]
+ public void XmlCacheCreationWithOverflow()
+ {
+ Cache cache = null;
+ IRegion<object, object> region1;
+ IRegion<object, object> region2;
+ IRegion<object, object> region3;
+ IRegion<object, object>[] rootRegions;
+ //Region<object, object>[] subRegions;
+ ICollection<IRegion<object, object>> subRegions;
+ /*string host_name = "XML_CACHE_CREATION_TEST";*/
+ const UInt32 totalSubRegionsRoot1 = 2;
+ const UInt32 totalRootRegions = 3;
+
+ try
+ {
+ CacheHelper.CloseCache();
+ Util.Log("Creating cache with the configurations provided in valid_overflowAttr.xml");
+ string cachePath = CacheHelper.TestDir + Path.DirectorySeparatorChar + "valid_overflowAttr.xml";
+ cache = CacheFactory.CreateCacheFactory().Set("cache-xml-file", cachePath).Create();
+ Util.Log("Successfully created the cache.");
+ rootRegions = cache.RootRegions<object, object>();
+ Assert.IsNotNull(rootRegions);
+ Assert.AreEqual(totalRootRegions, rootRegions.Length);
+
+ Util.Log("Root regions in Cache: ");
+ foreach (IRegion<object, object> rg in rootRegions)
+ {
+ Util.Log('\t' + rg.Name);
+ }
+
+ region1 = rootRegions[0];
+ //subRegions = region1.SubRegions(true);
+ subRegions = region1.SubRegions(true);
+ Assert.IsNotNull(subRegions);
+ Assert.AreEqual(subRegions.Count, totalSubRegionsRoot1);
+
+ Util.Log("SubRegions for the root region: ");
+ foreach (IRegion<object, object> rg in subRegions)
+ {
+ Util.Log('\t' + rg.Name);
+ }
+
+ Util.Log("Testing if the nesting of regions is correct...");
+ region2 = rootRegions[1];
+ subRegions = region2.SubRegions(true);
+ string childName;
+ string parentName;
+ foreach (IRegion<object, object> rg in subRegions)
+ {
+ childName = rg.Name;
+ IRegion<object, object> parent = rg.ParentRegion;
+ parentName = parent.Name;
+ if (childName == "SubSubRegion221")
+ {
+ Assert.AreEqual("SubRegion22", parentName);
+ }
+ }
+
+ region3 = rootRegions[2];
+ //subRegions = region1.SubRegions(true);
+ subRegions = region3.SubRegions(true);
+ Assert.IsNotNull(subRegions);
+ Assert.AreEqual(subRegions.Count, totalSubRegionsRoot1);
+
+ Util.Log("SubRegions for the root region: ");
+ foreach (IRegion<object, object> rg in subRegions)
+ {
+ Util.Log('\t' + rg.Name);
+ }
+
+ Apache.Geode.Client.RegionAttributes<object, object> attrs = region1.Attributes;
+ //Util.Log("Attributes of root region Root1 are: ");
+
+ bool cachingEnabled = attrs.CachingEnabled;
+ Assert.IsTrue(cachingEnabled);
+
+ uint lruEL = attrs.LruEntriesLimit;
+ Assert.AreEqual(35, lruEL);
+
+ int concurrency = attrs.ConcurrencyLevel;
+ Assert.AreEqual(10, concurrency);
+
+ int initialCapacity = attrs.InitialCapacity;
+ Assert.AreEqual(25, initialCapacity);
+
+ int regionIdleTO = attrs.RegionIdleTimeout;
+ Assert.AreEqual(20, regionIdleTO);
+
+ ExpirationAction action1 = attrs.RegionIdleTimeoutAction;
+ Assert.AreEqual(ExpirationAction.Destroy, action1);
+
+ DiskPolicyType type = attrs.DiskPolicy;
+ Assert.AreEqual(DiskPolicyType.Overflows, type);
+ string persistenceDir, maxPageCount, pageSize;
+
+ string lib = attrs.PersistenceLibrary;
+ string libFun = attrs.PersistenceFactory;
+ Util.Log(" persistence library1 = " + lib);
+ Util.Log(" persistence function1 = " + libFun);
+ Properties<string, string> pconfig = attrs.PersistenceProperties;
+ Assert.IsNotNull(pconfig, "Persistence properties should not be null for root1.");
+ persistenceDir = (string)pconfig.Find("PersistenceDirectory");
+ maxPageCount = (string)pconfig.Find("MaxPageCount");
+ pageSize = (string)pconfig.Find("PageSize");
+ Assert.IsNotNull(persistenceDir, "Persistence directory should not be null.");
+ Assert.AreNotEqual(0, persistenceDir.Length, "Persistence directory should not be empty.");
+ Assert.IsNotNull(maxPageCount, "Persistence MaxPageCount should not be null.");
+ Assert.AreNotEqual(0, maxPageCount.Length, "Persistence MaxPageCount should not be empty.");
+ Assert.IsNotNull(pageSize, "Persistence PageSize should not be null.");
+ Assert.AreNotEqual(0, pageSize.Length, "Persistence PageSize should not be empty.");
+ Util.Log("****Attributes of Root1 are correctly set****");
+
+ Apache.Geode.Client.RegionAttributes<object, object> attrs2 = region2.Attributes;
+ string lib2 = attrs2.PersistenceLibrary;
+ string libFun2 = attrs2.PersistenceFactory;
+ Util.Log(" persistence library2 = " + lib2);
+ Util.Log(" persistence function2 = " + libFun2);
+ Properties<string, string> pconfig2 = attrs2.PersistenceProperties;
+ Assert.IsNotNull(pconfig2, "Persistence properties should not be null for root2.");
+ persistenceDir = (string)pconfig2.Find("PersistenceDirectory");
+ maxPageCount = (string)pconfig2.Find("MaxPageCount");
+ maxPageCount = (string)pconfig2.Find("PageSize");
+ Assert.IsNotNull(persistenceDir, "Persistence directory should not be null.");
+ Assert.AreNotEqual(0, persistenceDir.Length, "Persistence directory should not be empty.");
+ Assert.IsNotNull(maxPageCount, "Persistence MaxPageCount should not be null.");
+ Assert.AreNotEqual(0, maxPageCount.Length, "Persistence MaxPageCount should not be empty.");
+ Assert.IsNotNull(pageSize, "Persistence PageSize should not be null.");
+ Assert.AreNotEqual(0, pageSize.Length, "Persistence PageSize should not be empty.");
+
+ Util.Log("****Attributes of Root2 are correctly set****");
+
+ Apache.Geode.Client.RegionAttributes<object, object> attrs3 = region3.Attributes;
+ //Util.Log("Attributes of root region Root1 are: ");
+
+ Assert.IsTrue(attrs3.CachingEnabled);
+ Assert.AreEqual(35, attrs3.LruEntriesLimit);
+ Assert.AreEqual(10, attrs3.ConcurrencyLevel);
+ Assert.AreEqual(25, attrs3.InitialCapacity);
+ Assert.AreEqual(20, attrs3.RegionIdleTimeout);
+ Assert.AreEqual(ExpirationAction.Destroy, attrs3.RegionIdleTimeoutAction);
+ Assert.AreEqual(DiskPolicyType.Overflows, attrs3.DiskPolicy);
+
+ Util.Log(" persistence library1 = " + attrs3.PersistenceLibrary);
+ Util.Log(" persistence function1 = " + attrs3.PersistenceFactory);
+ Properties<string, string> pconfig3 = attrs.PersistenceProperties;
+ Assert.IsNotNull(pconfig3, "Persistence properties should not be null for root1.");
+ Assert.IsNotNull(pconfig3.Find("PersistenceDirectory"), "Persistence directory should not be null.");
+ Assert.AreNotEqual(0, pconfig3.Find("PersistenceDirectory").Length, "Persistence directory should not be empty.");
+ Assert.IsNotNull(pconfig3.Find("MaxPageCount"), "Persistence MaxPageCount should not be null.");
+ Assert.AreNotEqual(0, pconfig3.Find("MaxPageCount").Length, "Persistence MaxPageCount should not be empty.");
+ Assert.IsNotNull(pconfig3.Find("PageSize"), "Persistence PageSize should not be null.");
+ Assert.AreNotEqual(0, pconfig3.Find("PageSize"), "Persistence PageSize should not be empty.");
+ Util.Log("****Attributes of Root1 are correctly set****");
+
+ region1.DestroyRegion(null);
+ region2.DestroyRegion(null);
+ region3.DestroyRegion(null);
+
+ if (!cache.IsClosed)
+ {
+ cache.Close();
+ }
+
+ ////////////////////////////testing of cache.xml completed///////////////////
+
+
+ Util.Log("Create cache with the configurations provided in the invalid_overflowAttr1.xml.");
+
+ Util.Log("Non existent XML; exception should be thrown");
+
+ try
+ {
+ cachePath = CacheHelper.TestDir + Path.DirectorySeparatorChar + "non-existent.xml";
+ cache = CacheFactory.CreateCacheFactory().Set("cache-xml-file", cachePath).Create();
+ Assert.Fail("Creation of cache with non-existent.xml should fail!");
+ }
+ catch (CacheXmlException ex)
+ {
+ Util.Log("Expected exception with non-existent.xml: {0}", ex);
+ }
+
+ Util.Log("This is a well-formed xml....attributes not provided for persistence manager. exception should be thrown");
+
+ try
+ {
+ cachePath = CacheHelper.TestDir + Path.DirectorySeparatorChar + "invalid_overflowAttr1.xml";
+ cache = CacheFactory.CreateCacheFactory().Set("cache-xml-file", cachePath).Create();
+ Assert.Fail("Creation of cache with invalid_overflowAttr1.xml should fail!");
+ }
+ catch (IllegalStateException ex)
+ {
+ Util.Log("Expected exception with invalid_overflowAttr1.xml: {0}", ex);
+ }
+
+ ///////////////testing of invalid_overflowAttr1.xml completed///////////////////
+
+ Util.Log("Create cache with the configurations provided in the invalid_overflowAttr2.xml.");
+ Util.Log("This is a well-formed xml....attribute values is not provided for persistence library name......should throw an exception");
+
+ try
+ {
+ cachePath = CacheHelper.TestDir + Path.DirectorySeparatorChar + "invalid_overflowAttr2.xml";
+ cache = CacheFactory.CreateCacheFactory().Set("cache-xml-file", cachePath).Create();
+ Assert.Fail("Creation of cache with invalid_overflowAttr2.xml should fail!");
+ }
+ catch (CacheXmlException ex)
+ {
+ Util.Log("Expected exception with invalid_overflowAttr2.xml: {0}", ex);
+ }
+
+ ///////////////testing of invalid_overflowAttr2.xml completed///////////////////
+
+ Util.Log("Create cache with the configurations provided in the invalid_overflowAttr3.xml.");
+ Util.Log("This is a well-formed xml....but region-attributes for persistence invalid......should throw an exception");
+
+ try
+ {
+ cachePath = CacheHelper.TestDir + Path.DirectorySeparatorChar + "invalid_overflowAttr3.xml";
+ cache = CacheFactory.CreateCacheFactory().Set("cache-xml-file", cachePath).Create();
+ Assert.Fail("Creation of cache with invalid_overflowAttr3.xml should fail!");
+ }
+ catch (CacheXmlException ex)
+ {
+ Util.Log("Expected exception with invalid_overflowAttr3.xml: {0}", ex);
+ }
+
+ ///////////////testing of invalid_overflowAttr3.xml completed///////////////////
+ }
+ catch (Exception ex)
+ {
+ Assert.Fail("Caught exception: {0}", ex);
+ }
+ finally
+ {
+ if (cache != null && !cache.IsClosed)
+ {
+ cache.Close();
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/PutGetPerfTests.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/PutGetPerfTests.cs b/clicache/integration-test/PutGetPerfTests.cs
new file mode 100644
index 0000000..8268742
--- /dev/null
+++ b/clicache/integration-test/PutGetPerfTests.cs
@@ -0,0 +1,333 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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;
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+
+ [TestFixture]
+ public class PutGetPerfTests : UnitTests
+ {
+ #region Constants
+
+ private const int MaxKeys = 25000;
+ private const bool Mirrored = false;
+
+ #endregion
+
+ private CacheableString[] keysA = null;
+ private CacheableString[] keysB = null;
+ private CacheableString[] valuesA = null;
+ private CacheableString[] valuesB = null;
+
+ private CacheableInt32[] intKeysA = null;
+ private CacheableInt32[] intKeysB = null;
+ private CacheableInt32[] intValuesA = null;
+ private CacheableInt32[] intValuesB = null;
+
+ private UnitProcess m_client1, m_client2, m_client3, m_client4;
+
+ protected override ClientBase[] GetClients()
+ {
+ m_client1 = new UnitProcess();
+ m_client2 = new UnitProcess();
+ m_client3 = new UnitProcess();
+ m_client4 = new UnitProcess();
+ return new ClientBase[] { m_client1, m_client2, m_client3, m_client4 };
+ }
+
+ #region Private functions
+
+ private void InitStringObjects(int num, string prefix,
+ ref CacheableString[] strings)
+ {
+ if (num > 0)
+ {
+ strings = new CacheableString[num];
+ for (int i = 1; i <= num; i++)
+ {
+ strings[i - 1] = new CacheableString(prefix + i.ToString());
+ }
+ }
+ }
+
+ private void InitIntObjects(int num, int offset, int factor,
+ ref CacheableInt32[] ints)
+ {
+ if (num > 0)
+ {
+ ints = new CacheableInt32[num];
+ for (int i = 1; i <= num; i++)
+ {
+ ints[i - 1] = new CacheableInt32(offset + i * factor);
+ }
+ }
+ }
+
+ private void Puts(CacheableKey[] keys, Serializable[] values,
+ int offset, int numIters, int step)
+ {
+ if (keys != null && values != null && keys.Length == values.Length)
+ {
+ int numKeys = keys.Length;
+ if (numIters <= 0)
+ {
+ numIters = numKeys;
+ }
+ for (int i = offset; i < offset + numIters; i += step)
+ {
+ CacheHelper.CurrentRegion.Put(keys[i % numKeys], values[i % numKeys]);
+ }
+ }
+ }
+
+ private void Gets(CacheableKey[] keys,
+ int offset, int numIters, int step)
+ {
+ if (keys != null)
+ {
+ int numKeys = keys.Length;
+ if (numIters <= 0)
+ {
+ numIters = numKeys;
+ }
+ for (int i = offset; i < offset + numIters; i += step)
+ {
+ CacheHelper.CurrentRegion.Get(keys[i % numKeys]);
+ }
+ }
+ }
+
+ #endregion
+
+ #region Functions that are invoked by the tests
+
+ public enum RegionOp { Put, Get }
+ public enum KeysSelect { KeysA, KeysB, IntKeysA, IntKeysB }
+
+ public void InitKeysValues(int num)
+ {
+ InitStringObjects(num, "KeysA - ", ref keysA);
+ InitStringObjects(num, "KeysB - ", ref keysB);
+ InitStringObjects(num, "ValuesA - ", ref valuesA);
+ InitStringObjects(num, "ValuesB - ", ref valuesB);
+
+ InitIntObjects(num, 1, 2, ref intKeysA);
+ InitIntObjects(num, 0, 2, ref intKeysB);
+ InitIntObjects(num, 0, 2, ref intValuesA);
+ InitIntObjects(num, 1, 2, ref intValuesB);
+ }
+
+ public void RegionOpsAB(RegionOp op, KeysSelect sel,
+ int offset, int numIters, int step)
+ {
+ CacheableKey[] keys = null;
+ Serializable[] values = null;
+ switch (sel)
+ {
+ case KeysSelect.KeysA:
+ keys = (CacheableKey[])keysA;
+ values = (Serializable[])valuesA;
+ break;
+ case KeysSelect.KeysB:
+ keys = (CacheableKey[])keysB;
+ values = (Serializable[])valuesB;
+ break;
+ case KeysSelect.IntKeysA:
+ keys = (CacheableKey[])intKeysA;
+ values = (Serializable[])intValuesA;
+ break;
+ case KeysSelect.IntKeysB:
+ keys = (CacheableKey[])intKeysB;
+ values = (Serializable[])intValuesB;
+ break;
+ }
+ switch (op)
+ {
+ case RegionOp.Put:
+ Puts(keys, values, offset, numIters, step);
+ break;
+ case RegionOp.Get:
+ Gets(keys, offset, numIters, step);
+ break;
+ }
+ }
+
+ public void CheckNumKeys(int numExpected)
+ {
+ int numKeys = 0;
+ string message;
+ IGeodeSerializable[] keys = CacheHelper.CurrentRegion.GetKeys();
+ if (keys != null)
+ {
+ numKeys = keys.Length;
+ }
+ if (numExpected == 0)
+ {
+ message = "Region is not empty.";
+ }
+ else
+ {
+ message = "Region does not contain the expected number of entries.";
+ }
+ Assert.AreEqual(numExpected, numKeys, message);
+ }
+
+ #endregion
+
+ [TestFixtureSetUp]
+ public override void InitTests()
+ {
+ base.InitTests();
+
+ m_client1.Call(InitKeysValues, MaxKeys);
+ m_client2.Call(InitKeysValues, MaxKeys);
+ m_client3.Call(InitKeysValues, MaxKeys);
+ m_client4.Call(InitKeysValues, MaxKeys);
+ }
+
+ private void DoCommonDistribTests(string putTestName, int putIters,
+ string failTestName, int failIters, string proc2TestName)
+ {
+ StartTimer();
+ m_client1.Call(RegionOpsAB, RegionOp.Put, KeysSelect.KeysA, 0, putIters, 1);
+ LogTaskTiming(m_client1, putTestName, putIters);
+
+ StartTimer();
+ m_client1.Call(RegionOpsAB, RegionOp.Get, KeysSelect.KeysB, 0, failIters, 1);
+ LogTaskTiming(m_client1, failTestName, failIters);
+
+
+ m_client2.Call(CheckNumKeys, 0);
+ StartTimer();
+ m_client2.Call(RegionOpsAB, RegionOp.Get, KeysSelect.KeysA, 0, MaxKeys, 1);
+ LogTaskTiming(m_client2, proc2TestName, MaxKeys);
+ m_client2.Call(CheckNumKeys, MaxKeys);
+ }
+
+ [Test]
+ public void NoPeers()
+ {
+ int numIters = 50 * MaxKeys;
+
+ m_client1.Call(CacheHelper.CreateScopeRegion, "LocalOnly", ScopeType.Local, true);
+
+ StartTimer();
+ m_client1.Call(RegionOpsAB, RegionOp.Put, KeysSelect.KeysA, 0, numIters, 1);
+ LogTaskTiming(m_client1, "LocalPuts", numIters);
+
+ StartTimer();
+ m_client1.Call(RegionOpsAB, RegionOp.Get, KeysSelect.KeysA, 0, numIters, 1);
+ LogTaskTiming(m_client1, "LocalGets", numIters);
+
+ StartTimer();
+ m_client1.Call(RegionOpsAB, RegionOp.Get, KeysSelect.KeysB, 0, numIters, 1);
+ LogTaskTiming(m_client1, "LocalFailGets", numIters);
+
+ m_client1.Call(CacheHelper.DestroyRegion, "LocalOnly", false, true);
+
+ m_client1.Call(CacheHelper.CreateScopeRegion, "DistNoPeers", ScopeType.DistributedNoAck, true);
+
+ StartTimer();
+ m_client1.Call(RegionOpsAB, RegionOp.Put, KeysSelect.KeysA, 0, numIters, 1);
+ LogTaskTiming(m_client1, "DistNoPeersPuts", numIters);
+
+ m_client1.Call(CacheHelper.DestroyRegion, "DistNoPeers", false, true);
+ }
+
+ [Test]
+ public void NoAck2Proc()
+ {
+ m_client1.Call(CacheHelper.CreateScopeRegion, "NoAck2Proc", ScopeType.DistributedNoAck, true);
+ m_client2.Call(CacheHelper.CreateScopeRegion, "NoAck2Proc", ScopeType.DistributedNoAck, true);
+
+ DoCommonDistribTests("NoAck2ProcPuts", 10 * MaxKeys,
+ "NoAck2ProcNetsearchFail", 2 * MaxKeys, "NoAck2ProcNetsearch");
+
+ m_client1.Call(CacheHelper.DestroyRegion, "NoAck2Proc", false, true);
+ }
+
+ [Test]
+ public void Ack2Proc()
+ {
+ m_client1.Call(CacheHelper.CreateScopeRegion, "Ack2Proc", ScopeType.DistributedAck, true);
+ m_client2.Call(CacheHelper.CreateScopeRegion, "Ack2Proc", ScopeType.DistributedAck, true);
+
+ DoCommonDistribTests("Ack2ProcPuts", 2 * MaxKeys,
+ "Ack2ProcNetsearchFail", MaxKeys, "Ack2ProcNetsearch");
+
+ m_client1.Call(CacheHelper.DestroyRegion, "Ack2Proc", false, true);
+ }
+
+ [Test]
+ public void NoAck3Proc()
+ {
+ m_client1.Call(CacheHelper.CreateScopeRegion, "NoAck3Proc", ScopeType.DistributedNoAck, true);
+ m_client2.Call(CacheHelper.CreateScopeRegion, "NoAck3Proc", ScopeType.DistributedNoAck, true);
+ m_client3.Call(CacheHelper.CreateScopeRegion, "NoAck3Proc", ScopeType.DistributedNoAck, true);
+
+ DoCommonDistribTests("NoAck3ProcPuts", 2 * MaxKeys,
+ "NoAck3ProcNetsearchFail", MaxKeys, "NoAck3ProcNetsearch");
+
+ m_client1.Call(CacheHelper.DestroyRegion, "NoAck3Proc", false, true);
+ }
+
+ [Test]
+ public void Ack3Proc()
+ {
+ m_client1.Call(CacheHelper.CreateScopeRegion, "Ack3Proc", ScopeType.DistributedAck, true);
+ m_client2.Call(CacheHelper.CreateScopeRegion, "Ack3Proc", ScopeType.DistributedAck, true);
+ m_client3.Call(CacheHelper.CreateScopeRegion, "Ack3Proc", ScopeType.DistributedAck, true);
+
+ DoCommonDistribTests("Ack3ProcPuts", MaxKeys,
+ "Ack3ProcNetsearchFail", MaxKeys, "Ack3ProcNetsearch");
+
+ m_client1.Call(CacheHelper.DestroyRegion, "Ack3Proc", false, true);
+ }
+
+ [Test]
+ public void NoAck4Proc()
+ {
+ m_client1.Call(CacheHelper.CreateScopeRegion, "NoAck4Proc", ScopeType.DistributedNoAck, true);
+ m_client2.Call(CacheHelper.CreateScopeRegion, "NoAck4Proc", ScopeType.DistributedNoAck, true);
+ m_client3.Call(CacheHelper.CreateScopeRegion, "NoAck4Proc", ScopeType.DistributedNoAck, true);
+ m_client4.Call(CacheHelper.CreateScopeRegion, "NoAck4Proc", ScopeType.DistributedNoAck, true);
+
+ DoCommonDistribTests("NoAck4ProcPuts", MaxKeys,
+ "NoAck4ProcNetsearchFail", MaxKeys, "NoAck4ProcNetsearch");
+
+ m_client1.Call(CacheHelper.DestroyRegion, "NoAck4Proc", false, true);
+ }
+
+ [Test]
+ public void Ack4Proc()
+ {
+ m_client1.Call(CacheHelper.CreateScopeRegion, "Ack4Proc", ScopeType.DistributedAck, true);
+ m_client2.Call(CacheHelper.CreateScopeRegion, "Ack4Proc", ScopeType.DistributedAck, true);
+ m_client3.Call(CacheHelper.CreateScopeRegion, "Ack4Proc", ScopeType.DistributedAck, true);
+ m_client4.Call(CacheHelper.CreateScopeRegion, "Ack4Proc", ScopeType.DistributedAck, true);
+
+ DoCommonDistribTests("Ack4ProcPuts", MaxKeys,
+ "Ack4ProcNetsearchFail", MaxKeys, "Ack4ProcNetsearch");
+
+ m_client1.Call(CacheHelper.DestroyRegion, "Ack4Proc", false, true);
+ }
+ }
+}