Exemplo n.º 1
0
 internal ResultResponse(ResponseFrame frame)
     : base(frame)
 {
     Kind = (ResultResponseKind) BEBinaryReader.ReadInt32();
     switch (Kind)
     {
         case ResultResponseKind.Void:
             Output = new OutputVoid(TraceID);
             break;
         case ResultResponseKind.Rows:
             Output = new OutputRows(BEBinaryReader, frame.RawStream is BufferedProtoBuf, TraceID);
             break;
         case ResultResponseKind.SetKeyspace:
             Output = new OutputSetKeyspace(BEBinaryReader.ReadString());
             break;
         case ResultResponseKind.Prepared:
             Output = new OutputPrepared(BEBinaryReader);
             break;
         case ResultResponseKind.SchemaChange:
             Output = new OutputSchemaChange(BEBinaryReader, TraceID);
             break;
         default:
             throw new DriverInternalError("Unknown Event Type");
     }
 }
Exemplo n.º 2
0
        internal EventResponse(ResponseFrame frame)
            : base(frame)
        {
            string eventTypeString = BeBinaryReader.ReadString();
            if (eventTypeString == "TOPOLOGY_CHANGE")
            {
                var ce = new TopologyChangeEventArgs();
                ce.What = BeBinaryReader.ReadString() == "NEW_NODE"
                              ? TopologyChangeEventArgs.Reason.NewNode
                              : TopologyChangeEventArgs.Reason.RemovedNode;
                ce.Address = BeBinaryReader.ReadInet();
                CassandraEventArgs = ce;
                return;
            }
            if (eventTypeString == "STATUS_CHANGE")
            {
                var ce = new StatusChangeEventArgs();
                ce.What = BeBinaryReader.ReadString() == "UP"
                              ? StatusChangeEventArgs.Reason.Up
                              : StatusChangeEventArgs.Reason.Down;
                ce.Address = BeBinaryReader.ReadInet();
                CassandraEventArgs = ce;
                return;
            }
            if (eventTypeString == "SCHEMA_CHANGE")
            {
                HandleSchemaChange(frame);
                return;
            }

            var ex = new DriverInternalError("Unknown Event Type");
            _logger.Error(ex);
            throw ex;
        }
Exemplo n.º 3
0
 internal ErrorResponse(ResponseFrame frame) 
     : base(frame)
 {
     int errorCode = BeBinaryReader.ReadInt32();
     string message = BeBinaryReader.ReadString();
     Output = OutputError.CreateOutputError(errorCode, message, BeBinaryReader);
 }
Exemplo n.º 4
0
 internal ErrorResponse(ResponseFrame frame)
     : base(frame)
 {
     var ctype = (CassandraErrorType) BEBinaryReader.ReadInt32();
     var message = BEBinaryReader.ReadString();
     Output = OutputError.CreateOutputError(ctype, message, BEBinaryReader);
 }
Exemplo n.º 5
0
        public ResponseFrame MakeFrame(IProtoBuf stream)
        {
            var bodyLen = TypeInterpreter.BytesToInt32(Len, 0);

            if (MaxFrameSize - 8 < bodyLen) throw new DriverInternalError("Frame length mismatch");

            var frame = new ResponseFrame() { FrameHeader = this, RawStream = stream };
            return frame;
        }
        public void Ctor_NoFlags_TraceIdIsNull()
        {
            // Arrange
            var frame = new ResponseFrame(new FrameHeader(), new MemoryStream());

            // Act
            var uut = new AbstractResponse(frame);

            // Assert
            Assert.IsNull(uut.TraceId);
        }
        public void Ctor_NoFlags_BodyStreamPositionIsZero()
        {
            // Arrange
            var frame = new ResponseFrame(new FrameHeader(), new MemoryStream(new byte[] { 1 }));

            // Act
            new AbstractResponse(frame);

            // Assert
            Assert.AreEqual(0, frame.Body.Position);
        }
        public void Ctor_TraceFlagSet_BytesReadFromFrame()
        {
            // Arrange
            var header = new FrameHeader { Flags = FrameHeader.HeaderFlag.Tracing };
            var body = new MemoryStream(new byte[20]);
            var frame = new ResponseFrame(header, body);

            // Act
            new AbstractResponse(frame);

            // Assert
            Assert.AreEqual(16, body.Position);
            Assert.AreEqual(20, body.Length);
        }
 public void HandleSchemaChange(ResponseFrame frame)
 {
     var ce = new SchemaChangeEventArgs();
     CassandraEventArgs = ce;
     var changeTypeText = BeBinaryReader.ReadString();
     SchemaChangeEventArgs.Reason changeType;
     switch (changeTypeText)
     {
         case "UPDATED":
             changeType = SchemaChangeEventArgs.Reason.Updated;
             break;
         case "DROPPED":
             changeType = SchemaChangeEventArgs.Reason.Dropped;
             break;
         default:
             changeType = SchemaChangeEventArgs.Reason.Created;
             break;
     }
     ce.What = changeType;
     if (frame.Header.Version < 3)
     {
         //protocol v1 and v2: <change_type><keyspace><table>
         ce.Keyspace = BeBinaryReader.ReadString();
         ce.Table = BeBinaryReader.ReadString();
         return;
     }
     //protocol v3+: <change_type><target><options>
     var target = BeBinaryReader.ReadString();
     ce.Keyspace = BeBinaryReader.ReadString();
     switch (target)
     {
         case "TABLE":
             ce.Table = BeBinaryReader.ReadString();
             break;
         case "TYPE":
             ce.Type = BeBinaryReader.ReadString();
             break;
         case "FUNCTION":
             ce.FunctionName = BeBinaryReader.ReadString();
             ce.Signature = BeBinaryReader.ReadStringList();
             break;
         case "AGGREGATE":
             ce.AggregateName = BeBinaryReader.ReadString();
             ce.Signature = BeBinaryReader.ReadStringList();
             break;
     }
 }
        public void Ctor_TraceFlagSet_TraceIdIsSet()
        {
            // Arrange
            var header = new FrameHeader {Flags = FrameHeader.HeaderFlag.Tracing};
            var rnd = new Random();
            var buffer = new byte[16];
            rnd.NextBytes(buffer);
            var expected = new Guid(TypeCodec.GuidShuffle(buffer));
            var body = new MemoryStream(buffer);
            var frame = new ResponseFrame(header, body);

            // Act
            var uut = new AbstractResponse(frame);

            // Assert
            Assert.AreEqual(expected, uut.TraceId);
        }
Exemplo n.º 11
0
        internal EventResponse(ResponseFrame frame)
            : base(frame)
        {
            var eventTypeString = BEBinaryReader.ReadString();
            if (eventTypeString == "TOPOLOGY_CHANGE")
            {
                var ce = new TopopogyChangeEventArgs();
                ce.What = BEBinaryReader.ReadString() == "NEW_NODE"
                              ? TopopogyChangeEventArgs.Reason.NewNode
                              : TopopogyChangeEventArgs.Reason.RemovedNode;
                ce.Address = BEBinaryReader.ReadInet().Address;
                CassandraEventArgs = ce;
                return;
            }
            else if (eventTypeString == "STATUS_CHANGE")
            {
                var ce = new StatusChangeEventArgs();
                ce.What = BEBinaryReader.ReadString() == "UP"
                              ? StatusChangeEventArgs.Reason.Up
                              : StatusChangeEventArgs.Reason.Down;
                ce.Address = BEBinaryReader.ReadInet().Address;
                CassandraEventArgs = ce;
                return;
            }
            else if (eventTypeString == "SCHEMA_CHANGE")
            {
                var ce = new SchemaChangeEventArgs();
                var m = BEBinaryReader.ReadString();
                ce.What = m == "CREATED"
                              ? SchemaChangeEventArgs.Reason.Created
                              : (m == "UPDATED"
                                     ? SchemaChangeEventArgs.Reason.Updated
                                     : SchemaChangeEventArgs.Reason.Dropped);
                ce.Keyspace = BEBinaryReader.ReadString();
                ce.Table = BEBinaryReader.ReadString();
                CassandraEventArgs = ce;
                return;
            }

            var ex = new DriverInternalError("Unknown Event Type");
            _logger.Error(ex);
            throw ex;
        }
Exemplo n.º 12
0
 public void HandleSchemaChange(ResponseFrame frame)
 {
     var ce = new SchemaChangeEventArgs();
     string m = BeBinaryReader.ReadString();
     ce.What = m == "CREATED"
                   ? SchemaChangeEventArgs.Reason.Created
                   : (m == "UPDATED"
                          ? SchemaChangeEventArgs.Reason.Updated
                          : SchemaChangeEventArgs.Reason.Dropped);
     if (frame.Header.Version < 3)
     {
         //protocol v1 and v2: <change_type><keyspace><table>
         ce.Keyspace = BeBinaryReader.ReadString();
         ce.Table = BeBinaryReader.ReadString();
     }
     else
     {
         //protocol v3: <change_type><target><options>
         var target = BeBinaryReader.ReadString();
         switch (target)
         {
             case "KEYSPACE":
                 ce.Keyspace = BeBinaryReader.ReadString();
                 break;
             case "TABLE":
                 ce.Keyspace = BeBinaryReader.ReadString();
                 ce.Table = BeBinaryReader.ReadString();
                 break;
             case "TYPE":
                 ce.Keyspace = BeBinaryReader.ReadString();
                 ce.Type = BeBinaryReader.ReadString();
                 break;
         }
     }
     CassandraEventArgs = ce;
 }
Exemplo n.º 13
0
 internal static SupportedResponse Create(ResponseFrame frame)
 {
     return new SupportedResponse(frame);
 }
Exemplo n.º 14
0
 internal static ErrorResponse Create(ResponseFrame frame)
 {
     return new ErrorResponse(frame);
 }
Exemplo n.º 15
0
 internal AuthChallengeResponse(ResponseFrame frame)
     : base(frame)
 {
     Token = BeBinaryReader.ReadBytes();
 }
Exemplo n.º 16
0
 internal static EventResponse Create(ResponseFrame frame)
 {
     return new EventResponse(frame);
 }
Exemplo n.º 17
0
 internal static ResultResponse Create(ResponseFrame frame)
 {
     return new ResultResponse(frame);
 }
Exemplo n.º 18
0
 internal static AuthChallengeResponse Create(ResponseFrame frame)
 {
     return new AuthChallengeResponse(frame);
 }
Exemplo n.º 19
0
 internal ReadyResponse(ResponseFrame frame)
     : base(frame)
 {
 }
Exemplo n.º 20
0
 public static IdentifyResponse ParseWithFrame(ResponseFrame frame)
 {
     return(JsonConvert.DeserializeObject <IdentifyResponse>(frame.Message, Settings));
 }
Exemplo n.º 21
0
 internal AuthenticateResponse(ResponseFrame frame) : base(frame)
 {
     Authenticator = BeBinaryReader.ReadString();
 }
Exemplo n.º 22
0
 internal SupportedResponse(ResponseFrame frame)
     : base(frame)
 {
     Output = new OutputOptions(BEBinaryReader);
 }
Exemplo n.º 23
0
 internal AuthSuccessResponse(ResponseFrame frame)
     : base(frame)
 {
     Token = BeBinaryReader.ReadBytes();
 }
Exemplo n.º 24
0
 internal static AuthSuccessResponse Create(ResponseFrame frame)
 {
     return new AuthSuccessResponse(frame);
 }
Exemplo n.º 25
0
 internal static AuthenticateResponse Create(ResponseFrame frame)
 {
     return new AuthenticateResponse(frame);
 }
Exemplo n.º 26
0
 internal static EventResponse Create(ResponseFrame frame)
 {
     return(new EventResponse(frame));
 }