Skip to content

Commit

Permalink
PyroProxy now gets the right pyroOneway settings from the metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Jul 11, 2019
1 parent ed875ce commit 317777d
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dotnet/Razorvine.Pyrolite/Pyrolite/Pyro/PyroProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected void GetMetadata(string objectId) {
/// Extract meta data and store it in the relevant properties on the proxy.
/// If no attribute or method is exposed at all, throw an exception.
/// </summary>
private void _processMetadata(IDictionary result)
protected void _processMetadata(IDictionary result)
{
// the collections in the result can be either an object[] or a HashSet<object> or List<object>,
// depending on the serializer and Pyro version that is used
Expand All @@ -132,12 +132,18 @@ private void _processMetadata(IDictionary result)

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

if(!pyroMethods.Any() && !pyroAttrs.Any()) {
throw new PyroException("remote object doesn't expose any methods or attributes");
}
}

protected void _processMetadata(IDictionary<object, object> data)
{
var dict = (IDictionary) data;
_processMetadata(dict);
}

protected static HashSet<string> GetStringSet(object strings)
{
Expand Down
91 changes: 91 additions & 0 deletions dotnet/Razorvine.Pyrolite/Tests/Pyro/SerializePyroTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,97 @@ public void TestBytes()
}
}


/// <summary>
/// Some tests about the peculiarities of the handshake
/// </summary>
public class HandshakeTests
{
class MetadataProxy : PyroProxy
{
public MetadataProxy() : base("test", 999, "object42")
{
}

public void TestMetadataHashtable(Hashtable table)
{
base._processMetadata(table);
}

public void TestMetadataDictionary(IDictionary dict)
{
base._processMetadata(dict);
}

public void TestMetadataGenericDict(IDictionary<object, object> dict)
{
base._processMetadata(dict);
}
}


[Fact]
public void TestHandshakeDicts()
{
var proxy = new MetadataProxy();

var hashtable = new Hashtable
{
{"methods", new object[] {"method1"}},
{"attrs", new List<object>() {"attr1"}},
{"oneway", new HashSet<object>() {"oneway1"}}
};
var dict = new SortedList
{
{"methods", new object[] {"method1"}},
{"attrs", new List<object>() {"attr1"}},
{"oneway", new HashSet<object>() {"oneway1"}}
};
var gdict = new Dictionary<object, object>
{
{"methods", new object[] {"method1"}},
{"attrs", new List<object>() {"attr1"}},
{"oneway", new HashSet<object>() {"oneway1"}}
};

var expectedMethods = new HashSet<string> {"method1"};
var expectedAttrs = new HashSet<string> {"attr1"};
var expectedOneway = new HashSet<string> {"oneway1"};

proxy.pyroMethods.Clear();
proxy.pyroAttrs.Clear();
proxy.pyroOneway.Clear();
proxy.TestMetadataHashtable(hashtable);
Assert.Equal(expectedMethods, proxy.pyroMethods);
Assert.Equal(expectedAttrs, proxy.pyroAttrs);
Assert.Equal(expectedOneway, proxy.pyroOneway);

proxy.pyroMethods.Clear();
proxy.pyroAttrs.Clear();
proxy.pyroOneway.Clear();
proxy.TestMetadataDictionary(dict);
Assert.Equal(expectedMethods, proxy.pyroMethods);
Assert.Equal(expectedAttrs, proxy.pyroAttrs);
Assert.Equal(expectedOneway, proxy.pyroOneway);

proxy.pyroMethods.Clear();
proxy.pyroAttrs.Clear();
proxy.pyroOneway.Clear();
proxy.TestMetadataDictionary(gdict);
Assert.Equal(expectedMethods, proxy.pyroMethods);
Assert.Equal(expectedAttrs, proxy.pyroAttrs);
Assert.Equal(expectedOneway, proxy.pyroOneway);

proxy.pyroMethods.Clear();
proxy.pyroAttrs.Clear();
proxy.pyroOneway.Clear();
proxy.TestMetadataGenericDict(gdict);
Assert.Equal(expectedMethods, proxy.pyroMethods);
Assert.Equal(expectedAttrs, proxy.pyroAttrs);
Assert.Equal(expectedOneway, proxy.pyroOneway);
}
}

/// <summary>
/// Miscellaneous tests.
/// </summary>
Expand Down

0 comments on commit 317777d

Please sign in to comment.