You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by db...@apache.org on 2012/06/07 04:40:37 UTC
git commit: fix OOM with ReadMessageTest.testNoCommitLog patch by
dbrosius reviewed by ymorishita for (CASSANDRA-4312)
Updated Branches:
refs/heads/trunk 355fcf53a -> de6dba733
fix OOM with ReadMessageTest.testNoCommitLog
patch by dbrosius reviewed by ymorishita for (CASSANDRA-4312)
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/de6dba73
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/de6dba73
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/de6dba73
Branch: refs/heads/trunk
Commit: de6dba73352b8406452bd2b0ab792e9af817c901
Parents: 355fcf5
Author: Dave Brosius <db...@apache.org>
Authored: Wed Jun 6 22:38:20 2012 -0400
Committer: Dave Brosius <db...@apache.org>
Committed: Wed Jun 6 22:38:20 2012 -0400
----------------------------------------------------------------------
.../org/apache/cassandra/db/ReadMessageTest.java | 72 ++++++++++++--
1 files changed, 61 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/de6dba73/test/unit/org/apache/cassandra/db/ReadMessageTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/ReadMessageTest.java b/test/unit/org/apache/cassandra/db/ReadMessageTest.java
index 2c7f158..4b56b96 100644
--- a/test/unit/org/apache/cassandra/db/ReadMessageTest.java
+++ b/test/unit/org/apache/cassandra/db/ReadMessageTest.java
@@ -115,25 +115,75 @@ public class ReadMessageTest extends SchemaLoader
File commitLogDir = new File(DatabaseDescriptor.getCommitLogLocation());
+ byte[] commitBytes = "commit".getBytes("UTF-8");
+
for(String filename : commitLogDir.list())
{
- BufferedReader f = new BufferedReader(new FileReader(commitLogDir.getAbsolutePath()+File.separator+filename));
-
- String line = null;
- while( (line = f.readLine()) != null)
+ BufferedInputStream is = null;
+ try
{
- if(line.contains("commit1"))
- commitLogMessageFound = true;
-
- if(line.contains("commit2"))
- noCommitLogMessageFound = true;
+ is = new BufferedInputStream(new FileInputStream(commitLogDir.getAbsolutePath()+File.separator+filename));
+
+ if (!isEmptyCommitLog(is))
+ {
+ while (findPatternInStream(commitBytes, is))
+ {
+ char c = (char)is.read();
+
+ if (c == '1')
+ commitLogMessageFound = true;
+ else if (c == '2')
+ noCommitLogMessageFound = true;
+ }
+ }
+ }
+ finally
+ {
+ if (is != null)
+ is.close();
}
-
- f.close();
}
assertTrue(commitLogMessageFound);
assertFalse(noCommitLogMessageFound);
}
+ private boolean isEmptyCommitLog(BufferedInputStream is) throws IOException
+ {
+ byte[] lookahead = new byte[100];
+
+ is.mark(100);
+ is.read(lookahead);
+ is.reset();
+
+ for (int i = 0; i < 100; i++)
+ {
+ if (lookahead[i] != 0)
+ return false;
+ }
+
+ return true;
+ }
+
+ private boolean findPatternInStream(byte[] pattern, InputStream is) throws IOException
+ {
+ int patternOffset = 0;
+
+ int b = is.read();
+ while (b != -1)
+ {
+ if (pattern[patternOffset] == ((byte) b))
+ {
+ patternOffset++;
+ if (patternOffset == pattern.length)
+ return true;
+ }
+ else
+ patternOffset = 0;
+
+ b = is.read();
+ }
+
+ return false;
+ }
}