Skip to content

Commit 317777d

Browse files
committed
PyroProxy now gets the right pyroOneway settings from the metadata
1 parent ed875ce commit 317777d

File tree

2 files changed

+99
-2
lines changed

2 files changed

+99
-2
lines changed

dotnet/Razorvine.Pyrolite/Pyrolite/Pyro/PyroProxy.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected void GetMetadata(string objectId) {
122122
/// Extract meta data and store it in the relevant properties on the proxy.
123123
/// If no attribute or method is exposed at all, throw an exception.
124124
/// </summary>
125-
private void _processMetadata(IDictionary result)
125+
protected void _processMetadata(IDictionary result)
126126
{
127127
// the collections in the result can be either an object[] or a HashSet<object> or List<object>,
128128
// depending on the serializer and Pyro version that is used
@@ -132,12 +132,18 @@ private void _processMetadata(IDictionary result)
132132

133133
pyroMethods = methods_array != null ? new HashSet<string>(methods_array.Select(o => o as string)) : GetStringSet(result["methods"]);
134134
pyroAttrs = attrs_array != null ? new HashSet<string>(attrs_array.Select(o => o as string)) : GetStringSet(result["attrs"]);
135-
pyroOneway = oneway_array != null ? new HashSet<string>(oneway_array.Select(o => o as string)) : GetStringSet(result["attrs"]);
135+
pyroOneway = oneway_array != null ? new HashSet<string>(oneway_array.Select(o => o as string)) : GetStringSet(result["oneway"]);
136136

137137
if(!pyroMethods.Any() && !pyroAttrs.Any()) {
138138
throw new PyroException("remote object doesn't expose any methods or attributes");
139139
}
140140
}
141+
142+
protected void _processMetadata(IDictionary<object, object> data)
143+
{
144+
var dict = (IDictionary) data;
145+
_processMetadata(dict);
146+
}
141147

142148
protected static HashSet<string> GetStringSet(object strings)
143149
{

dotnet/Razorvine.Pyrolite/Tests/Pyro/SerializePyroTests.cs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,97 @@ public void TestBytes()
164164
}
165165
}
166166

167+
168+
/// <summary>
169+
/// Some tests about the peculiarities of the handshake
170+
/// </summary>
171+
public class HandshakeTests
172+
{
173+
class MetadataProxy : PyroProxy
174+
{
175+
public MetadataProxy() : base("test", 999, "object42")
176+
{
177+
}
178+
179+
public void TestMetadataHashtable(Hashtable table)
180+
{
181+
base._processMetadata(table);
182+
}
183+
184+
public void TestMetadataDictionary(IDictionary dict)
185+
{
186+
base._processMetadata(dict);
187+
}
188+
189+
public void TestMetadataGenericDict(IDictionary<object, object> dict)
190+
{
191+
base._processMetadata(dict);
192+
}
193+
}
194+
195+
196+
[Fact]
197+
public void TestHandshakeDicts()
198+
{
199+
var proxy = new MetadataProxy();
200+
201+
var hashtable = new Hashtable
202+
{
203+
{"methods", new object[] {"method1"}},
204+
{"attrs", new List<object>() {"attr1"}},
205+
{"oneway", new HashSet<object>() {"oneway1"}}
206+
};
207+
var dict = new SortedList
208+
{
209+
{"methods", new object[] {"method1"}},
210+
{"attrs", new List<object>() {"attr1"}},
211+
{"oneway", new HashSet<object>() {"oneway1"}}
212+
};
213+
var gdict = new Dictionary<object, object>
214+
{
215+
{"methods", new object[] {"method1"}},
216+
{"attrs", new List<object>() {"attr1"}},
217+
{"oneway", new HashSet<object>() {"oneway1"}}
218+
};
219+
220+
var expectedMethods = new HashSet<string> {"method1"};
221+
var expectedAttrs = new HashSet<string> {"attr1"};
222+
var expectedOneway = new HashSet<string> {"oneway1"};
223+
224+
proxy.pyroMethods.Clear();
225+
proxy.pyroAttrs.Clear();
226+
proxy.pyroOneway.Clear();
227+
proxy.TestMetadataHashtable(hashtable);
228+
Assert.Equal(expectedMethods, proxy.pyroMethods);
229+
Assert.Equal(expectedAttrs, proxy.pyroAttrs);
230+
Assert.Equal(expectedOneway, proxy.pyroOneway);
231+
232+
proxy.pyroMethods.Clear();
233+
proxy.pyroAttrs.Clear();
234+
proxy.pyroOneway.Clear();
235+
proxy.TestMetadataDictionary(dict);
236+
Assert.Equal(expectedMethods, proxy.pyroMethods);
237+
Assert.Equal(expectedAttrs, proxy.pyroAttrs);
238+
Assert.Equal(expectedOneway, proxy.pyroOneway);
239+
240+
proxy.pyroMethods.Clear();
241+
proxy.pyroAttrs.Clear();
242+
proxy.pyroOneway.Clear();
243+
proxy.TestMetadataDictionary(gdict);
244+
Assert.Equal(expectedMethods, proxy.pyroMethods);
245+
Assert.Equal(expectedAttrs, proxy.pyroAttrs);
246+
Assert.Equal(expectedOneway, proxy.pyroOneway);
247+
248+
proxy.pyroMethods.Clear();
249+
proxy.pyroAttrs.Clear();
250+
proxy.pyroOneway.Clear();
251+
proxy.TestMetadataGenericDict(gdict);
252+
Assert.Equal(expectedMethods, proxy.pyroMethods);
253+
Assert.Equal(expectedAttrs, proxy.pyroAttrs);
254+
Assert.Equal(expectedOneway, proxy.pyroOneway);
255+
}
256+
}
257+
167258
/// <summary>
168259
/// Miscellaneous tests.
169260
/// </summary>

0 commit comments

Comments
 (0)