This is an automated email from the ASF dual-hosted git repository. echobravo pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode-native.git
The following commit(s) were added to refs/heads/develop by this push: new a1a7c13 GEODE-5768: New ContinuousQuery tests using DataSerializable objects (#376) a1a7c13 is described below commit a1a7c131e45b36dff99fb3be8097ed73f056ab92 Author: Michael Martell <mmart...@pivotal.io> AuthorDate: Wed Oct 10 13:32:16 2018 -0700 GEODE-5768: New ContinuousQuery tests using DataSerializable objects (#376) * Refactored CqListners to override OnEvent method for specific type * Added JMX port info to start/stop server scripting * Reverted original Position.java to fix cppcache tests * Created Position.java for cli tests * Turned off parallel test execution in cli/integration-test2 using xunit parallelizeAssembly=false. * Rename GemFireServerTest to GeodeServerTest * Removed debug statements from base class --- clicache/integration-test2/CMakeLists.txt | 4 +- clicache/integration-test2/CqOperationTest.cs | 180 +++++++++++++++---- clicache/integration-test2/GeodeServer.cs | 27 +-- clicache/integration-test2/GeodeServerTests.cs | 2 +- clicache/integration-test2/Position.cs | 239 +++++++++++++++++++++++++ clicache/integration-test2/server.xml | 26 +++ clicache/integration-test2/xunit.runner.json | 3 +- tests/javaobject/CMakeLists.txt | 1 + tests/javaobject/cli/Position.java | 217 ++++++++++++++++++++++ 9 files changed, 647 insertions(+), 52 deletions(-) diff --git a/clicache/integration-test2/CMakeLists.txt b/clicache/integration-test2/CMakeLists.txt index 990dd86..46a4891 100644 --- a/clicache/integration-test2/CMakeLists.txt +++ b/clicache/integration-test2/CMakeLists.txt @@ -36,7 +36,9 @@ add_library( ${PROJECT_NAME} SHARED CqOperationTest.cs RegionTest.cs RegionSSLTest.cs + Position.cs cache.xml + server.xml geode.properties xunit.runner.json packages.config @@ -47,7 +49,7 @@ add_library( ${PROJECT_NAME} SHARED ServerSslKeys/server_truststore.jks ) -set_source_files_properties(cache.xml xunit.runner.json geode.properties ClientSslKeys/client_keystore.password.pem ClientSslKeys/client_truststore.pem ServerSslKeys/server_keystore.jks ServerSslKeys/server_truststore.jks PROPERTIES +set_source_files_properties(cache.xml server.xml xunit.runner.json geode.properties ClientSslKeys/client_keystore.password.pem ClientSslKeys/client_truststore.pem ServerSslKeys/server_keystore.jks ServerSslKeys/server_truststore.jks PROPERTIES VS_COPY_TO_OUT_DIR Always VS_TOOL_OVERRIDE "None" ) diff --git a/clicache/integration-test2/CqOperationTest.cs b/clicache/integration-test2/CqOperationTest.cs index ad6bfa9..9a6f99e 100644 --- a/clicache/integration-test2/CqOperationTest.cs +++ b/clicache/integration-test2/CqOperationTest.cs @@ -64,7 +64,7 @@ namespace Apache.Geode.Client.IntegrationTests } } - public class MyCqListener<TKey, TResult> : ICqListener<TKey, TResult> + public class CqListener<TKey, TResult> : ICqListener<TKey, TResult> { public AutoResetEvent RegionClearEvent { get; private set; } public AutoResetEvent CreatedEvent { get; private set; } @@ -72,9 +72,9 @@ namespace Apache.Geode.Client.IntegrationTests public AutoResetEvent DestroyedNonNullEvent { get; private set; } public AutoResetEvent DestroyedNullEvent { get; private set; } public AutoResetEvent InvalidatedEvent { get; private set; } - public bool ReceivedUnknownEventType { get; private set; } + public bool ReceivedUnknownEventType { get; internal set; } - public MyCqListener() + public CqListener() { CreatedEvent = new AutoResetEvent(false); UpdatedEvent = new AutoResetEvent(false); @@ -87,8 +87,23 @@ namespace Apache.Geode.Client.IntegrationTests public virtual void OnEvent(CqEvent<TKey, TResult> ev) { - Debug.WriteLine("MyCqListener::OnEvent called"); - MyOrder val = ev.getNewValue() as MyOrder; + } + + public virtual void OnError(CqEvent<TKey, TResult> ev) + { + } + + public virtual void Close() + { + } + } + + public class PdxCqListener<TKey, TResult> : CqListener<TKey, TResult> + { + public override void OnEvent(CqEvent<TKey, TResult> ev) + { + Debug.WriteLine("CqListener::OnEvent called"); + var val = ev.getNewValue() as MyOrder; TKey key = ev.getKey(); switch (ev.getQueryOperation()) @@ -120,15 +135,44 @@ namespace Apache.Geode.Client.IntegrationTests break; } } + } - public virtual void OnError(CqEvent<TKey, TResult> ev) + public class DataCqListener<TKey, TResult> : CqListener<TKey, TResult> + { + public override void OnEvent(CqEvent<TKey, TResult> ev) { - Debug.WriteLine("MyCqListener::OnError called"); - } + Debug.WriteLine("CqListener::OnEvent called"); + var val = ev.getNewValue() as Position; + TKey key = ev.getKey(); - public virtual void Close() - { - Debug.WriteLine("MyCqListener::close called"); + switch (ev.getQueryOperation()) + { + case CqOperation.OP_TYPE_REGION_CLEAR: + RegionClearEvent.Set(); + break; + case CqOperation.OP_TYPE_CREATE: + CreatedEvent.Set(); + break; + case CqOperation.OP_TYPE_UPDATE: + UpdatedEvent.Set(); + break; + case CqOperation.OP_TYPE_INVALIDATE: + InvalidatedEvent.Set(); + break; + case CqOperation.OP_TYPE_DESTROY: + if (val == null) + { + DestroyedNullEvent.Set(); + } + else + { + DestroyedNonNullEvent.Set(); + } + break; + default: + ReceivedUnknownEventType = true; + break; + } } } @@ -138,42 +182,42 @@ namespace Apache.Geode.Client.IntegrationTests private readonly Cache _cache; private readonly GeodeServer _geodeServer; private static int _waitInterval = 1000; - + public CqOperationTest() { var cacheFactory = new CacheFactory() .Set("log-level", "error"); - + _cache = cacheFactory.Create(); _geodeServer = new GeodeServer(); - + } - + public void Dispose() { _cache.Close(); _geodeServer.Dispose(); } - + [Fact] - public void NotificationsHaveCorrectValues() + public void NotificationsHaveCorrectValuesPdxSerializable() { _cache.TypeRegistry.RegisterPdxType(MyOrder.CreateDeserializable); - + var poolFactory = _cache.GetPoolFactory() .AddLocator("localhost", _geodeServer.LocatorPort); var pool = poolFactory .SetSubscriptionEnabled(true) .Create("pool"); - + var regionFactory = _cache.CreateRegionFactory(RegionShortcut.PROXY) .SetPoolName("pool"); - + var region = regionFactory.Create<string, MyOrder>("cqTestRegion"); - + var queryService = pool.GetQueryService(); var cqAttributesFactory = new CqAttributesFactory<string, MyOrder>(); - var cqListener = new MyCqListener<string, MyOrder>(); + var cqListener = new PdxCqListener<string, MyOrder>(); cqAttributesFactory.AddCqListener(cqListener); var cqAttributes = cqAttributesFactory.Create(); @@ -181,36 +225,98 @@ namespace Apache.Geode.Client.IntegrationTests Debug.WriteLine("Executing continuous query"); query.Execute(); - Debug.WriteLine("Putting and changing Order objects in the region"); + Debug.WriteLine("Putting and changing Position objects in the region"); var order1 = new MyOrder(1, "product x", 23); var order2 = new MyOrder(2, "product y", 37); var order3 = new MyOrder(3, "product z", 101); - + region.Put("order1", order1); + region.Put("order2", order2); - Assert.True(cqListener.CreatedEvent.WaitOne(_waitInterval), "Didn't receieve expected CREATE event"); - + Assert.True(cqListener.CreatedEvent.WaitOne(_waitInterval), "Didn't receive expected CREATE event"); + order1.Quantity = 60; region.Put("order1", order1); - Assert.True(cqListener.CreatedEvent.WaitOne(_waitInterval), "Didn't receieve expected CREATE event"); - + Assert.True(cqListener.CreatedEvent.WaitOne(_waitInterval), "Didn't receive expected CREATE event"); + order2.Quantity = 45; region.Put("order2", order2); - Assert.True(cqListener.UpdatedEvent.WaitOne(_waitInterval), "Didn't receieve expected UPDATE event"); - + Assert.True(cqListener.UpdatedEvent.WaitOne(_waitInterval), "Didn't receive expected UPDATE event"); + order2.Quantity = 11; region.Put("order2", order2); - Assert.True(cqListener.DestroyedNonNullEvent.WaitOne(_waitInterval), "Didn't receieve expected DESTROY event"); - + Assert.True(cqListener.DestroyedNonNullEvent.WaitOne(_waitInterval), "Didn't receive expected DESTROY event"); + region.Remove("order1"); - Assert.True(cqListener.DestroyedNullEvent.WaitOne(_waitInterval), "Didn't receieve expected DESTROY event"); - + Assert.True(cqListener.DestroyedNullEvent.WaitOne(_waitInterval), "Didn't receive expected DESTROY event"); + region.Put("order3", order3); - Assert.True(cqListener.CreatedEvent.WaitOne(_waitInterval), "Didn't receieve expected CREATE event"); - + Assert.True(cqListener.CreatedEvent.WaitOne(_waitInterval), "Didn't receive expected CREATE event"); + region.Clear(); Assert.True(cqListener.RegionClearEvent.WaitOne(_waitInterval), "Didn't receive expected CLEAR event"); - + + Assert.False(cqListener.ReceivedUnknownEventType, "An unknown event was received by CQ listener"); + } + + [Fact] + public void NotificationsHaveCorrectValuesDataSerializable() + { + _cache.TypeRegistry.RegisterType(Position.CreateDeserializable, 22); + + var poolFactory = _cache.GetPoolFactory() + .AddLocator("localhost", _geodeServer.LocatorPort); + var pool = poolFactory + .SetSubscriptionEnabled(true) + .Create("pool"); + + var regionFactory = _cache.CreateRegionFactory(RegionShortcut.PROXY) + .SetPoolName("pool"); + + var region = regionFactory.Create<string, Position>("cqTestRegion"); + + var queryService = pool.GetQueryService(); + var cqAttributesFactory = new CqAttributesFactory<string, Position>(); + var cqListener = new DataCqListener<string, Position>(); + cqAttributesFactory.AddCqListener(cqListener); + var cqAttributes = cqAttributesFactory.Create(); + + var query = queryService.NewCq("MyCq", "SELECT * FROM /cqTestRegion WHERE sharesOutstanding > 30", cqAttributes, false); + Debug.WriteLine("Executing continuous query"); + query.Execute(); + + Debug.WriteLine("Putting and changing Position objects in the region"); + var order1 = new Position("GOOG", 23); + var order2 = new Position("IBM", 37); + var order3 = new Position("PVTL", 101); + + region.Put("order1", order1); + var Value = region["order1"]; + + region.Put("order2", order2); + Assert.True(cqListener.CreatedEvent.WaitOne(_waitInterval), "Didn't receive expected CREATE event"); + + order1.SharesOutstanding = 55; + region.Put("order1", order1); + Assert.True(cqListener.CreatedEvent.WaitOne(_waitInterval), "Didn't receive expected CREATE event"); + + order2.SharesOutstanding = 77; + region.Put("order2", order2); + Assert.True(cqListener.UpdatedEvent.WaitOne(_waitInterval), "Didn't receive expected UPDATE event"); + + order2.SharesOutstanding = 11; + region.Put("order2", order2); + Assert.True(cqListener.DestroyedNonNullEvent.WaitOne(_waitInterval), "Didn't receive expected DESTROY event"); + + region.Remove("order1"); + Assert.True(cqListener.DestroyedNullEvent.WaitOne(_waitInterval), "Didn't receive expected DESTROY event"); + + region.Put("order3", order3); + Assert.True(cqListener.CreatedEvent.WaitOne(_waitInterval), "Didn't receive expected CREATE event"); + + region.Clear(); + Assert.True(cqListener.RegionClearEvent.WaitOne(_waitInterval), "Didn't receive expected CLEAR event"); + Assert.False(cqListener.ReceivedUnknownEventType, "An unknown event was received by CQ listener"); } } diff --git a/clicache/integration-test2/GeodeServer.cs b/clicache/integration-test2/GeodeServer.cs index 0844d88..3f34905 100644 --- a/clicache/integration-test2/GeodeServer.cs +++ b/clicache/integration-test2/GeodeServer.cs @@ -87,18 +87,21 @@ public class GeodeServer : IDisposable { StartInfo = { - FileName = Config.GeodeGfsh, - Arguments = " -e \"start locator --bind-address=localhost --port=" + LocatorPort + - " --J=-Dgemfire.jmx-manager-port=" + LocatorJmxPort + " --http-service-port=0" + "\"" + - " -e \"start server --bind-address=localhost --server-port=0\"" + - " -e \"create region --name=" + regionName + " --type=PARTITION\"" + - " -e \"create region --name=testRegion1 --type=PARTITION\"" + - " -e \"create region --name=cqTestRegion --type=REPLICATE\"", - WindowStyle = ProcessWindowStyle.Hidden, - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - CreateNoWindow = true + + FileName = Config.GeodeGfsh, + Arguments = " -e \"start locator --name=locator1 --bind-address=localhost --port=" + LocatorPort + + " --J=-Dgemfire.jmx-manager-port=" + LocatorJmxPort + " --http-service-port=0" + "\"" + + " -e \"deploy --jar=..\\..\\..\\tests\\javaobject\\javaobject.jar\"" + + " -e \"start server --name=server1 --bind-address=localhost --cache-xml-file=server.xml --server-port=0\"" + + " -e \"start server --name=server1 --bind-address=localhost --server-port=0\"" + + " -e \"create region --name=" + regionName + " --type=PARTITION\"" + + " -e \"create region --name=testRegion1 --type=PARTITION\"" + + " -e \"create region --name=cqTestRegion --type=REPLICATE\"", + WindowStyle = ProcessWindowStyle.Hidden, + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + CreateNoWindow = true } }; } diff --git a/clicache/integration-test2/GeodeServerTests.cs b/clicache/integration-test2/GeodeServerTests.cs index 271186c..2374310 100644 --- a/clicache/integration-test2/GeodeServerTests.cs +++ b/clicache/integration-test2/GeodeServerTests.cs @@ -18,7 +18,7 @@ using Xunit; [Trait("Category", "Integration")] -public class GemFireServerTest +public class GeodeServerTest { [Fact] public void Start() diff --git a/clicache/integration-test2/Position.cs b/clicache/integration-test2/Position.cs new file mode 100644 index 0000000..ca3730f --- /dev/null +++ b/clicache/integration-test2/Position.cs @@ -0,0 +1,239 @@ +/* + * 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.IntegrationTests +{ + using Apache.Geode.Client; + public class Position + : IDataSerializable + { + #region Private members + + private long m_avg20DaysVol; + private string m_bondRating; + private double m_convRatio; + private string m_country; + private double m_delta; + private long m_industry; + private long m_issuer; + private double m_mktValue; + private double m_qty; + private string m_secId; + private string m_secLinks; + private string m_secType; + private int m_sharesOutstanding; + private string m_underlyer; + private long m_volatility; + private int m_pid; + + private static int m_count = 0; + + #endregion + + #region Private methods + + private void Init() + { + m_avg20DaysVol = 0; + m_bondRating = "bondRatingString"; + m_convRatio = 0.0; + m_country = null; + m_delta = 0.0; + m_industry = 0; + m_issuer = 0; + m_mktValue = 0.0; + m_qty = 0.0; + m_secId = null; + m_secLinks = null; + m_secType = null; + m_sharesOutstanding = 0; + m_underlyer = null; + m_volatility = 0; + m_pid = 0; + } + + private UInt64 GetObjectSize(ISerializable obj) + { + return (obj == null ? 0 : obj.ObjectSize); + } + + #endregion + + #region Public accessors + + public string SecId + { + get + { + return m_secId; + } + } + + public int Id + { + get + { + return m_pid; + } + } + + public int SharesOutstanding + { + get + { + return m_sharesOutstanding; + } + set + { + m_sharesOutstanding = value; + } + } + + public static int Count + { + get + { + return m_count; + } + set + { + m_count = value; + } + } + + public override string ToString() + { + return "Position [secId=" + m_secId + " sharesOutstanding=" + m_sharesOutstanding + " type=" + m_secType + " id=" + m_pid + "]"; + } + #endregion + + #region Constructors + + public Position() + { + Init(); + } + + //This ctor is for a data validation test + public Position(Int32 iForExactVal) + { + Init(); + + char[] id = new char[iForExactVal + 1]; + for (int i = 0; i <= iForExactVal; i++) + { + id[i] = 'a'; + } + m_secId = id.ToString(); + m_qty = iForExactVal % 2 == 0 ? 1000 : 100; + m_mktValue = m_qty * 2; + m_sharesOutstanding = iForExactVal; + m_secType = "a"; + m_pid = iForExactVal; + } + + public Position(string id, int shares) + { + Init(); + m_secId = id; + m_qty = shares * (m_count % 2 == 0 ? 10.0 : 100.0); + m_mktValue = m_qty * 1.2345998; + m_sharesOutstanding = shares; + m_secType = "a"; + m_pid = m_count++; + } + + #endregion + + #region IDataSerializable Members + + public void FromData(DataInput input) + { + m_avg20DaysVol = input.ReadInt64(); + m_bondRating = input.ReadUTF(); + m_convRatio = input.ReadDouble(); + m_country = input.ReadUTF(); + m_delta = input.ReadDouble(); + m_industry = input.ReadInt64(); + m_issuer = input.ReadInt64(); + m_mktValue = input.ReadDouble(); + m_qty = input.ReadDouble(); + m_secId = input.ReadUTF(); + m_secLinks = input.ReadUTF(); + m_secType = input.ReadUTF(); + m_sharesOutstanding = input.ReadInt32(); + m_underlyer = input.ReadUTF(); + m_volatility = input.ReadInt64(); + m_pid = input.ReadInt32(); + } + + public void ToData(DataOutput output) + { + output.WriteInt64(m_avg20DaysVol); + output.WriteUTF(m_bondRating); + output.WriteDouble(m_convRatio); + output.WriteUTF(m_country); + output.WriteDouble(m_delta); + output.WriteInt64(m_industry); + output.WriteInt64(m_issuer); + output.WriteDouble(m_mktValue); + output.WriteDouble(m_qty); + output.WriteUTF(m_secId); + output.WriteUTF(m_secLinks); + output.WriteUTF(m_secType); + output.WriteInt32(m_sharesOutstanding); + output.WriteUTF(m_underlyer); + output.WriteInt64(m_volatility); + output.WriteInt32(m_pid); + + } + + public UInt64 ObjectSize + { + get + { + UInt64 objectSize = 0; + objectSize += (UInt64)sizeof(long); + objectSize += (UInt64) (m_bondRating.Length * sizeof(char)); + objectSize += (UInt64)sizeof(double); + objectSize += (UInt64)(m_country.Length * sizeof(char)); + objectSize += (UInt64)sizeof(double); + objectSize += (UInt64)sizeof(Int64); + objectSize += (UInt64)sizeof(Int64); + objectSize += (UInt64)sizeof(double); + objectSize += (UInt64)sizeof(double); + objectSize += (UInt64)(m_secId.Length * sizeof(char)); + objectSize += (UInt64)(m_secLinks.Length * sizeof(char)); + objectSize += (UInt64)(m_secType == null ? 0 : sizeof(char) * m_secType.Length); + objectSize += (UInt64)sizeof(Int32); + objectSize += (UInt64)(m_underlyer.Length * sizeof(char)); + objectSize += (UInt64)sizeof(Int64); + objectSize += (UInt64)sizeof(Int32); + return objectSize; + } + } + + #endregion + + public static ISerializable CreateDeserializable() + { + return new Position(); + } + } +} diff --git a/clicache/integration-test2/server.xml b/clicache/integration-test2/server.xml new file mode 100644 index 0000000..8d8a088 --- /dev/null +++ b/clicache/integration-test2/server.xml @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<!-- + 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. +--> +<cache + xmlns="http://geode.apache.org/schema/cache" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd" version="1.0"> + <serialization-registration> + <instantiator id="22"> + <class-name>javaobject.cli.Position</class-name> + </instantiator> + </serialization-registration> +</cache> \ No newline at end of file diff --git a/clicache/integration-test2/xunit.runner.json b/clicache/integration-test2/xunit.runner.json index a7903ec..6d84265 100644 --- a/clicache/integration-test2/xunit.runner.json +++ b/clicache/integration-test2/xunit.runner.json @@ -1,4 +1,5 @@ { "methodDisplay": "classAndMethod", - "parallelizeTestCollections": "false" + "parallelizeAssembly": false , + "parallelizeTestCollections": false } diff --git a/tests/javaobject/CMakeLists.txt b/tests/javaobject/CMakeLists.txt index 4cd0d30..3f3a595 100644 --- a/tests/javaobject/CMakeLists.txt +++ b/tests/javaobject/CMakeLists.txt @@ -22,6 +22,7 @@ include(UseJava) file(GLOB_RECURSE SOURCES "*.java") + add_jar(javaobject ${SOURCES} INCLUDE_JARS ${Geode_CLASSPATH} ) diff --git a/tests/javaobject/cli/Position.java b/tests/javaobject/cli/Position.java new file mode 100644 index 0000000..8796e25 --- /dev/null +++ b/tests/javaobject/cli/Position.java @@ -0,0 +1,217 @@ +/* + * 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. + */ +package javaobject.cli; + +import java.util.*; +import java.io.*; +import org.apache.geode.*; +import org.apache.geode.cache.Declarable; + + +public class Position implements Declarable, Serializable, DataSerializable { + private long avg20DaysVol=0; + private String bondRating; + private double convRatio; + private String country; + private double delta; + private long industry; + private long issuer; + private double mktValue; + private double qty; + public String secId; + private String secLinks; + public String secType; + private int sharesOutstanding; + public String underlyer; + private long volatility; + private int pid; + public static int cnt = 0; + + static { + Instantiator.register(new Instantiator(javaobject.cli.Position.class, (byte) 22) { + public DataSerializable newInstance() { + return new Position(); + } + }); + } + + public void init(Properties props) { + this.secId = props.getProperty("secId"); + + if(props.getProperty("qty") != null) { + this.qty = Double.parseDouble( props.getProperty("qty") ); + } + + if(props.getProperty("mktValue") != null) { + this.mktValue = Double.parseDouble( props.getProperty("mktValue") ); + } + + this.sharesOutstanding = Integer.parseInt(props.getProperty("sharesOutstanding")); + this.secType = props.getProperty("secType"); + this.pid = Integer.parseInt(props.getProperty("pid")); + } + + /* public no-arg constructor required for DataSerializable */ + public Position() {} + + public Position(String id, int out){ + secId = id; + sharesOutstanding = out; + secType = "a"; + pid = cnt++; + } + + public static void resetCounter() { + cnt = 0; + } + public String getSecId(){ + return secId; + } + + public int getId(){ + return pid; + } + + public int getSharesOutstanding(){ + return sharesOutstanding; + } + + public String toString(){ + return "Position [secId="+secId+" sharesOutstanding="+sharesOutstanding+ " type="+secType +" id="+pid+"]"; + } + + public Set getSet(int size){ + Set set = new HashSet(); + for(int i=0;i<size;i++){ + set.add(""+i); + } + return set; + } + + public Set getCol(){ + Set set = new HashSet(); + for(int i=0;i<2;i++){ + set.add(""+i); + } + return set; + } + + public void fromData(DataInput in) throws IOException, ClassNotFoundException { + this.avg20DaysVol = in.readLong(); + this.bondRating = in.readUTF(); + this.convRatio = in.readDouble(); + this.country = in.readUTF(); + this.delta = in.readDouble(); + this.industry = in.readLong(); + this.issuer = in.readLong(); + this.mktValue = in.readDouble(); + this.qty = in.readDouble(); + this.secId = in.readUTF(); + this.secLinks = in.readUTF(); + this.secType = in.readUTF(); + this.sharesOutstanding = in.readInt(); + this.underlyer = in.readUTF(); + this.volatility = in.readLong(); + this.pid = in.readInt(); + } + + public void toData(DataOutput out) throws IOException { + out.writeLong(this.avg20DaysVol); + out.writeUTF(this.bondRating); + out.writeDouble(this.convRatio); + out.writeUTF(this.country); + out.writeDouble(this.delta); + out.writeLong(this.industry); + out.writeLong(this.issuer); + out.writeDouble(this.mktValue); + out.writeDouble(this.qty); + out.writeUTF(this.secId); + out.writeUTF(this.secLinks); + out.writeUTF(this.secType); + out.writeInt(this.sharesOutstanding); + out.writeUTF(this.underlyer); + out.writeLong(this.volatility); + out.writeInt(this.pid); + } + + public static boolean compareForEquals(Object first, Object second) { + if (first == null && second == null) return true; + if (first != null && first.equals(second)) return true; + return false; + } + + public boolean equals(Object other) { + if (other==null) return false; + if (!(other instanceof Position)) return false; + + Position pos = (Position) other; + + if (this.avg20DaysVol != pos.avg20DaysVol) return false; + if (this.convRatio != pos.convRatio) return false; + if (this.delta != pos.delta) return false; + if (this.industry != pos.industry) return false; + if (this.issuer != pos.issuer) return false; + if (this.mktValue != pos.mktValue) return false; + if (this.qty != pos.qty) return false; + if (this.sharesOutstanding != pos.sharesOutstanding) return false; + if (this.volatility != pos.volatility) return false; + if (this.pid != pos.pid) return false; + + if (!Position.compareForEquals(this.bondRating, pos.bondRating)) return false; + if (!Position.compareForEquals(this.country, pos.country)) return false; + if (!Position.compareForEquals(this.secId, pos.secId)) return false; + if (!Position.compareForEquals(this.secLinks, pos.secLinks)) return false; + if (!Position.compareForEquals(this.secType, pos.secType)) return false; + if (!Position.compareForEquals(this.underlyer, pos.underlyer)) return false; + + return true; + } + + public int hashCode() { + Long avg = new Long(avg20DaysVol); + Double convRat = new Double(convRatio); + Double del = new Double(delta); + Long ind = new Long(industry); + Long iss = new Long(issuer); + Double mktVal = new Double(mktValue); + Double quant = new Double(qty); + Integer shout = new Integer(sharesOutstanding); + Long vol = new Long(volatility); + Integer id = new Integer(pid); + + int hashcode = + avg.hashCode() ^ + convRat.hashCode() ^ + del.hashCode() ^ + ind.hashCode() ^ + iss.hashCode() ^ + mktVal.hashCode() ^ + quant.hashCode() ^ + shout.hashCode() ^ + vol.hashCode() ^ + id.hashCode(); + + if (this.country != null) hashcode ^= country.hashCode(); + if (this.bondRating != null) hashcode ^= bondRating.hashCode(); + if (this.secId != null) hashcode ^= secId.hashCode(); + if (this.secLinks != null) hashcode ^= secLinks.hashCode(); + if (this.secType != null) hashcode ^= secType.hashCode(); + if (this.underlyer != null) hashcode ^= underlyer.hashCode(); + + return hashcode; + } +}