Ejemplo n.º 1
0
        private void TransactionUpdate()
        {
            byte[] transactionIdBytes = m_serverSocket.Receive();

            int transactionId = BitConverter.ToInt32(transactionIdBytes, 0);

            byte[] documentIdBytes = m_serverSocket.Receive();

            DocumentId documentId = new DocumentId(documentIdBytes);

            byte[] blob = m_serverSocket.Receive();

            try
            {
                m_db.TransactionUpdate(transactionId, documentId, blob);

                // sending success
                m_serverSocket.Send(Protocol.Success);
            }
            catch (TransactionNotExistException ex)
            {
                m_serverSocket.SendMore(Protocol.Failed).Send("Transaction doesn't exist");
            }
            catch (DocumentLockedException)
            {
                m_serverSocket.SendMore(Protocol.Failed).Send("Document locked by another transaction");
            }
        }
Ejemplo n.º 2
0
        public void ReadDocumentUpdatedByTransaction()
        {
            DocumentId id1 = new DocumentId("1");

            m_db.Update(id1, new byte[1] {
                0
            });

            int transactionId = m_db.StartTransaction();

            m_db.TransactionUpdate(transactionId, id1, new byte[1] {
                1
            });

            byte[] blob = m_db.TransactionGet(transactionId, id1);
            Assert.AreEqual(1, blob[0]);

            // reading without transaction should return uncommitted document
            blob = m_db.Get(id1);
            Assert.AreEqual(0, blob[0]);

            m_db.CommitTransaction(transactionId);

            // reading the object agian after the transaction committed making sure we are reading the new committed document
            blob = m_db.Get(id1);
            Assert.AreEqual(1, blob[0]);
        }