示例#1
0
        public void ToStringPrintsDataNeeded()
        {
            Fixture fixture         = new Fixture();
            byte    protocolVersion = fixture.Create <byte>();
            string  contextMessage  = fixture.Create <string>();

            UnsupportedProtocolVersionException exception = new UnsupportedProtocolVersionException(new QueueContextMock(contextMessage), protocolVersion);
            string exceptionToStringResult = exception.ToString();

            Assert.IsTrue(exceptionToStringResult.Contains(protocolVersion.ToString()));
            Assert.IsTrue(exceptionToStringResult.Contains(contextMessage));
        }
示例#2
0
        public async Task <IConnection> ChangeProtocolVersion(
            Configuration config,
            ISerializerManager serializer,
            ProtocolVersion nextVersion,
            IConnection previousConnection,
            UnsupportedProtocolVersionException ex = null,
            ProtocolVersion?previousVersion        = null)
        {
            if (!nextVersion.IsSupported() || nextVersion == previousVersion)
            {
                nextVersion = nextVersion.GetLowerSupported();
            }

            if (nextVersion == 0)
            {
                if (ex != null)
                {
                    // We have downgraded the version until is 0 and none of those are supported
                    throw ex;
                }

                // There was no exception leading to the downgrade, signal internal error
                throw new DriverInternalError("Connection was unable to STARTUP using protocol version 0");
            }

            ControlConnection.Logger.Info(ex != null
                ? $"{ex.Message}, trying with version {nextVersion:D}"
                : $"Changing protocol version to {nextVersion:D}");

            serializer.ChangeProtocolVersion(nextVersion);

            previousConnection.Dispose();

            var c = config.ConnectionFactory.CreateUnobserved(
                serializer.GetCurrentSerializer(),
                previousConnection.EndPoint,
                config);

            try
            {
                await c.Open().ConfigureAwait(false);

                return(c);
            }
            catch
            {
                c.Dispose();
                throw;
            }
        }
 public Task <IConnection> ChangeProtocolVersion(Configuration config, ISerializerManager serializer, ProtocolVersion nextVersion, IConnection previousConnection,
                                                 UnsupportedProtocolVersionException ex = null, ProtocolVersion?previousVersion = null)
 {
     return(Task.FromResult(previousConnection));
 }