You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ignite.apache.org by "Nikolay Izhikov (Jira)" <ji...@apache.org> on 2021/12/10 10:16:00 UTC
[jira] [Updated] (IGNITE-14299) .NET: Service loses array type information
[ https://issues.apache.org/jira/browse/IGNITE-14299?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Nikolay Izhikov updated IGNITE-14299:
-------------------------------------
Fix Version/s: 2.13
> .NET: Service loses array type information
> ------------------------------------------
>
> Key: IGNITE-14299
> URL: https://issues.apache.org/jira/browse/IGNITE-14299
> Project: Ignite
> Issue Type: Bug
> Reporter: Nikolay Izhikov
> Assignee: Nikolay Izhikov
> Priority: Major
> Labels: .NET
> Fix For: 2.13
>
> Time Spent: 4h 10m
> Remaining Estimate: 0h
>
> In case .Net -> .Net service call Ignite loses array type information.
> {code:java}
> using Apache.Ignite.Core;
> using Apache.Ignite.Core.Discovery.Tcp;
> using Apache.Ignite.Core.Discovery.Tcp.Static;
> using Apache.Ignite.Core.Services;
> using Castle.DynamicProxy;
> using System;
> using System.Linq;
> using Xunit;
> namespace Ignite.ServiceReturnsArray
> {
> public class Test : IDisposable
> {
> private readonly IIgnite igniteSrv;
> private readonly IIgnite ignite;
> public Test()
> {
> IgniteConfiguration IgniteConfig(bool clientMode) => new IgniteConfiguration()
> {
> ClientMode = clientMode,
> IgniteInstanceName = Guid.NewGuid().ToString(),
> DiscoverySpi = new TcpDiscoverySpi
> {
> IpFinder = new TcpDiscoveryStaticIpFinder { Endpoints = new[] { "127.0.0.1:47500" } }
> }
> };
> igniteSrv = Ignition.Start(IgniteConfig(false));
> ignite = Ignition.Start(IgniteConfig(true));
> ignite.GetServices().DeployClusterSingleton(nameof(ArrayFactoryService), new ArrayFactoryService());
> }
> public void Dispose()
> {
> ignite.Dispose();
> igniteSrv.Dispose();
> }
> [Fact]
> public void ServiceReturnsArray()
> {
> var arr = ignite.GetServices().GetServiceProxy<IArrayFactory>(nameof(ArrayFactoryService), false)
> .CreateArray(2, 1);
> Assert.IsType<Result[]>(arr);
> Assert.Equal(1, arr?[1]?.Value);
> }
> [Fact]
> public void ServiceReturnsArrayWithReflection()
> {
> var arr = typeof(IArrayFactory).GetMethod(nameof(IArrayFactory.CreateArray)).Invoke(
> ignite.GetServices().GetServiceProxy<IArrayFactory>(nameof(ArrayFactoryService)),
> new object[] { 2, 1 });
> Assert.IsType<Result[]>(arr);
> Assert.Equal(1, ((Result[])arr)?[1]?.Value);
> }
> [Fact]
> public void ServiceReturnsArrayWithCastleProxy()
> {
> var interceptor = new ServiceInterceptor<IArrayFactory>(ignite, nameof(ArrayFactoryService));
>
> var arr = new ProxyGenerator().CreateInterfaceProxyWithoutTarget<IArrayFactory>(interceptor)
> .CreateArray(2, 1);
> Assert.IsType<Result[]>(arr);
> Assert.Equal(1, arr?[1]?.Value);
> }
> public sealed class Result
> {
> public int Value { get; set; }
> }
> public interface IArrayFactory
> {
> Result[] CreateArray(int size, int dlftVal);
> }
> public sealed class ArrayFactoryService : IArrayFactory, IService
> {
> public Result[] CreateArray(int size, int dfltVal)
> {
> return Enumerable.Repeat(new Result { Value = dfltVal }, size).ToArray();
> }
> public void Cancel(IServiceContext context)
> {
> }
> public void Execute(IServiceContext context)
> {
> }
> public void Init(IServiceContext context)
> {
> }
> }
> private sealed class ServiceInterceptor<T> : IInterceptor where T: class
> {
> private readonly IIgnite ignite;
> private readonly string name;
> public ServiceInterceptor(IIgnite ignite, string name)
> {
> this.ignite = ignite;
> this.name = name;
> }
> public void Intercept(IInvocation invocation)
> {
> var svc = ignite.GetServices().GetServiceProxy<T>(name, false);
> invocation.ReturnValue = invocation.Method.Invoke(svc, invocation.Arguments);
> }
> }
> }
> }
> {code}
>
> Above test fail on type check.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)