Skip to content

Commit

Permalink
invocation timeout fixed to respect long running operations
Browse files Browse the repository at this point in the history
  • Loading branch information
asimarslan committed Jul 18, 2017
1 parent 985de41 commit e16f3ad
Show file tree
Hide file tree
Showing 13 changed files with 296 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ public ClientConnectionManager(HazelcastClient client)
}
_socketInterceptor = null;

var timeout = EnvironmentUtil.ReadEnvironmentVar("hazelcast.client.invocation.timeout.seconds");
if (timeout > 0)
{
ThreadUtil.TaskOperationTimeOutMilliseconds = timeout.Value*1000;
}

_heartbeatTimeout = EnvironmentUtil.ReadEnvironmentVar("hazelcast.client.heartbeat.timeout") ??
_heartbeatTimeout;
_heartbeatInterval = EnvironmentUtil.ReadEnvironmentVar("hazelcast.client.heartbeat.interval") ??
Expand Down
21 changes: 19 additions & 2 deletions Hazelcast.Net/Hazelcast.Client.Spi/ClientInvocationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,17 @@ private void HandleInvocationException(ClientInvocation invocation, Exception ex
}
}
//Fail with exception
if (!invocation.Future.IsComplete)
try
{
invocation.Future.Exception = exception;
}
catch (InvalidOperationException e)
{
if (Logger.IsFinestEnabled())
{
Logger.Finest("Invocation already completed:", e);
}
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -530,7 +537,17 @@ private void HandleResponseMessage(IClientMessage response)
}
else
{
invocation.Future.Result = response;
try
{
invocation.Future.Result = response;
}
catch (InvalidOperationException e)
{
if (Logger.IsFinestEnabled())
{
Logger.Finest("Invocation already completed:", e);
}
}
}
}
else
Expand Down
15 changes: 9 additions & 6 deletions Hazelcast.Net/Hazelcast.Util/ThreadUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,31 @@ namespace Hazelcast.Util
{
internal sealed class ThreadUtil
{
public static int TaskOperationTimeOutMilliseconds = 250*1000;

public static IList<IClientMessage> GetResult(IEnumerable<IFuture<IClientMessage>> futures)
{
return futures.Select(future => GetResult(future)).ToList();
}

public static IClientMessage GetResult(IFuture<IClientMessage> future, int? timeout = null)
public static IClientMessage GetResult(IFuture<IClientMessage> future)
{
return future.GetResult(Timeout.Infinite);
}

public static IClientMessage GetResult(IFuture<IClientMessage> future, int timeout)
{
return future.GetResult(timeout ?? TaskOperationTimeOutMilliseconds);
return future.GetResult(timeout);
}

public static IClientMessage GetResult(Task<IClientMessage> task)
{
return GetResult(task, TaskOperationTimeOutMilliseconds);
return GetResult(task, Timeout.Infinite);
}

public static IClientMessage GetResult(Task<IClientMessage> task, int timeout)
{
try
{
var responseReady = task.Wait(TimeSpan.FromMilliseconds(TaskOperationTimeOutMilliseconds));
var responseReady = task.Wait(timeout);
if (!responseReady)
{
throw new TimeoutException("Operation time-out! No response received from the server.");
Expand Down
65 changes: 65 additions & 0 deletions Hazelcast.Test/Hazelcast.Client.Test/ClientLongRunningTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
//
// Licensed 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;
using Hazelcast.Core;
using Hazelcast.Test;
using NUnit.Framework;

namespace Hazelcast.Client.Test
{
[TestFixture]
[Category("enterprise")]
public class ClientLongRunningTest : SingleMemberBaseTest
{
private static IMap<object, object> map;

[SetUp]
public void Init()
{
map = Client.GetMap<object, object>(TestSupport.RandomString());
FillMap();
}

[TearDown]
public static void Destroy()
{
map.Clear();
}

protected override string GetServerConfig()
{
return Resources.hazelcast_delay;
}

private void FillMap()
{
for (var i = 0; i < 10; i++)
{
map.Put("key" + i, "value" + i);
}
}

[Test]
public void TestLongRunning()
{
var starTicks = DateTime.Now.Ticks;
var collection = map.Values(Predicates.Sql("this == 'value5'"));

var timeSpan = new TimeSpan(DateTime.Now.Ticks - starTicks);
Assert.IsNotEmpty(collection);
Assert.GreaterOrEqual(timeSpan.TotalSeconds, 300);
}
}
}
7 changes: 6 additions & 1 deletion Hazelcast.Test/Hazelcast.Client.Test/SingleMemberBaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class SingleMemberBaseTest : HazelcastTestSupport
public void SetupCluster()
{
RemoteController = CreateRemoteController();
var cluster = CreateCluster(RemoteController);
var cluster = CreateCluster(RemoteController, GetServerConfig());
RemoteController.startMember(cluster.Id);
Client = CreateClient();
}
Expand All @@ -39,5 +39,10 @@ public void ShutdownRemoteController()
HazelcastClient.ShutdownAll();
StopRemoteController(RemoteController);
}

protected virtual string GetServerConfig()
{
return Resources.hazelcast;
}
}
}
4 changes: 4 additions & 0 deletions Hazelcast.Test/Hazelcast.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="Hazelcast.Client.Model\IdentifiedFactory.cs" />
<Compile Include="Hazelcast.Client.Test\AggregatorAndProjectionTest.cs" />
<Compile Include="Hazelcast.Client.Test\ClientExecutorServiceTest.cs" />
<Compile Include="Hazelcast.Client.Test\ClientLongRunningTest.cs" />
<Compile Include="Hazelcast.Client.Test\ClientSSLTest.cs" />
<Compile Include="Hazelcast.Client.Test\PagingPredicateTest.cs" />
<Compile Include="Hazelcast.Client.Test\PredicateExtTest.cs" />
Expand Down Expand Up @@ -259,6 +260,9 @@
<ItemGroup>
<None Include="Resources\hazelcast-ssl.xml" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\hazelcast-delay.xml" />
</ItemGroup>
<PropertyGroup>
<NUnitResultsFile>$(OutputPath)nunit-result.xml</NUnitResultsFile>
</PropertyGroup>
Expand Down
86 changes: 84 additions & 2 deletions Hazelcast.Test/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Hazelcast.Test/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@
<data name="hazelcast_config_full" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\hazelcast-client-full.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="hazelcast_delay" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\hazelcast-delay.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
</data>
<data name="hazelcast_ssl" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\hazelcast-ssl.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
<value>..\Resources\hazelcast-ssl.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;iso-8859-1</value>
</data>
</root>
2 changes: 1 addition & 1 deletion Hazelcast.Test/Resources/hazelcast-client-full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
~ limitations under the License.
-->

<hazelcast-client xsi:schemaLocation="http://www.hazelcast.com/schema/client-config hazelcast-client-config-3.5.xsd"
<hazelcast-client xsi:schemaLocation="http://www.hazelcast.com/schema/client-config hazelcast-client-config-3.8.xsd"
xmlns="http://www.hazelcast.com/schema/client-config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Expand Down

0 comments on commit e16f3ad

Please sign in to comment.