From: <tho...@us...> - 2013-12-16 18:27:47
|
Revision: 7663 http://bigdata.svn.sourceforge.net/bigdata/?rev=7663&view=rev Author: thompsonbry Date: 2013-12-16 18:27:40 +0000 (Mon, 16 Dec 2013) Log Message: ----------- bug fix for HASendState.getMarker(). It was not including the version (2 bytes). Modified Paths: -------------- branches/MGC_1_3_0/bigdata/src/java/com/bigdata/ha/msg/HASendState.java branches/MGC_1_3_0/bigdata/src/test/com/bigdata/ha/msg/TestAll.java Added Paths: ----------- branches/MGC_1_3_0/bigdata/src/test/com/bigdata/ha/msg/TestHASendState.java Modified: branches/MGC_1_3_0/bigdata/src/java/com/bigdata/ha/msg/HASendState.java =================================================================== --- branches/MGC_1_3_0/bigdata/src/java/com/bigdata/ha/msg/HASendState.java 2013-12-16 18:09:07 UTC (rev 7662) +++ branches/MGC_1_3_0/bigdata/src/java/com/bigdata/ha/msg/HASendState.java 2013-12-16 18:27:40 UTC (rev 7663) @@ -1,6 +1,8 @@ package com.bigdata.ha.msg; +import java.io.ByteArrayInputStream; import java.io.DataInput; +import java.io.DataInputStream; import java.io.DataOutput; import java.io.Externalizable; import java.io.IOException; @@ -8,7 +10,6 @@ import java.io.ObjectOutput; import java.util.UUID; -import com.bigdata.io.DataInputBuffer; import com.bigdata.io.DataOutputBuffer; import com.bigdata.rawstore.Bytes; @@ -87,8 +88,13 @@ @Override public byte[] getMarker() { - final byte[] a = new byte[MAGIC_SIZE + currentVersionLen]; + final int len = MAGIC_SIZE + currentVersionLen; +// final ByteArrayOutputStream baos = new ByteArrayOutputStream(len); +// +// final DataOutputStream dob = new DataOutputStream(baos); + final byte[] a = new byte[len]; + final DataOutputBuffer dob = new DataOutputBuffer(0/* len */, a); try { @@ -97,14 +103,17 @@ writeExternal2(dob); + dob.flush(); + +// return baos.toByteArray(); + return a; + } catch (IOException e) { throw new RuntimeException(e); } - return a; - } @Override @@ -150,6 +159,7 @@ private static final transient short VERSION0 = 0x0; private static final transient int VERSION0_LEN = // + Bytes.SIZEOF_SHORT + // version Bytes.SIZEOF_LONG + // messageId Bytes.SIZEOF_UUID + // originalSenderId Bytes.SIZEOF_UUID + // senderId @@ -205,24 +215,24 @@ * <code>null</code>. */ static public IHASendState decode(final byte[] a) throws IOException { - return null; -// if (a == null) -// return null; -// -// final HASendState tmp = new HASendState(); -// -// final DataInputBuffer dis = new DataInputBuffer(a); -// -// final long magic = dis.readLong(); -// -// if (magic != MAGIC) -// throw new IOException("Bad magic: expected=" + MAGIC + ", actual=" -// + magic); -// -// tmp.readExternal2(dis); -// -// return tmp; + + if (a == null) + return null; + + final HASendState tmp = new HASendState(); + final DataInputStream dis = new DataInputStream(new ByteArrayInputStream(a)); + + final long magic = dis.readLong(); + + if (magic != MAGIC) + throw new IOException("Bad magic: expected=" + MAGIC + ", actual=" + + magic); + + tmp.readExternal2(dis); + + return tmp; + } @Override Modified: branches/MGC_1_3_0/bigdata/src/test/com/bigdata/ha/msg/TestAll.java =================================================================== --- branches/MGC_1_3_0/bigdata/src/test/com/bigdata/ha/msg/TestAll.java 2013-12-16 18:09:07 UTC (rev 7662) +++ branches/MGC_1_3_0/bigdata/src/test/com/bigdata/ha/msg/TestAll.java 2013-12-16 18:27:40 UTC (rev 7663) @@ -62,7 +62,9 @@ final TestSuite suite = new TestSuite("HA messages"); suite.addTestSuite(TestHAWriteMessage.class); - + + suite.addTestSuite(TestHASendState.class); + return suite; } Added: branches/MGC_1_3_0/bigdata/src/test/com/bigdata/ha/msg/TestHASendState.java =================================================================== --- branches/MGC_1_3_0/bigdata/src/test/com/bigdata/ha/msg/TestHASendState.java (rev 0) +++ branches/MGC_1_3_0/bigdata/src/test/com/bigdata/ha/msg/TestHASendState.java 2013-12-16 18:27:40 UTC (rev 7663) @@ -0,0 +1,80 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2007. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +package com.bigdata.ha.msg; + +import java.io.IOException; +import java.util.UUID; + +import com.bigdata.io.SerializerUtil; + +import junit.framework.TestCase2; + +public class TestHASendState extends TestCase2 { + + public TestHASendState() { + } + + public TestHASendState(String name) { + super(name); + } + + public void test_roundTrip() throws IOException { + + final long messageId = 5; + final UUID originalSenderUUID = UUID.randomUUID(); + final UUID senderId = UUID.randomUUID(); + final long quorumToken = 12; + final int replicationFactor = 3; + + final HASendState expected = new HASendState(messageId, + originalSenderUUID, senderId, quorumToken, replicationFactor); + + final byte[] b = SerializerUtil.serialize(expected); + + final HASendState actual = (HASendState) SerializerUtil.deserialize(b); + + assertEquals(expected, actual); + + } + + public void test_getMarker_decode() throws IOException { + + final long messageId = 5; + final UUID originalSenderUUID = UUID.randomUUID(); + final UUID senderId = UUID.randomUUID(); + final long quorumToken = 12; + final int replicationFactor = 3; + + final HASendState expected = new HASendState(messageId, + originalSenderUUID, senderId, quorumToken, replicationFactor); + + final byte[] b = expected.getMarker(); + + final HASendState actual = (HASendState) HASendState.decode(b); + + assertEquals(expected, actual); + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |