Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
`ConnectionFactory#CreateConnection` could deadlock in some circumstances.

GH issue: [rabbitmq-dotnet-client#239](https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/239).

Occasional NullReferenceException when unable to resolve any endpoints/

GH issue: [rabbitmq-dotnet-client#238](https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/238)
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public static T SelectOne<T>(this IEndpointResolver resolver, Func<AmqpTcpEndpoi
exception = e;
}
}
if(t.Equals(default(T)))

if(Object.Equals(t, default(T)) && exception != null)
{
throw exception;
}
Expand Down
92 changes: 92 additions & 0 deletions projects/client/Unit/src/unit/TestIEndpointResolverExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// This source code is dual-licensed under the Apache License, version
// 2.0, and the Mozilla Public License, version 1.1.
//
// The APL v2.0:
//
//---------------------------------------------------------------------------
// Copyright (c) 2007-2016 Pivotal Software, Inc.
//
// 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.
//---------------------------------------------------------------------------
//
// The MPL v1.1:
//
//---------------------------------------------------------------------------
// The contents of this file are subject to the Mozilla Public License
// Version 1.1 (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.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
// the License for the specific language governing rights and
// limitations under the License.
//
// The Original Code is RabbitMQ.
//
// The Initial Developer of the Original Code is Pivotal Software, Inc.
// Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
//---------------------------------------------------------------------------

using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Threading;

namespace RabbitMQ.Client.Unit
{
public class TestEndpointResolver : IEndpointResolver
{
private IEnumerable<AmqpTcpEndpoint> endpoints;
public TestEndpointResolver (IEnumerable<AmqpTcpEndpoint> endpoints)
{
this.endpoints = endpoints;
}

public IEnumerable<AmqpTcpEndpoint> All()
{
return endpoints;
}
}

class TestEndpointException : Exception
{
public TestEndpointException(string message) : base(message)
{
}
}

public class TestIEndpointResolverExtensions
{
[Test]
public void SelectOneShouldReturnDefaultWhenThereAreNoEndpoints()
{
var ep = new TestEndpointResolver(new List<AmqpTcpEndpoint>());
Assert.IsNull(ep.SelectOne<AmqpTcpEndpoint>((x) => null));
}

[Test]
public void SelectOneShouldRaiseThrownExceptionWhenThereAreOnlyInaccessibleEndpoints()
{
var ep = new TestEndpointResolver(new List<AmqpTcpEndpoint> { new AmqpTcpEndpoint()});
Assert.Throws<TestEndpointException>(() => ep.SelectOne<AmqpTcpEndpoint>((x) => { throw new TestEndpointException("bananas"); }));
}

[Test]
public void SelectOneShouldReturnFoundEndpoint()
{
var ep = new TestEndpointResolver(new List<AmqpTcpEndpoint> { new AmqpTcpEndpoint()});
Assert.IsNotNull(ep.SelectOne<AmqpTcpEndpoint>((e) => e));
}
}
}