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:52:59 UTC
[43/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/PutGetTestsN.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/PutGetTestsN.cs b/clicache/integration-test/PutGetTestsN.cs
new file mode 100644
index 0000000..2147821
--- /dev/null
+++ b/clicache/integration-test/PutGetTestsN.cs
@@ -0,0 +1,536 @@
+/*
+ * 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.Collections.Generic;
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+ // using Apache.Geode.Client;
+ using Apache.Geode.Client;
+ //using Region = Apache.Geode.Client.IRegion<Object, Object>;
+
+ [TestFixture]
+ [Category("group1")]
+ [Category("unicast_only")]
+ [Category("generics")]
+ public class PutGetTests : UnitTests
+ {
+ #region Private members and constants
+
+ public const int NumKeys = 20;
+ public const int KeySize = 256;
+ public const int ValueSize = 4096;
+ private const string RegionName = "PutGetTest";
+ private const string KeyChecksumPrefix = "KeyChecksum:";
+ private const string ValChecksumPrefix = "ValChecksum:";
+ private UnitProcess m_client1, m_client2;
+ private IRegion<object, object> m_region;
+ private CacheableKeyWrapper[] m_cKeys;
+ private uint[] m_cKeyCksums;
+ private CacheableWrapper[] m_cValues;
+ private uint[] m_cValCksums;
+ private static string FEOnRegionPrSHOP_OptimizeForWrite = "FEOnRegionPrSHOP_OptimizeForWrite";
+ private static string FEOnRegionPrSHOP = "FEOnRegionPrSHOP";
+ private static string getFuncName = "MultiGetFunction";
+
+ #endregion
+
+ protected override ClientBase[] GetClients()
+ {
+ m_client1 = new UnitProcess();
+ m_client2 = new UnitProcess();
+ return new ClientBase[] { m_client1, m_client2 };
+ }
+
+ #region Public accessors
+
+ public CacheableWrapper[] CacheableKeys
+ {
+ get
+ {
+ return m_cKeys;
+ }
+ }
+
+ public CacheableWrapper[] CacheableValues
+ {
+ get
+ {
+ return m_cValues;
+ }
+ }
+
+ #endregion
+
+ #region Private functions
+
+ private Type GetValueType()
+ {
+ Type valType = null;
+ if (m_cValues[0].Cacheable != null)
+ {
+ valType = m_cValues[0].Cacheable.GetType();
+ }
+ return valType;
+ }
+
+ #endregion
+
+ #region Functions invoked by the tests
+
+ /// <summary>
+ /// Initialize the keys for different key types.
+ /// </summary>
+ public int InitKeys(UInt32 typeId, int numKeys, int maxSize)
+ {
+ Util.Log("InitKeys typeId " + typeId + " numKeys= " + numKeys + "maxSize=" + maxSize);
+ Assert.Greater(numKeys, 0,
+ "Number of keys should be greater than zero.");
+ Type type = CacheableWrapperFactory.GetTypeForId(typeId);
+ CacheableKeyWrapper instance = CacheableWrapperFactory.CreateKeyInstance(typeId);
+ Assert.IsNotNull(instance, "InitKeys: Type '{0}' could not be instantiated.", type.Name);
+ int maxKeys = instance.MaxKeys;
+ if (numKeys > maxKeys)
+ {
+ numKeys = maxKeys;
+ }
+ m_cKeys = new CacheableKeyWrapper[numKeys];
+ m_cKeyCksums = new uint[numKeys];
+ for (int keyIndex = 0; keyIndex < numKeys; keyIndex++)
+ {
+ instance = CacheableWrapperFactory.CreateKeyInstance(typeId);
+ instance.InitKey(keyIndex, maxSize);
+ m_cKeyCksums[keyIndex] = instance.GetChecksum();
+ m_cKeys[keyIndex] = instance;
+ }
+
+ Util.Log("InitKeys final m_cKeyCksums " + m_cKeyCksums.Length + " m_cKeys:" + m_cKeys.Length + "numKeys: " + numKeys);
+ return numKeys;
+ }
+
+ /// <summary>
+ /// Initialize the values to random values for different value types.
+ /// </summary>
+ public void InitValues(UInt32 typeId, int numValues, int maxSize)
+ {
+ Util.Log("InitValues typeId " + typeId + " numKeys= " + numValues + "maxSize=" + maxSize);
+ Assert.Greater(numValues, 0,
+ "Number of values should be greater than zero.");
+ Type type = CacheableWrapperFactory.GetTypeForId(typeId);
+ m_cValues = new CacheableWrapper[numValues];
+ m_cValCksums = new uint[numValues];
+ CacheableWrapper instance;
+ for (int valIndex = 0; valIndex < numValues; valIndex++)
+ {
+ instance = CacheableWrapperFactory.CreateInstance(typeId);
+ Util.Log(" in initvalue type " + instance.GetType().ToString());
+ Assert.IsNotNull(instance, "InitValues: Type '{0}' could not be instantiated.",
+ type.Name);
+ instance.InitRandomValue(maxSize);
+ m_cValCksums[valIndex] = instance.GetChecksum();
+ m_cValues[valIndex] = instance;
+ }
+
+ Util.Log("InitValues final m_cValCksums " + m_cValCksums.Length + " m_cValues:" + m_cValues.Length);
+ }
+
+ public void SetRegion(string regionName)
+ {
+ m_region = CacheHelper.GetVerifyRegion<object, object>(regionName);
+ }
+
+ public void DoPuts()
+ {
+ Assert.IsNotNull(m_cKeys, "DoPuts: null keys array.");
+ Assert.IsNotNull(m_cValues, "DoPuts: null values array.");
+ Assert.IsNotNull(m_region, "DoPuts: null region.");
+
+ for (int keyIndex = 0; keyIndex < m_cKeys.Length; keyIndex++)
+ {
+ object key = m_cKeys[keyIndex].CacheableKey;
+ object val = m_cValues[keyIndex].Cacheable;
+ if (val != null)
+ {
+ Util.Log(" DoPuts() key hashcode " + key.GetHashCode());
+ Util.Log(" DoPuts() " + key.GetType().ToString() + " : " + val.GetType().ToString());
+ m_region[key] = val;
+ }
+ else
+ {
+ try
+ {
+ m_region.Remove(key);//Destroy() replaced by Remove() Api
+ }
+ catch (EntryNotFoundException)
+ {
+ // expected
+ }
+ m_region.Add(key, val); //Create() replaced by Add() Api.
+ }
+ }
+ Util.Log("DoPuts completed for keyType [{0}], valType [{1}].",
+ m_cKeys[0].CacheableKey.GetType(), GetValueType());
+ }
+
+ public void DoHashPuts()
+ {
+ Assert.IsNotNull(m_cKeys, "DoPuts: null keys array.");
+ Assert.IsNotNull(m_region, "DoPuts: null region.");
+ for (int keyIndex = 0; keyIndex < m_cKeys.Length; keyIndex++)
+ {
+ object key = m_cKeys[keyIndex].CacheableKey;
+
+ //TODO: GetHashCode() is C# builtIn function. it needs to match with our implementation of GetHashCode().
+ //Console.WriteLine("Key type = {0}", key.GetType());
+
+ //int val = key.GetHashCodeN();
+ int val = key.GetHashCode();
+ m_region[key] = val;
+ }
+ }
+
+ public void DoPRSHPartitionResolverPuts(string rname)
+ {
+
+ }
+
+ public void DoPRSHTradeResolverTasks(string rname)
+ {
+
+ }
+
+ public void DoPRSHFixedPartitionResolverTests(string rname)
+ {
+ IRegion<object, object> region = CacheHelper.GetRegion<object, object>(rname);
+ int metadatarefreshCount = 0;
+ int metadatarefreshCount1 = 0;
+ Assert.IsNotNull(region, "DoPRSHPartitionResolverPuts: null region.");
+ Util.Log("Inside DoPRSHFixedPartitionResolverTests region name is {0} ", region.Name.ToString());
+ for (int i = 0; i < 2000; i++)
+ {
+ try
+ {
+ int key = i;
+ int val = key/*.GetHashCode()*/;
+ region[key] = val;
+ Util.Log("Put inside DoPRSHFixedPartitionResolverTests successfull {0} {1}", key, val);
+ }
+ catch (CacheServerException ex)
+ {
+ Util.Log("CacheServerException: Put caused networkhop");
+ Assert.Fail("Got CacheServerException (0}", ex.Message);
+ }
+ catch (CacheWriterException ex)
+ {
+ Util.Log("CacheWriterException: Put caused networkhop");
+ Assert.Fail("Got CacheWriterException (0}", ex.Message);
+ }
+ catch (Exception ex)
+ {
+ Util.Log("Exception: Put caused networkhop ");
+ Util.Log("Got Exception (0} {1} {2} ", ex.Message, ex.StackTrace, ex.Source);
+ Assert.Fail("Got Exception (0} {1} {2} ", ex.Message, ex.StackTrace, ex.Source);
+ }
+ }
+
+ }
+
+ public void DoPRSHFixedPartitionResolverTasks(ClientBase client1, string regionName)
+ {
+ client1.Call(DoPRSHFixedPartitionResolverTests, regionName);
+ }
+
+ public void DoPRSHPartitionResolverTasks(ClientBase client1, ClientBase client2, string regionName)
+ {
+ client1.Call(DoPRSHPartitionResolverPuts, regionName);
+ client2.Call(DoPRSHPartitionResolverPuts, regionName);
+ }
+
+ public void DoHashCodePuts(ClientBase client1, ClientBase client2, string regionName)
+ {
+ client1.Call(DoHashPuts);
+ client2.Call(DoHashPuts);
+ }
+
+ public void DoKeyChecksumPuts()
+ {
+ Assert.IsNotNull(m_cKeyCksums, "PutKeyChecksums: null checksums array.");
+ Assert.IsNotNull(m_region, "PutKeyChecksums: null region.");
+ Util.Log("DoKeyChecksumPuts number of keys " + m_cKeyCksums.Length);
+ for (int keyIndex = 0; keyIndex < m_cKeyCksums.Length; keyIndex++)
+ {
+ m_region[KeyChecksumPrefix + keyIndex] = (int)m_cKeyCksums[keyIndex];
+ }
+ Util.Log("DoKeyChecksumPuts completed for keyType [{0}], valType [{1}].",
+ m_cKeys[0].CacheableKey.GetType(), GetValueType());
+ }
+
+ public void DoValChecksumPuts()
+ {
+ Assert.IsNotNull(m_cValCksums, "PutValChecksums: null checksums array.");
+ Assert.IsNotNull(m_region, "PutValChecksums: null region.");
+ Util.Log("DoValChecksumPuts number of keys " + m_cValCksums.Length);
+ for (int keyIndex = 0; keyIndex < m_cValCksums.Length; keyIndex++)
+ {
+ m_region[ValChecksumPrefix + keyIndex] = (int)m_cValCksums[keyIndex];
+ }
+ Util.Log("DoValChecksumPuts completed for keyType [{0}], valType [{1}].",
+ m_cKeys[0].CacheableKey.GetType(), GetValueType());
+ }
+
+ /// <summary>
+ /// Run a query on server for native client to force deserialization
+ /// on server and thereby check serialization/deserialization compability
+ /// between native clients and java server.
+ /// </summary>
+ public void DoRunQuery()
+ {
+ Assert.IsNotNull(m_cKeys, "DoGets: null keys array.");
+ Assert.IsNotNull(m_region, "DoGets: null region.");
+
+ // for a type that cannot be handled by server, delete these values
+ // before next query that will cause problem
+ Type valType = GetValueType();
+ if (CacheableHelper.IsUnhandledType(m_cValues[0].TypeId))
+ {
+ Util.Log("DoRunQuery: deleting entries with value type {0}", valType);
+ for (int keyIndex = 0; keyIndex < m_cKeys.Length; keyIndex++)
+ {
+ m_region.Remove(m_cKeys[keyIndex].CacheableKey); // Destroy() -> Remove()
+ }
+ }
+ else
+ {
+ QueryService<object, object> qs = null;
+ qs = CacheHelper.DCache.GetPoolManager().Find(m_region.Attributes.PoolName).GetQueryService<object, object>();
+ Query<object> qry = qs.NewQuery("SELECT * FROM " + m_region.FullPath);
+ ISelectResults<object> results = qry.Execute();
+ // not really interested in results but loop through them neverthless
+ Util.Log("DoRunQuery: obtained {0} results", results.Size);
+ int numResults = 0;
+ foreach (object res in results)
+ {
+ ++numResults;
+ }
+ Assert.AreEqual(results.Size, numResults,
+ "Expected the number of results to match the size of ISelectResults");
+ }
+ Util.Log("DoQuery completed for keyType [{0}], valType [{1}].",
+ m_cKeys[0].CacheableKey.GetType(), valType);
+ }
+
+ public void DoGetsVerify()
+ {
+ Util.Log("DoGetsVerify: m_cKeys " + m_cKeys.Length);
+ Assert.IsNotNull(m_cKeys, "DoGetsVerify: null keys array.");
+ Assert.IsNotNull(m_cValues, "DoGetsVerify: null values array.");
+ Assert.IsNotNull(m_region, "DoGetsVerify: null region.");
+
+ for (int keyIndex = 0; keyIndex < m_cKeys.Length; keyIndex++)
+ {
+ Util.Log("DoGetsVerify key type " + m_cKeys[keyIndex].CacheableKey.GetType());
+ Object actualValue = m_region[m_cKeys[keyIndex].CacheableKey];
+
+ if (actualValue == null)
+ Util.Log("DoGetsVerify value is null");
+ else
+ Util.Log("DoGetsVerify value is not null ");
+ uint cksum = m_cKeys[keyIndex].GetChecksum();
+ //Util.Log("DoGetsVerify key clasid " + m_region[(KeyChecksumPrefix + keyIndex).ClassId]);
+ //Util.Log("DoGetsVerify key clasid " + m_region[(KeyChecksumPrefix + keyIndex).ClassId]);
+ //Util.Log("DoGetsVerify key type " + m_region.Get(KeyChecksumPrefix + keyIndex).GetType().ToString());
+ //CacheableInt32 putCksum = m_region[KeyChecksumPrefix + keyIndex] as CacheableInt32;
+ Util.Log("DoGetsVerify key type " + m_region[KeyChecksumPrefix + keyIndex].GetType().ToString());
+ int putCksum = (int)m_region[KeyChecksumPrefix + keyIndex];
+ Assert.IsNotNull(putCksum,
+ "DoGetsVerify: Could not find checksum for key at index {0}.",
+ keyIndex);
+ Assert.AreEqual(cksum, (uint)putCksum,
+ "DoGetsVerify: Checksums of the keys at index {0} differ.",
+ keyIndex);
+ Util.Log("actualValue Type = {0}", actualValue.GetType());
+ cksum = m_cValues[keyIndex].GetChecksum((object)actualValue);
+ putCksum = (int)m_region[ValChecksumPrefix + keyIndex];
+ Assert.IsNotNull(putCksum, "DoGetsVerify: Could not find checksum for value at index {0}.", keyIndex);
+ Assert.AreEqual(cksum, (uint)putCksum, "DoGetsVerify: Checksums of the values at index {0} differ.", keyIndex);
+
+ // Also check in local cache using GetEntry
+ Util.Log("DoGetsVerify() key hashcode " + m_cKeys[keyIndex].CacheableKey.GetHashCode());
+ RegionEntry<object, object> entry = m_region.GetEntry(m_cKeys[keyIndex].CacheableKey);
+
+ if (entry != null)
+ {
+ try
+ {
+ cksum = m_cValues[keyIndex].GetChecksum(entry.Value);
+ }
+ catch (Exception ex)
+ {
+ Util.Log("DoGetsVerify() got exception " + ex.Message);
+ Util.Log("DoGetsVerify() get stacktrace " + ex.StackTrace);
+ throw ex;
+ }
+ }
+ else
+ {
+ cksum = 0;
+ }
+ Assert.AreEqual(cksum, (uint)putCksum, "DoGetsVerify: " +
+ "Checksums of the values at index {0} differ using GetEntry.",
+ keyIndex);
+ }
+ Util.Log("DoGetsVerify completed for keyType [{0}], valType [{1}].",
+ m_cKeys[0].CacheableKey.GetType(), GetValueType());
+ }
+
+ public void DoGets()
+ {
+ Assert.IsNotNull(m_cKeys, "DoGets: null keys array.");
+ Assert.IsNotNull(m_region, "DoGets: null region.");
+
+ for (int keyIndex = 0; keyIndex < m_cKeys.Length; keyIndex++)
+ {
+ //Object actualValue = m_region[m_cKeys[keyIndex].CacheableKey];
+ Object actualValue = m_region[m_cKeys[keyIndex].CacheableKey];
+ if (actualValue == null)
+ {
+ Assert.AreEqual(GeodeClassIds.CacheableNullString,
+ m_cValues[keyIndex].TypeId, "Only null string should return a " +
+ "null object");
+ }
+ }
+ Util.Log("DoGets completed for keyType [{0}], valType [{1}].",
+ m_cKeys[0].CacheableKey.GetType(), GetValueType());
+ }
+
+ public void PutGetSteps(ClientBase client1, ClientBase client2,
+ string regionName, bool verifyGets, bool runQuery)
+ {
+ if (verifyGets)
+ {
+ client1.Call(DoPuts);
+ client1.Call(DoKeyChecksumPuts);
+ client1.Call(DoValChecksumPuts);
+ client2.Call(DoGetsVerify);
+ InvalidateRegion(regionName, client1);
+ if (runQuery)
+ {
+ // run a query for ThinClient regions to check for deserialization
+ // compability on server
+ client1.Call(DoRunQuery);
+ }
+ client2.Call(DoPuts);
+ client2.Call(DoKeyChecksumPuts);
+ client2.Call(DoValChecksumPuts);
+ client1.Call(DoGetsVerify);
+ }
+ else
+ {
+ client1.Call(DoPuts);
+ client2.Call(DoGets);
+ InvalidateRegion(regionName, client1);
+ client2.Call(DoPuts);
+ client1.Call(DoGets);
+ }
+ // this query invocation is primarily to delete the entries that cannot
+ // be deserialized by the server
+ if (runQuery)
+ {
+ client1.Call(DoRunQuery);
+ }
+ }
+
+ public void InvalidateRegion(string regionName, params ClientBase[] clients)
+ {
+ if (clients != null)
+ {
+ foreach (ClientBase client in clients)
+ {
+ client.Call(CacheHelper.InvalidateRegionNonGeneric, regionName, true, true);
+ }
+ }
+ }
+
+ public void TestAllKeyValuePairs(ClientBase client1, ClientBase client2,
+ string regionName, bool runQuery, long dtTicks)
+ {
+ ICollection<UInt32> registeredKeyTypeIds =
+ CacheableWrapperFactory.GetRegisteredKeyTypeIds();
+ ICollection<UInt32> registeredValueTypeIds =
+ CacheableWrapperFactory.GetRegisteredValueTypeIds();
+
+ client1.Call(CacheableHelper.RegisterBuiltins, dtTicks);
+ client2.Call(CacheableHelper.RegisterBuiltins, dtTicks);
+
+ foreach (UInt32 keyTypeId in registeredKeyTypeIds)
+ {
+ int numKeys;
+ client1.Call(InitKeys, out numKeys, keyTypeId, NumKeys, KeySize);
+ client2.Call(InitKeys, out numKeys, keyTypeId, NumKeys, KeySize);
+
+ Type keyType = CacheableWrapperFactory.GetTypeForId(keyTypeId);
+ foreach (UInt32 valueTypeId in registeredValueTypeIds)
+ {
+ client1.Call(InitValues, valueTypeId, numKeys, ValueSize);
+ client2.Call(InitValues, valueTypeId, numKeys, ValueSize);
+ Type valueType = CacheableWrapperFactory.GetTypeForId(valueTypeId);
+
+ Util.Log("Starting gets/puts with keyType '{0}' and valueType '{1}'",
+ keyType.Name, valueType.Name);
+ StartTimer();
+ Util.Log("Running warmup task which verifies the puts.");
+ PutGetSteps(client1, client2, regionName, true, runQuery);
+ Util.Log("End warmup task.");
+ LogTaskTiming(client1,
+ string.Format("IRegion<object, object>:{0},Key:{1},Value:{2},KeySize:{3},ValueSize:{4},NumOps:{5}",
+ regionName, keyType.Name, valueType.Name, KeySize, ValueSize, 4 * numKeys),
+ 4 * numKeys);
+
+ InvalidateRegion(regionName, client1, client2);
+
+ }
+ }
+ }
+
+ public void TestAllKeys(ClientBase client1, ClientBase client2, string regionName, long dtTime)
+ {
+ ICollection<UInt32> registeredKeyTypeIds =
+ CacheableWrapperFactory.GetRegisteredKeyTypeIds();
+ ICollection<UInt32> registeredValueTypeIds =
+ CacheableWrapperFactory.GetRegisteredValueTypeIds();
+
+ client1.Call(CacheableHelper.RegisterBuiltinsJavaHashCode, dtTime);
+ client2.Call(CacheableHelper.RegisterBuiltinsJavaHashCode, dtTime);
+
+ foreach (UInt32 keyTypeId in registeredKeyTypeIds)
+ {
+ int numKeys;
+ client1.Call(InitKeys, out numKeys, keyTypeId, NumKeys, KeySize);
+ client2.Call(InitKeys, out numKeys, keyTypeId, NumKeys, KeySize);
+ Type keyType = CacheableWrapperFactory.GetTypeForId(keyTypeId);
+ StartTimer();
+ Util.Log("Running warmup task which verifies the puts.");
+ DoHashCodePuts(client1, client2, regionName);
+ }
+ }
+
+ #endregion
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/RegionEntryTests.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/RegionEntryTests.cs b/clicache/integration-test/RegionEntryTests.cs
new file mode 100644
index 0000000..ba76dae
--- /dev/null
+++ b/clicache/integration-test/RegionEntryTests.cs
@@ -0,0 +1,105 @@
+/*
+ * 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 RegionEntryTests : UnitTests
+ {
+ private const string hostName = "REGIONENTRYTEST";
+ private const string regionName = "TESTREGIONENTRY_ROOT_REGION";
+ private Region region;
+
+ protected override ClientBase[] GetClients()
+ {
+ return null;
+ }
+
+ [TestFixtureSetUp]
+ public override void InitTests()
+ {
+ base.InitTests();
+ CacheHelper.InitName(hostName, hostName);
+ }
+
+ [TestFixtureTearDown]
+ public override void EndTests()
+ {
+ try
+ {
+ CacheHelper.Close();
+ }
+ finally
+ {
+ base.EndTests();
+ }
+ }
+
+ public void TestEntries(Region region, int num)
+ {
+ string regionName = region.Name;
+ Util.Log("Creating {0} entries in Region {1}", num, regionName);
+
+ for (int i = 0; i < num; i++)
+ {
+ region.Create(regionName + ": " + i.ToString(),
+ regionName + ": value of " + i.ToString());
+ }
+ ICacheableKey[] cKeys = region.GetKeys();
+ IGeodeSerializable[] cValues = region.GetValues();
+ Assert.AreEqual(num, cKeys.Length, "Number of keys in region is incorrect.");
+ Assert.AreEqual(num, cValues.Length, "Number of values in region is incorrect.");
+
+ foreach (ICacheableKey key in cKeys)
+ {
+ region.LocalInvalidate(key);
+ }
+ cKeys = region.GetKeys();
+ cValues = region.GetValues();
+ Assert.AreEqual(num, cKeys.Length, "Number of keys in region is incorrect after invalidate.");
+ Assert.AreEqual(0, cValues.Length, "Number of values in region is incorrect after invalidate.");
+
+ foreach (ICacheableKey key in cKeys)
+ {
+ region.LocalDestroy(key);
+ }
+ cKeys = region.GetKeys();
+ cValues = region.GetValues();
+ Assert.AreEqual(0, cKeys.Length, "Number of keys in region is incorrect after destroy.");
+ Assert.AreEqual(0, cValues.Length, "Number of values in region is incorrect after destroy.");
+ }
+
+ [Test]
+ public void RegionEntryFunction()
+ {
+ CacheHelper.CreatePlainRegion(regionName);
+ region = CacheHelper.GetVerifyRegion(regionName);
+
+ TestEntries(region, 10);
+ TestEntries(region, 100);
+ TestEntries(region, 10000);
+
+ region.LocalDestroyRegion();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/RegionOperationN.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/RegionOperationN.cs b/clicache/integration-test/RegionOperationN.cs
new file mode 100644
index 0000000..a0db56f
--- /dev/null
+++ b/clicache/integration-test/RegionOperationN.cs
@@ -0,0 +1,97 @@
+/*
+ * 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.Diagnostics;
+using System.Threading;
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+ using Apache.Geode.Client;
+
+ using Region = Apache.Geode.Client.IRegion<Object, Object>;
+ public class RegionOperation
+ {
+ protected IRegion<object, object> m_region;
+
+ public Region Region
+ {
+ get
+ {
+ return m_region;
+ }
+ }
+
+ public RegionOperation(string RegionName)
+ {
+ Serializable.RegisterPdxType(PdxTests.PdxTypes1.CreateDeserializable);
+ Serializable.RegisterPdxType(PdxTests.PdxTypes8.CreateDeserializable);
+ m_region = CacheHelper.GetRegion<object, object>(RegionName);
+ }
+
+ public void PutOp(int key, Object CallbackArg)
+ {
+
+ Object value = "value";
+ for (int i = 1; i <= key; i++)
+ {
+ Util.Log("PutOp:key={0},value={1}",i,value);
+ m_region.Put(i,value,CallbackArg);
+ //m_region[10000 + i] = new PdxTests.PdxTypes1();
+ m_region[10000 + i] = new PdxTests.PdxTypes8();
+ }
+ }
+
+ public void InvalidateOp(int key, Object CallbackArg)
+ {
+ for (int i = 1; i <= key; i++)
+ {
+ Util.Log("InvalidateOp:key={0}", i);
+ m_region.GetLocalView().Invalidate(i, CallbackArg);
+ }
+ }
+
+ public void DestroyOp(int key, Object CallbackArg)
+ {
+ for (int i = 1; i <= key; i++)
+ {
+ Util.Log("DestroyOp:key={0}", i);
+ m_region.Remove(i, CallbackArg);
+ }
+ }
+ public void DestroyOpWithPdxValue(int key, Object CallbackArg)
+ {
+ for (int i = 1; i <= key; i++)
+ {
+ Util.Log("DestroyOpWithPdxValue:key={0}", i);
+ m_region.Remove(i, CallbackArg);
+ m_region.Remove(10000 + i, null);
+ }
+ }
+
+ public void RemoveOp(int key, Object CallbackArg)
+ {
+
+ string value = "value";
+ for (int i = 1; i <= key; i++) {
+ Util.Log("PutOp:key={0},value={1}", i, value);
+ m_region.Remove(i, value, CallbackArg);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/RegionWrapperN.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/RegionWrapperN.cs b/clicache/integration-test/RegionWrapperN.cs
new file mode 100644
index 0000000..224db45
--- /dev/null
+++ b/clicache/integration-test/RegionWrapperN.cs
@@ -0,0 +1,243 @@
+/*
+ * 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.Diagnostics;
+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>;
+
+ public class RegionWrapper
+ {
+ protected IRegion<object, object> m_region;
+ protected bool m_noack;
+
+ public IRegion<object, object> Region
+ {
+ get
+ {
+ return m_region;
+ }
+ }
+
+ public RegionWrapper(IRegion<object, object> region)
+ {
+ if (region == null)
+ {
+ Assert.Fail("Cannot wrap null region.");
+ }
+ m_region = region;
+ }
+
+ public RegionWrapper(string name)
+ {
+ m_region = CacheHelper.GetRegion<object, object>(name);
+ if (m_region == null)
+ {
+ Assert.Fail("No region with name {0} found!", name);
+ }
+ }
+
+ public virtual void Put(int key, int value)
+ {
+ m_region["key" + key.ToString()] = value;
+ }
+
+ public virtual bool WaitForKey(string key)
+ {
+ return WaitForKey(key, 100, 100);
+ }
+
+ public virtual bool WaitForKey(string key, int maxTries, int sleepMillis)
+ {
+ int tries = 0;
+ bool found = false;
+
+ while ((tries < maxTries) && (!(found = m_region.ContainsKey(key))))
+ {
+ Thread.Sleep(sleepMillis);
+ tries++;
+ }
+ return found;
+ }
+
+ public virtual bool WaitForValue(ICacheableKey key)
+ {
+ return WaitForValue(key, 100, 100);
+ }
+
+ public virtual bool WaitForValue(ICacheableKey cKey, int maxTries, int sleepMillis)
+ {
+ int tries = 0;
+ bool found = false;
+
+ while ((tries++ < maxTries) && (!(found = m_region.ContainsValueForKey(cKey))))
+ {
+ Thread.Sleep(sleepMillis);
+ }
+ return found;
+ }
+
+ public virtual Object WaitForValueGet(ICacheableKey cKey,
+ int maxTries, int sleepMillis)
+ {
+ int tries = 0;
+ Object cVal = null;
+
+ while ((tries++ < maxTries) && ((cVal = m_region[cKey]) != null))
+ {
+ Thread.Sleep(sleepMillis);
+ }
+ return cVal;
+ }
+
+ public virtual int WaitForValue(Object key, int expected, bool noack)
+ {
+ int val = -1;
+ Object cVal = null;
+
+ if (noack)
+ {
+ for (int tries = 0; tries < 100; tries++)
+ {
+ cVal = m_region[key];
+ Assert.IsNotNull(cVal, "value should not be null.");
+ Util.Log("WaitForValue: Received value: {0}", cVal);
+ val = int.Parse(cVal.ToString());
+ if (val == expected)
+ {
+ break;
+ }
+ Thread.Sleep(100);
+ }
+ }
+ else
+ {
+ cVal = m_region[key];
+ Assert.IsNotNull(cVal, "value should not be null.");
+ val = int.Parse(cVal.ToString());
+ }
+ return val;
+ }
+
+ // by convention, we'll accept value of -1 to mean not exists, 0 to mean invalid, and otherwise we'll compare.
+ public virtual void Test(int key, int value)
+ {
+ Test(key, value, m_noack);
+ }
+
+ public virtual void Test(int key, int value, bool noack)
+ {
+ string cKey = "key" + key.ToString();
+ StackFrame sf = new StackFrame(1, true);
+ int line = sf.GetFileLineNumber();
+ string method = sf.GetMethod().Name;
+ if (value == -1)
+ {
+ Assert.IsFalse(m_region.GetLocalView().ContainsKey(cKey),
+ "unexpected key found at line {0} in method {1}.", line, method);
+ if (noack)
+ { // need to wait a bit and retest...
+ Thread.Sleep(1000);
+ Assert.IsFalse(m_region.GetLocalView().ContainsKey(cKey),
+ "unexpected key found at line {0} in method {1}.", line, method);
+ }
+ }
+ else if (value == 0)
+ {
+ if (noack)
+ {
+ WaitForKey(cKey);
+ }
+ Assert.IsTrue(m_region.GetLocalView().ContainsKey(cKey),
+ "missing key at line {0} in method {1}.", line, method);
+ Assert.IsFalse(m_region.ContainsValueForKey(cKey),
+ "should have found invalid at line {0} in method {1}.", line, method);
+ }
+ else
+ {
+ if (noack)
+ {
+ WaitForKey(cKey);
+ }
+ Assert.IsTrue(m_region.GetLocalView().ContainsKey(cKey),
+ "missing key at line {0} in method {1}.", line, method);
+ int val = WaitForValue(cKey, value, noack);
+ Assert.AreEqual(value, val,
+ "unexpected value: \"{0}\", expected \"{1}\" from line {2} in method {3}",
+ val, value, line, method);
+
+ }
+ }
+
+ // by convention, we'll accept value of -1 to mean not exists, otherwise we'll compare.
+ public virtual void NetSearch(int key, int value)
+ {
+ string cKey = "key" + key.ToString();
+ Assert.IsFalse(m_region.ContainsKey(cKey), "shouldn't have key before NetSearch.");
+ int cVal = (int)m_region[cKey];
+ if (value == -1)
+ {
+ Assert.IsNull(cVal, "unexpected value found.");
+ }
+ else
+ {
+ Assert.IsNotNull(cVal, "missing value for key[{0}].", cKey);
+ Util.Log("got value='{0}' for key[{1}]", cVal, cKey);
+ Assert.AreEqual(value, cVal);
+ Assert.IsTrue(m_region.ContainsValueForKey(cKey),
+ "should now be in the local cache.");
+ }
+ }
+
+ public void ShowKeys()
+ {
+ ICollection<Object> keys = m_region.Keys;
+ int len = keys.Count;
+ Util.Log("Total keys in IRegion<object, object> {0} : {1}", m_region.Name, len);
+ CacheHelper.ShowKeys(keys);
+ }
+
+ public void ShowValues()
+ {
+ ICollection<Object> values = m_region.Values;
+ int len = values.Count;
+ Util.Log("Total values in IRegion<object, object> {0} : {1}", m_region.Name, len);
+ CacheHelper.ShowValues(values);
+ }
+
+ public void ShowKeysValues()
+ {
+ //Object value;
+ ICollection<Object> keys = m_region.Keys;
+ int len = keys.Count;
+ Util.Log("Total keys in IRegion<object, object> {0} : {1}", m_region.Name, len);
+ for (int i = 0; i < len; i++)
+ {
+ //TODO UNCOMMENT ONCE WE ATTACH THE LIST TO THE COLLECTION
+ //value = m_region[keys[i]];
+ //Util.Log("Key[{0}] = {1}, Value[{2}] = {3}", i, keys[i], i, value);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/SecurityTestUtilN.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/SecurityTestUtilN.cs b/clicache/integration-test/SecurityTestUtilN.cs
new file mode 100644
index 0000000..aced33d
--- /dev/null
+++ b/clicache/integration-test/SecurityTestUtilN.cs
@@ -0,0 +1,267 @@
+/*
+ * 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.Collections.Generic;
+
+#pragma warning disable 618
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.Client.Tests;
+ using Apache.Geode.DUnitFramework;
+ using Apache.Geode.Client;
+ using AssertionException = Apache.Geode.Client.AssertionException;
+
+ /// <summary>
+ /// Enumeration to indicate the result expected of an operation.
+ /// </summary>
+ public enum ExpectedResult
+ {
+ Success,
+ AuthRequiredException,
+ AuthFailedException,
+ NotAuthorizedException,
+ OtherException
+ }
+
+ /// <summary>
+ /// Helper class to start/stop cache servers and other utility methods
+ /// for security tests.
+ /// </summary>
+ public class SecurityTestUtil
+ {
+ public static List<CredentialGenerator> getAllGenerators(bool isMultiUser)
+ {
+ string dataDir = Util.GetEnvironmentVariable("CPP_TESTOUT");
+ List<CredentialGenerator> generators = new List<CredentialGenerator>();
+ foreach (CredentialGenerator.ClassCode code in Enum.GetValues(
+ typeof(CredentialGenerator.ClassCode)))
+ {
+ CredentialGenerator gen = CredentialGenerator.Create(code, isMultiUser);
+ if (gen != null)
+ {
+ gen.Init(dataDir, dataDir);
+ generators.Add(gen);
+ }
+ }
+ return generators;
+ }
+
+ public static string GetServerArgs(string authenticator,
+ Properties<string, string> extraProps, Properties<string, string> javaProps)
+ {
+ return Utility.GetServerArgs(authenticator, null, null,
+ extraProps, javaProps);
+ }
+
+ public static string GetServerArgs(string authenticator, string accessor,
+ string accessorPP, Properties<string, string> extraProps, Properties<string, string> javaProps)
+ {
+ return Utility.GetServerArgs(authenticator, accessor, accessorPP,
+ extraProps, javaProps);
+ }
+
+ public static Properties<string, string> ConcatProperties(params Properties<string, string>[] propsArray)
+ {
+ Properties<string, string> result = null;
+ if (propsArray != null)
+ {
+ result = new Properties<string, string>();
+ foreach (Properties<string, string> props in propsArray)
+ {
+ result.AddAll(props);
+ }
+ }
+ return result;
+ }
+
+ public static void CreateClientMU(string regionName, string locators,
+ string authInit, Properties<string, string> credentials, bool isMultiuser)
+ {
+ CreateClient(regionName, locators, authInit, credentials,
+ ExpectedResult.Success, isMultiuser, null);
+ }
+ //for notification
+ public static void CreateClientMU2(string regionName, string locators,
+ string authInit, Properties<string, string> credentials, bool isMultiuser, bool notificationEnabled)
+ {
+ CreateClient<object, object>(regionName, locators,
+ authInit, credentials, false,
+ notificationEnabled, 0, -1,
+ null, ExpectedResult.Success, isMultiuser, null, false, false);
+ }
+ //for durable client...
+ public static void CreateMUDurableClient(string regionName, string locators,
+ string authInit, string durableClientId, bool isMultiuser, bool notificationEnabled)
+ {
+ CreateClient<object, object>(regionName, locators,
+ authInit, null, false,
+ notificationEnabled, 0, -1,
+ null, ExpectedResult.Success, isMultiuser, durableClientId, false, false);
+ }
+
+ public static void CreateClient(string regionName, string locators,
+ string authInit, Properties<string, string> credentials)
+ {
+ CreateClient(regionName, locators, authInit, credentials,
+ ExpectedResult.Success);
+ }
+
+ public static void CreateClientSSL(string regionName, string locators,
+ string authInit, Properties<string, string> credentials, bool ssl, bool withPassword)
+ {
+ CreateClient<object, object>(regionName, locators, authInit, credentials,
+ true, true, 1, -1, null, ExpectedResult.Success, false, null, ssl, withPassword);
+ }
+
+ public static void CreateClientR0(string regionName, string locators,
+ string authInit, Properties<string, string> credentials)
+ {
+ CreateClient(regionName, locators, authInit, credentials,
+ ExpectedResult.Success, 0);
+ }
+
+ public static void CreateClient(string regionName, string locators,
+ string authInit, Properties<string, string> credentials, ExpectedResult expect, int redundancy)
+ {
+ CreateClient<object, object>(regionName, locators, authInit, credentials, true, true,
+ redundancy, -1, null, expect);
+ }
+
+ public static void CreateClient(string regionName, string locators,
+ string authInit, Properties<string, string> credentials, ExpectedResult expect,
+ bool isMultiuser, string durebleClientId)
+ {
+ CreateClient<object, object>(regionName, locators, authInit, credentials, false, false,
+ 0, -1, null, expect, isMultiuser, durebleClientId, false, false);
+ }
+
+ public static void CreateClient(string regionName, string locators,
+ string authInit, Properties<string, string> credentials, ExpectedResult expect)
+ {
+ CreateClient<object, object>(regionName, locators, authInit, credentials, true, true,
+ 1, -1, null, expect);
+ }
+
+ public static void CreateClient(string regionName, string locators,
+ string authInit, Properties<string, string> credentials, int numConnections,
+ ExpectedResult expect)
+ {
+ CreateClient<object, object>(regionName, locators, authInit, credentials, true, true,
+ 1, numConnections, null, expect);
+ }
+
+ public static void CreateClient<TKey, TValue>(string regionName, string locators,
+ string authInit, Properties<string, string> credentials, bool caching,
+ bool clientNotification, int redundancyLevel, int numConnections,
+ ICacheListener<TKey, TValue> listener, ExpectedResult expect)
+ {
+ CreateClient<TKey, TValue>(regionName, locators, authInit, credentials, true, true,
+ redundancyLevel, numConnections, null, expect, false, null, false, false);
+ }
+
+ public static void CreateClient<TKey, TValue>(string regionName, string locators,
+ string authInit, Properties<string, string> credentials, bool caching,
+ bool clientNotification, int redundancyLevel, int numConnections,
+ ICacheListener<TKey, TValue> listener, ExpectedResult expect, bool isMultiUser, string durableClientId, bool ssl, bool withPassword)
+ {
+ Util.Log("Redundancy Level = {0}", redundancyLevel);
+ CacheHelper.Close();
+ Properties<string, string> sysProps = new Properties<string, string>();
+ if (durableClientId != null)
+ sysProps.Insert("durable-client-id", durableClientId);
+ Utility.GetClientProperties(authInit, credentials, ref sysProps);
+ if (numConnections >= 0)
+ {
+ sysProps.Insert("connection-pool-size", numConnections.ToString());
+ }
+
+ if (ssl && withPassword)
+ {
+ string keystore = Util.GetEnvironmentVariable("CPP_TESTOUT") + "/keystore";
+ sysProps.Insert("ssl-enabled", "true");
+ sysProps.Insert("ssl-keystore", keystore + "/client_keystore.password.pem");
+ sysProps.Insert("ssl-truststore", keystore + "/client_truststore.pem");
+ sysProps.Insert("ssl-keystore-password", "gemstone");
+ }
+ else if (ssl)
+ {
+ string keystore = Util.GetEnvironmentVariable("CPP_TESTOUT") + "/keystore";
+ sysProps.Insert("ssl-enabled", "true");
+ sysProps.Insert("ssl-keystore", keystore + "/client_keystore.pem");
+ sysProps.Insert("ssl-truststore", keystore + "/client_truststore.pem");
+ }
+ try
+ {
+ CacheHelper.InitConfig(sysProps);
+
+ CacheHelper.CreatePool<TKey, TValue>("__TESTPOOL1_", locators, (string)null,
+ redundancyLevel, clientNotification, numConnections, isMultiUser);
+ CacheHelper.CreateTCRegion_Pool<TKey, TValue>(regionName, true, caching,
+ listener, locators, "__TESTPOOL1_", clientNotification);
+
+ if (expect != ExpectedResult.Success)
+ {
+ Assert.Fail(
+ "CreateClient: expected an exception in creating region.");
+ }
+ }
+ catch (AssertionException)
+ {
+ throw;
+ }
+ catch (AuthenticationRequiredException ex)
+ {
+ if (expect == ExpectedResult.AuthRequiredException)
+ {
+ Util.Log("CreateClient: got expected exception in creating region: "
+ + ex.Message);
+ }
+ else
+ {
+ throw;
+ }
+ }
+ catch (AuthenticationFailedException ex)
+ {
+ if (expect == ExpectedResult.AuthFailedException)
+ {
+ Util.Log("CreateClient: got expected exception in creating region: "
+ + ex.Message);
+ }
+ else
+ {
+ throw;
+ }
+ }
+ catch (Exception ex)
+ {
+ if (expect == ExpectedResult.OtherException)
+ {
+ Util.Log("CreateClient: got expected exception in creating region: "
+ + ex.GetType() + "::" + ex.Message);
+ }
+ else
+ {
+ throw;
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/SerializationTestsN.cs
----------------------------------------------------------------------
diff --git a/clicache/integration-test/SerializationTestsN.cs b/clicache/integration-test/SerializationTestsN.cs
new file mode 100644
index 0000000..9fb63f6
--- /dev/null
+++ b/clicache/integration-test/SerializationTestsN.cs
@@ -0,0 +1,1280 @@
+/*
+ * 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.Diagnostics;
+using System.IO;
+using System.Threading;
+
+namespace Apache.Geode.Client.UnitTests
+{
+ using NUnit.Framework;
+ using Apache.Geode.DUnitFramework;
+ using Apache.Geode.Client;
+
+
+ [TestFixture]
+ [Category("generics")]
+ public class SerializationTests : ThinClientRegionSteps
+ {
+ private const int OTHER_TYPE1 = 1;
+ private const int OTHER_TYPE2 = 2;
+ private const int OTHER_TYPE22 = 3;
+ private const int OTHER_TYPE4 = 4;
+ private const int OTHER_TYPE42 = 5;
+ private const int OTHER_TYPE43 = 6;
+
+ private UnitProcess sender, receiver;
+
+ protected override ClientBase[] GetClients()
+ {
+ sender = new UnitProcess();
+ receiver = new UnitProcess();
+ return new ClientBase[] { sender, receiver };
+ }
+
+ [TestFixtureTearDown]
+ public override void EndTests()
+ {
+ CacheHelper.StopJavaServers();
+ base.EndTests();
+ }
+
+ [TearDown]
+ public override void EndTest()
+ {
+ try
+ {
+ sender.Call(DestroyRegions);
+ receiver.Call(DestroyRegions);
+ CacheHelper.ClearEndpoints();
+ }
+ finally
+ {
+ CacheHelper.StopJavaServers();
+ }
+ base.EndTest();
+ }
+
+ private IGeodeSerializable CreateOtherType(int i, int otherType)
+ {
+ IGeodeSerializable ot;
+ switch (otherType)
+ {
+ case OTHER_TYPE1: ot = new OtherType(i, i + 20000); break;
+ case OTHER_TYPE2: ot = new OtherType2(i, i + 20000); break;
+ case OTHER_TYPE22: ot = new OtherType22(i, i + 20000); break;
+ case OTHER_TYPE4: ot = new OtherType4(i, i + 20000); break;
+ case OTHER_TYPE42: ot = new OtherType42(i, i + 20000); break;
+ case OTHER_TYPE43: ot = new OtherType43(i, i + 20000); break;
+ default: ot = new OtherType(i, i + 20000); break;
+ }
+ return ot;
+ }
+
+ #region Functions that are invoked by the tests
+
+ public void CreateRegionForOT(string locators)
+ {
+ CacheHelper.CreateTCRegion2<object, object>(RegionNames[0], true, false,
+ null, locators, false);
+ Serializable.RegisterTypeGeneric(OtherType.CreateDeserializable, CacheHelper.DCache);
+ Serializable.RegisterTypeGeneric(OtherType2.CreateDeserializable, CacheHelper.DCache);
+ Serializable.RegisterTypeGeneric(OtherType22.CreateDeserializable, CacheHelper.DCache);
+ Serializable.RegisterTypeGeneric(OtherType4.CreateDeserializable, CacheHelper.DCache);
+ Serializable.RegisterTypeGeneric(OtherType42.CreateDeserializable, CacheHelper.DCache);
+ Serializable.RegisterTypeGeneric(OtherType43.CreateDeserializable, CacheHelper.DCache);
+ }
+
+ public void DoNPuts(int n)
+ {
+ try
+ {
+ Serializable.RegisterTypeGeneric(OtherType.CreateDeserializable, CacheHelper.DCache);
+ Assert.Fail("Expected exception in registering the type again.");
+ }
+ catch (IllegalStateException ex)
+ {
+ Util.Log("Got expected exception in RegisterType: {0}", ex);
+ }
+ IRegion<object, object> region = CacheHelper.GetVerifyRegion<object, object>(RegionNames[0]);
+ for (int i = 0; i < n; i++)
+ {
+ //CacheableInt32 key = new CacheableInt32(i);
+ //region.Put(key, key);
+
+ int key = i;
+ region[key] = key;
+ }
+ }
+
+ public void DoValidates(int n)
+ {
+ try
+ {
+ Serializable.RegisterTypeGeneric(OtherType.CreateDeserializable, CacheHelper.DCache);
+ Assert.Fail("Expected exception in registering the type again.");
+ }
+ catch (IllegalStateException ex)
+ {
+ Util.Log("Got expected exception in RegisterType: {0}", ex);
+ }
+ IRegion<object, object> region = CacheHelper.GetVerifyRegion<object, object>(RegionNames[0]);
+ for (int i = 0; i < n; i++)
+ {
+ //CacheableInt32 val = region.Get(i) as CacheableInt32;
+ object val = region[i];
+ Assert.AreEqual(i, val, "Found unexpected value");
+ }
+ }
+
+ public void DoNPutsOtherType(int n, int otherType)
+ {
+ IRegion<object, object> region = CacheHelper.GetVerifyRegion<object, object>(RegionNames[0]);
+ for (int i = 0; i < n; i++)
+ {
+ IGeodeSerializable ot = CreateOtherType(i, otherType);
+ region[i + 10] = ot;
+ }
+ }
+
+ public void DoValidateNPutsOtherType(int n, int otherType)
+ {
+ IRegion<object, object> region = CacheHelper.GetVerifyRegion<object, object>(RegionNames[0]);
+ for (int i = 0; i < n; i++)
+ {
+ object val = region[i + 10];
+ IGeodeSerializable ot = CreateOtherType(i, otherType);
+ Assert.IsTrue(ot.Equals(val), "Found unexpected value");
+ }
+ }
+
+ #endregion
+
+ #region Tests
+
+ [Test]
+ public void CustomTypes()
+ {
+ CacheHelper.SetupJavaServers(true, "cacheserver.xml");
+ CacheHelper.StartJavaLocator(1, "GFELOC");
+ Util.Log("Locator 1 started.");
+ CacheHelper.StartJavaServerWithLocators(1, "GFECS1", 1);
+ Util.Log("Cacheserver 1 started.");
+
+ sender.Call(CreateRegionForOT, CacheHelper.Locators);
+ Util.Log("StepOne complete.");
+
+ receiver.Call(CreateRegionForOT, CacheHelper.Locators);
+ Util.Log("StepTwo complete.");
+
+ sender.Call(DoNPuts, 10);
+ receiver.Call(DoValidates, 10);
+ Util.Log("StepThree complete.");
+
+ sender.Call(DoNPutsOtherType, 10, OTHER_TYPE1);
+ receiver.Call(DoValidateNPutsOtherType, 10, OTHER_TYPE1);
+ Util.Log("StepFour complete.");
+
+ sender.Call(DoNPutsOtherType, 10, OTHER_TYPE2);
+ receiver.Call(DoValidateNPutsOtherType, 10, OTHER_TYPE2);
+ Util.Log("StepFive complete.");
+
+ sender.Call(DoNPutsOtherType, 10, OTHER_TYPE22);
+ receiver.Call(DoValidateNPutsOtherType, 10, OTHER_TYPE22);
+ Util.Log("StepSix complete.");
+
+ sender.Call(DoNPutsOtherType, 10, OTHER_TYPE4);
+ receiver.Call(DoValidateNPutsOtherType, 10, OTHER_TYPE4);
+ Util.Log("StepSeven complete.");
+
+ sender.Call(DoNPutsOtherType, 10, OTHER_TYPE42);
+ receiver.Call(DoValidateNPutsOtherType, 10, OTHER_TYPE42);
+ Util.Log("StepEight complete.");
+
+ sender.Call(DoNPutsOtherType, 10, OTHER_TYPE43);
+ receiver.Call(DoValidateNPutsOtherType, 10, OTHER_TYPE43);
+ Util.Log("StepNine complete.");
+
+ CacheHelper.StopJavaServer(1);
+ Util.Log("Cacheserver 1 stopped.");
+
+ CacheHelper.StopJavaLocator(1);
+ }
+
+ #endregion
+ }
+
+ [Serializable]
+ public struct CData
+ {
+ #region Private members
+
+ private Int32 m_first;
+ private Int64 m_second;
+
+ #endregion
+
+ #region Public accessors
+
+ public Int32 First
+ {
+ get
+ {
+ return m_first;
+ }
+ set
+ {
+ m_first = value;
+ }
+ }
+
+ public Int64 Second
+ {
+ get
+ {
+ return m_second;
+ }
+ set
+ {
+ m_second = value;
+ }
+ }
+
+ #endregion
+
+ public CData(Int32 first, Int64 second)
+ {
+ m_first = first;
+ m_second = second;
+ }
+
+ public static bool operator ==(CData obj1, CData obj2)
+ {
+ return ((obj1.m_first == obj2.m_first) && (obj1.m_second == obj2.m_second));
+ }
+
+ public static bool operator !=(CData obj1, CData obj2)
+ {
+ return ((obj1.m_first != obj2.m_first) || (obj1.m_second != obj2.m_second));
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (obj is CData)
+ {
+ CData otherObj = (CData)obj;
+ return ((m_first == otherObj.m_first) && (m_second == otherObj.m_second));
+ }
+ return false;
+ }
+
+ public override int GetHashCode()
+ {
+ return m_first.GetHashCode() ^ m_second.GetHashCode();
+ }
+ };
+
+ public class PdxCData : IPdxSerializable
+ {
+ #region Private members
+
+ private Int32 m_first;
+ private Int64 m_second;
+
+ #endregion
+
+ #region Public accessors
+
+ public Int32 First
+ {
+ get
+ {
+ return m_first;
+ }
+ set
+ {
+ m_first = value;
+ }
+ }
+
+ public Int64 Second
+ {
+ get
+ {
+ return m_second;
+ }
+ set
+ {
+ m_second = value;
+ }
+ }
+
+ #endregion
+
+ public PdxCData(Int32 first, Int64 second)
+ {
+ m_first = first;
+ m_second = second;
+ }
+
+ public PdxCData() { }
+
+ public static PdxCData CreateDeserializable()
+ {
+ return new PdxCData();
+ }
+ public static bool operator ==(PdxCData obj1, PdxCData obj2)
+ {
+ return ((obj1.m_first == obj2.m_first) && (obj1.m_second == obj2.m_second));
+ }
+
+ public static bool operator !=(PdxCData obj1, PdxCData obj2)
+ {
+ return ((obj1.m_first != obj2.m_first) || (obj1.m_second != obj2.m_second));
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (obj is PdxCData)
+ {
+ PdxCData otherObj = (PdxCData)obj;
+ return ((m_first == otherObj.m_first) && (m_second == otherObj.m_second));
+ }
+ return false;
+ }
+
+ public override int GetHashCode()
+ {
+ return m_first.GetHashCode();
+ }
+
+ #region IPdxSerializable Members
+
+ public void FromData(IPdxReader reader)
+ {
+ m_first = reader.ReadInt("m_first");
+ m_second = reader.ReadLong("m_second");
+ }
+
+ public void ToData(IPdxWriter writer)
+ {
+ writer.WriteInt("m_first", m_first);
+ writer.MarkIdentityField("m_first");
+ writer.WriteLong("m_second", m_second);
+ }
+
+ #endregion
+
+
+
+
+ };
+
+ public class OtherType : IGeodeSerializable
+ {
+ private CData m_struct;
+ private ExceptionType m_exType;
+
+ public enum ExceptionType
+ {
+ None,
+ Geode,
+ System,
+ // below are with inner exceptions
+ GeodeGeode,
+ GeodeSystem,
+ SystemGeode,
+ SystemSystem
+ }
+
+ public OtherType()
+ {
+ m_exType = ExceptionType.None;
+ }
+
+ public OtherType(Int32 first, Int64 second)
+ : this(first, second, ExceptionType.None)
+ {
+ }
+
+ public OtherType(Int32 first, Int64 second, ExceptionType exType)
+ {
+ m_struct.First = first;
+ m_struct.Second = second;
+ m_exType = exType;
+ }
+
+ public CData Data
+ {
+ get
+ {
+ return m_struct;
+ }
+ }
+
+ public static IGeodeSerializable Duplicate(IGeodeSerializable orig)
+ {
+ DataOutput dout = CacheHelper.DCache.CreateDataOutput();
+ orig.ToData(dout);
+
+ //DataInput din = new DataInput(dout.GetBuffer());
+ DataInput din = CacheHelper.DCache.CreateDataInput(dout.GetBuffer());
+ IGeodeSerializable dup = (IGeodeSerializable)din.ReadObject();
+ return dup;
+ }
+
+ #region IGeodeSerializable Members
+
+ public IGeodeSerializable FromData(DataInput input)
+ {
+ m_struct.First = input.ReadInt32();
+ m_struct.Second = input.ReadInt64();
+ switch (m_exType)
+ {
+ case ExceptionType.None:
+ break;
+ case ExceptionType.Geode:
+ throw new GeodeIOException("Throwing an exception");
+ case ExceptionType.System:
+ throw new IOException("Throwing an exception");
+ case ExceptionType.GeodeGeode:
+ throw new GeodeIOException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.GeodeSystem:
+ throw new CacheServerException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ case ExceptionType.SystemGeode:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.SystemSystem:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ }
+ return this;
+ }
+
+ public void ToData(DataOutput output)
+ {
+ output.WriteInt32(m_struct.First);
+ output.WriteInt64(m_struct.Second);
+ switch (m_exType)
+ {
+ case ExceptionType.None:
+ break;
+ case ExceptionType.Geode:
+ throw new GeodeIOException("Throwing an exception");
+ case ExceptionType.System:
+ throw new IOException("Throwing an exception");
+ case ExceptionType.GeodeGeode:
+ throw new GeodeIOException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.GeodeSystem:
+ throw new CacheServerException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ case ExceptionType.SystemGeode:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.SystemSystem:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ }
+ }
+
+ public UInt32 ObjectSize
+ {
+ get
+ {
+ return (UInt32)(sizeof(Int32) + sizeof(Int64));
+ }
+ }
+
+ public UInt32 ClassId
+ {
+ get
+ {
+ return 0x0;
+ }
+ }
+
+ #endregion
+
+ public static IGeodeSerializable CreateDeserializable()
+ {
+ return new OtherType();
+ }
+
+ public override int GetHashCode()
+ {
+ return m_struct.First.GetHashCode() ^ m_struct.Second.GetHashCode();
+ }
+
+ public override bool Equals(object obj)
+ {
+ OtherType ot = obj as OtherType;
+ if (ot != null)
+ {
+ return (m_struct.Equals(ot.m_struct));
+ }
+ return false;
+ }
+ }
+
+ public class OtherType2 : IGeodeSerializable
+ {
+ private CData m_struct;
+ private ExceptionType m_exType;
+
+ public enum ExceptionType
+ {
+ None,
+ Geode,
+ System,
+ // below are with inner exceptions
+ GeodeGeode,
+ GeodeSystem,
+ SystemGeode,
+ SystemSystem
+ }
+
+ public OtherType2()
+ {
+ m_exType = ExceptionType.None;
+ }
+
+ public OtherType2(Int32 first, Int64 second)
+ : this(first, second, ExceptionType.None)
+ {
+ }
+
+ public OtherType2(Int32 first, Int64 second, ExceptionType exType)
+ {
+ m_struct.First = first;
+ m_struct.Second = second;
+ m_exType = exType;
+ }
+
+ public CData Data
+ {
+ get
+ {
+ return m_struct;
+ }
+ }
+
+ public static IGeodeSerializable Duplicate(IGeodeSerializable orig)
+ {
+ DataOutput dout = CacheHelper.DCache.CreateDataOutput();
+ orig.ToData(dout);
+
+ DataInput din = CacheHelper.DCache.CreateDataInput(dout.GetBuffer());
+ IGeodeSerializable dup = (IGeodeSerializable)din.ReadObject();
+ return dup;
+ }
+
+ #region IGeodeSerializable Members
+
+ public IGeodeSerializable FromData(DataInput input)
+ {
+ m_struct.First = input.ReadInt32();
+ m_struct.Second = input.ReadInt64();
+ switch (m_exType)
+ {
+ case ExceptionType.None:
+ break;
+ case ExceptionType.Geode:
+ throw new GeodeIOException("Throwing an exception");
+ case ExceptionType.System:
+ throw new IOException("Throwing an exception");
+ case ExceptionType.GeodeGeode:
+ throw new GeodeIOException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.GeodeSystem:
+ throw new CacheServerException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ case ExceptionType.SystemGeode:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.SystemSystem:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ }
+ return this;
+ }
+
+ public void ToData(DataOutput output)
+ {
+ output.WriteInt32(m_struct.First);
+ output.WriteInt64(m_struct.Second);
+ switch (m_exType)
+ {
+ case ExceptionType.None:
+ break;
+ case ExceptionType.Geode:
+ throw new GeodeIOException("Throwing an exception");
+ case ExceptionType.System:
+ throw new IOException("Throwing an exception");
+ case ExceptionType.GeodeGeode:
+ throw new GeodeIOException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.GeodeSystem:
+ throw new CacheServerException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ case ExceptionType.SystemGeode:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.SystemSystem:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ }
+ }
+
+ public UInt32 ObjectSize
+ {
+ get
+ {
+ return (UInt32)(sizeof(Int32) + sizeof(Int64));
+ }
+ }
+
+ public UInt32 ClassId
+ {
+ get
+ {
+ return 0x8C;
+ }
+ }
+
+ #endregion
+
+ public static IGeodeSerializable CreateDeserializable()
+ {
+ return new OtherType2();
+ }
+
+ public override int GetHashCode()
+ {
+ return m_struct.First.GetHashCode() ^ m_struct.Second.GetHashCode();
+ }
+
+ public override bool Equals(object obj)
+ {
+ OtherType2 ot = obj as OtherType2;
+ if (ot != null)
+ {
+ return (m_struct.Equals(ot.m_struct));
+ }
+ return false;
+ }
+
+ }
+
+ public class OtherType22 : IGeodeSerializable
+ {
+ private CData m_struct;
+ private ExceptionType m_exType;
+
+ public enum ExceptionType
+ {
+ None,
+ Geode,
+ System,
+ // below are with inner exceptions
+ GeodeGeode,
+ GeodeSystem,
+ SystemGeode,
+ SystemSystem
+ }
+
+ public OtherType22()
+ {
+ m_exType = ExceptionType.None;
+ }
+
+ public OtherType22(Int32 first, Int64 second)
+ : this(first, second, ExceptionType.None)
+ {
+ }
+
+ public OtherType22(Int32 first, Int64 second, ExceptionType exType)
+ {
+ m_struct.First = first;
+ m_struct.Second = second;
+ m_exType = exType;
+ }
+
+ public CData Data
+ {
+ get
+ {
+ return m_struct;
+ }
+ }
+
+ public static IGeodeSerializable Duplicate(IGeodeSerializable orig)
+ {
+ DataOutput dout = CacheHelper.DCache.CreateDataOutput();
+ orig.ToData(dout);
+
+ DataInput din = CacheHelper.DCache.CreateDataInput(dout.GetBuffer());
+ IGeodeSerializable dup = (IGeodeSerializable)din.ReadObject();
+ return dup;
+ }
+
+ #region IGeodeSerializable Members
+
+ public IGeodeSerializable FromData(DataInput input)
+ {
+ m_struct.First = input.ReadInt32();
+ m_struct.Second = input.ReadInt64();
+ switch (m_exType)
+ {
+ case ExceptionType.None:
+ break;
+ case ExceptionType.Geode:
+ throw new GeodeIOException("Throwing an exception");
+ case ExceptionType.System:
+ throw new IOException("Throwing an exception");
+ case ExceptionType.GeodeGeode:
+ throw new GeodeIOException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.GeodeSystem:
+ throw new CacheServerException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ case ExceptionType.SystemGeode:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.SystemSystem:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ }
+ return this;
+ }
+
+ public void ToData(DataOutput output)
+ {
+ output.WriteInt32(m_struct.First);
+ output.WriteInt64(m_struct.Second);
+ switch (m_exType)
+ {
+ case ExceptionType.None:
+ break;
+ case ExceptionType.Geode:
+ throw new GeodeIOException("Throwing an exception");
+ case ExceptionType.System:
+ throw new IOException("Throwing an exception");
+ case ExceptionType.GeodeGeode:
+ throw new GeodeIOException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.GeodeSystem:
+ throw new CacheServerException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ case ExceptionType.SystemGeode:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.SystemSystem:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ }
+ }
+
+ public UInt32 ObjectSize
+ {
+ get
+ {
+ return (UInt32)(sizeof(Int32) + sizeof(Int64));
+ }
+ }
+
+ public UInt32 ClassId
+ {
+ get
+ {
+ return 0x8C0;
+ }
+ }
+
+ #endregion
+
+ public static IGeodeSerializable CreateDeserializable()
+ {
+ return new OtherType22();
+ }
+
+ public override int GetHashCode()
+ {
+ return m_struct.First.GetHashCode() ^ m_struct.Second.GetHashCode();
+ }
+
+ public override bool Equals(object obj)
+ {
+ OtherType22 ot = obj as OtherType22;
+ if (ot != null)
+ {
+ return (m_struct.Equals(ot.m_struct));
+ }
+ return false;
+ }
+ }
+
+ public class OtherType4 : IGeodeSerializable
+ {
+ private CData m_struct;
+ private ExceptionType m_exType;
+
+ public enum ExceptionType
+ {
+ None,
+ Geode,
+ System,
+ // below are with inner exceptions
+ GeodeGeode,
+ GeodeSystem,
+ SystemGeode,
+ SystemSystem
+ }
+
+ public OtherType4()
+ {
+ m_exType = ExceptionType.None;
+ }
+
+ public OtherType4(Int32 first, Int64 second)
+ : this(first, second, ExceptionType.None)
+ {
+ }
+
+ public OtherType4(Int32 first, Int64 second, ExceptionType exType)
+ {
+ m_struct.First = first;
+ m_struct.Second = second;
+ m_exType = exType;
+ }
+
+ public CData Data
+ {
+ get
+ {
+ return m_struct;
+ }
+ }
+
+ public static IGeodeSerializable Duplicate(IGeodeSerializable orig)
+ {
+ DataOutput dout = CacheHelper.DCache.CreateDataOutput();
+ orig.ToData(dout);
+
+ DataInput din = CacheHelper.DCache.CreateDataInput(dout.GetBuffer());
+ IGeodeSerializable dup = (IGeodeSerializable)din.ReadObject();
+ return dup;
+ }
+
+ #region IGeodeSerializable Members
+
+ public IGeodeSerializable FromData(DataInput input)
+ {
+ m_struct.First = input.ReadInt32();
+ m_struct.Second = input.ReadInt64();
+ switch (m_exType)
+ {
+ case ExceptionType.None:
+ break;
+ case ExceptionType.Geode:
+ throw new GeodeIOException("Throwing an exception");
+ case ExceptionType.System:
+ throw new IOException("Throwing an exception");
+ case ExceptionType.GeodeGeode:
+ throw new GeodeIOException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.GeodeSystem:
+ throw new CacheServerException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ case ExceptionType.SystemGeode:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.SystemSystem:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ }
+ return this;
+ }
+
+ public void ToData(DataOutput output)
+ {
+ output.WriteInt32(m_struct.First);
+ output.WriteInt64(m_struct.Second);
+ switch (m_exType)
+ {
+ case ExceptionType.None:
+ break;
+ case ExceptionType.Geode:
+ throw new GeodeIOException("Throwing an exception");
+ case ExceptionType.System:
+ throw new IOException("Throwing an exception");
+ case ExceptionType.GeodeGeode:
+ throw new GeodeIOException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.GeodeSystem:
+ throw new CacheServerException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ case ExceptionType.SystemGeode:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.SystemSystem:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ }
+ }
+
+ public UInt32 ObjectSize
+ {
+ get
+ {
+ return (UInt32)(sizeof(Int32) + sizeof(Int64));
+ }
+ }
+
+ public UInt32 ClassId
+ {
+ get
+ {
+ return 0x8FC0;
+ }
+ }
+
+ #endregion
+
+ public static IGeodeSerializable CreateDeserializable()
+ {
+ return new OtherType4();
+ }
+
+ public override int GetHashCode()
+ {
+ return m_struct.First.GetHashCode() ^ m_struct.Second.GetHashCode();
+ }
+
+ public override bool Equals(object obj)
+ {
+ OtherType4 ot = obj as OtherType4;
+ if (ot != null)
+ {
+ return (m_struct.Equals(ot.m_struct));
+ }
+ return false;
+ }
+
+ }
+
+ public class OtherType42 : IGeodeSerializable
+ {
+ private CData m_struct;
+ private ExceptionType m_exType;
+
+ public enum ExceptionType
+ {
+ None,
+ Geode,
+ System,
+ // below are with inner exceptions
+ GeodeGeode,
+ GeodeSystem,
+ SystemGeode,
+ SystemSystem
+ }
+
+ public OtherType42()
+ {
+ m_exType = ExceptionType.None;
+ }
+
+ public OtherType42(Int32 first, Int64 second)
+ : this(first, second, ExceptionType.None)
+ {
+ }
+
+ public OtherType42(Int32 first, Int64 second, ExceptionType exType)
+ {
+ m_struct.First = first;
+ m_struct.Second = second;
+ m_exType = exType;
+ }
+
+ public CData Data
+ {
+ get
+ {
+ return m_struct;
+ }
+ }
+
+ public static IGeodeSerializable Duplicate(IGeodeSerializable orig)
+ {
+ DataOutput dout = CacheHelper.DCache.CreateDataOutput();
+ orig.ToData(dout);
+
+ DataInput din = CacheHelper.DCache.CreateDataInput(dout.GetBuffer());
+ IGeodeSerializable dup = (IGeodeSerializable)din.ReadObject();
+ return dup;
+ }
+
+ #region IGeodeSerializable Members
+
+ public IGeodeSerializable FromData(DataInput input)
+ {
+ m_struct.First = input.ReadInt32();
+ m_struct.Second = input.ReadInt64();
+ switch (m_exType)
+ {
+ case ExceptionType.None:
+ break;
+ case ExceptionType.Geode:
+ throw new GeodeIOException("Throwing an exception");
+ case ExceptionType.System:
+ throw new IOException("Throwing an exception");
+ case ExceptionType.GeodeGeode:
+ throw new GeodeIOException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.GeodeSystem:
+ throw new CacheServerException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ case ExceptionType.SystemGeode:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.SystemSystem:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ }
+ return this;
+ }
+
+ public void ToData(DataOutput output)
+ {
+ output.WriteInt32(m_struct.First);
+ output.WriteInt64(m_struct.Second);
+ switch (m_exType)
+ {
+ case ExceptionType.None:
+ break;
+ case ExceptionType.Geode:
+ throw new GeodeIOException("Throwing an exception");
+ case ExceptionType.System:
+ throw new IOException("Throwing an exception");
+ case ExceptionType.GeodeGeode:
+ throw new GeodeIOException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.GeodeSystem:
+ throw new CacheServerException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ case ExceptionType.SystemGeode:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.SystemSystem:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ }
+ }
+
+ public UInt32 ObjectSize
+ {
+ get
+ {
+ return (UInt32)(sizeof(Int32) + sizeof(Int64));
+ }
+ }
+
+ public UInt32 ClassId
+ {
+ get
+ {
+ return 0x6F3F97;
+ }
+ }
+
+ #endregion
+
+ public static IGeodeSerializable CreateDeserializable()
+ {
+ return new OtherType42();
+ }
+
+ public override int GetHashCode()
+ {
+ return m_struct.First.GetHashCode() ^ m_struct.Second.GetHashCode();
+ }
+
+ public override bool Equals(object obj)
+ {
+ OtherType42 ot = obj as OtherType42;
+ if (ot != null)
+ {
+ return (m_struct.Equals(ot.m_struct));
+ }
+ return false;
+ }
+
+ }
+
+ public class OtherType43 : IGeodeSerializable
+ {
+ private CData m_struct;
+ private ExceptionType m_exType;
+
+ public enum ExceptionType
+ {
+ None,
+ Geode,
+ System,
+ // below are with inner exceptions
+ GeodeGeode,
+ GeodeSystem,
+ SystemGeode,
+ SystemSystem
+ }
+
+ public OtherType43()
+ {
+ m_exType = ExceptionType.None;
+ }
+
+ public OtherType43(Int32 first, Int64 second)
+ : this(first, second, ExceptionType.None)
+ {
+ }
+
+ public OtherType43(Int32 first, Int64 second, ExceptionType exType)
+ {
+ m_struct.First = first;
+ m_struct.Second = second;
+ m_exType = exType;
+ }
+
+ public CData Data
+ {
+ get
+ {
+ return m_struct;
+ }
+ }
+
+ public static IGeodeSerializable Duplicate(IGeodeSerializable orig)
+ {
+ DataOutput dout = CacheHelper.DCache.CreateDataOutput();
+ orig.ToData(dout);
+
+ DataInput din = CacheHelper.DCache.CreateDataInput(dout.GetBuffer());
+ IGeodeSerializable dup = (IGeodeSerializable)din.ReadObject();
+ return dup;
+ }
+
+ #region IGeodeSerializable Members
+
+ public IGeodeSerializable FromData(DataInput input)
+ {
+ m_struct.First = input.ReadInt32();
+ m_struct.Second = input.ReadInt64();
+ switch (m_exType)
+ {
+ case ExceptionType.None:
+ break;
+ case ExceptionType.Geode:
+ throw new GeodeIOException("Throwing an exception");
+ case ExceptionType.System:
+ throw new IOException("Throwing an exception");
+ case ExceptionType.GeodeGeode:
+ throw new GeodeIOException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.GeodeSystem:
+ throw new CacheServerException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ case ExceptionType.SystemGeode:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.SystemSystem:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ }
+ return this;
+ }
+
+ public void ToData(DataOutput output)
+ {
+ output.WriteInt32(m_struct.First);
+ output.WriteInt64(m_struct.Second);
+ switch (m_exType)
+ {
+ case ExceptionType.None:
+ break;
+ case ExceptionType.Geode:
+ throw new GeodeIOException("Throwing an exception");
+ case ExceptionType.System:
+ throw new IOException("Throwing an exception");
+ case ExceptionType.GeodeGeode:
+ throw new GeodeIOException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.GeodeSystem:
+ throw new CacheServerException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ case ExceptionType.SystemGeode:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new CacheServerException("This is an inner exception"));
+ case ExceptionType.SystemSystem:
+ throw new ApplicationException("Throwing an exception with inner " +
+ "exception", new IOException("This is an inner exception"));
+ }
+ }
+
+ public UInt32 ObjectSize
+ {
+ get
+ {
+ return (UInt32)(sizeof(Int32) + sizeof(Int64));
+ }
+ }
+
+ public UInt32 ClassId
+ {
+ get
+ {
+ return 0x7FFFFFFF;
+ }
+ }
+
+ #endregion
+
+ public static IGeodeSerializable CreateDeserializable()
+ {
+ return new OtherType43();
+ }
+
+ public override int GetHashCode()
+ {
+ return m_struct.First.GetHashCode() ^ m_struct.Second.GetHashCode();
+ }
+
+ public override bool Equals(object obj)
+ {
+ OtherType43 ot = obj as OtherType43;
+ if (ot != null)
+ {
+ return (m_struct.Equals(ot.m_struct));
+ }
+ return false;
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6cbd424f/clicache/integration-test/Settings.xml
----------------------------------------------------------------------
diff --git a/clicache/integration-test/Settings.xml b/clicache/integration-test/Settings.xml
new file mode 100644
index 0000000..50cb7f5
--- /dev/null
+++ b/clicache/integration-test/Settings.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ 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.
+-->
+
+<Settings>
+ <DataIOTests>
+ <Byte>
+ <byte value="0x11" />
+ </Byte>
+ <Boolean>
+ <bool value="true" bytes="0x1" />
+ <bool value="false" bytes="0x0" />
+ </Boolean>
+ <Int16>
+ <short value="0x1122" bytes="0x11:0x22" />
+ </Int16>
+ <Int32>
+ <int value="0x11223344" bytes="0x11:0x22:0x33:0x44" />
+ </Int32>
+ <Int64>
+ <long value="0x1122334455667788" bytes="0x11:0x22:0x33:0x44:0x55:0x66:0x77:0x88" />
+ </Int64>
+ <Float>
+ <float value="1.2" bytes="0x3f:0x99:0x99:0x9a" />
+ </Float>
+ <Double>
+ <double value="1.2" bytes="0x3f:0xf3:0x33:0x33:0x33:0x33:0x33:0x33" />
+ </Double>
+ <ASCIIString>
+ <ascii value="This is fun." byte0="0x00" byte1="0x0c" />
+ </ASCIIString>
+ <UTFString>
+ <utf value="0x00:0x7f:0x80:0x81:0xffff" bytes="0x00:0x0a:0xc0:0x80:0x7f:0xc2:0x80:0xc2:0x81:0xef:0xbf:0xbf" />
+ </UTFString>
+ </DataIOTests>
+</Settings>