Nikolay Izhikov created IGNITE-14299:
----------------------------------------

             Summary: .Net Service loses array type information in case .Net 
<-> .Net call
                 Key: IGNITE-14299
                 URL: https://issues.apache.org/jira/browse/IGNITE-14299
             Project: Ignite
          Issue Type: Improvement
            Reporter: Nikolay Izhikov
            Assignee: Nikolay Izhikov


In case .Net -> .Net service call Ignite loses arra 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.3.4#803005)

Reply via email to