summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2009-11-26 20:16:30 -0800
committerShawn O. Pearce <spearce@spearce.org>2010-01-12 11:56:55 -0800
commit3f8fdc03253264cae2172c168b5c959ea09a4c9d (patch)
tree5a1e46a1a78cdd3c52121e2a594b847933138bcb /org.eclipse.jgit.test
parenta22b8f5fac9dd9b99333d709e6ef8f09ca6cd0d7 (diff)
downloadjgit-3f8fdc03253264cae2172c168b5c959ea09a4c9d.tar.gz
jgit-3f8fdc03253264cae2172c168b5c959ea09a4c9d.zip
Refactor TemporaryBuffer to support reuse in other contexts
Later we are going to add support for smart HTTP, which requires us to buffer at least some of the request created by a client before we ship it to the server. For many requests, we can fit it completely into a 1 MiB buffer, but if it doesn't we can drop back to using the chunked transfer encoding to send an unknown stream length. Rather than recoding the block based memory buffer, we refactor the local file overflow strategy into a subclass, allowing the HTTP client code to replace this portion of the logic with its own approach to start the chunked encoding request. Change-Id: Iac61ea1017b14e0ad3c4425efc3d75718b71bb8e Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java38
2 files changed, 27 insertions, 15 deletions
diff --git a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java
index 60d3853d85..ae9fb0ef50 100644
--- a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java
+++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, Google Inc.
+ * Copyright (C) 2008-2009, Google Inc.
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -211,7 +211,7 @@ public class EGitPatchHistoryTest extends TestCase {
buf.destroy();
}
commitId = line.substring("commit ".length());
- buf = new TemporaryBuffer();
+ buf = new TemporaryBuffer.LocalFile();
} else if (buf != null) {
buf.write(line.getBytes("ISO-8859-1"));
buf.write('\n');
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java
index e1f802b3d1..ea1fd7313d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, Google Inc.
+ * Copyright (C) 2008-2009, Google Inc.
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -54,7 +54,7 @@ import junit.framework.TestCase;
public class TemporaryBufferTest extends TestCase {
public void testEmpty() throws IOException {
- final TemporaryBuffer b = new TemporaryBuffer();
+ final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
try {
b.close();
assertEquals(0, b.length());
@@ -67,7 +67,7 @@ public class TemporaryBufferTest extends TestCase {
}
public void testOneByte() throws IOException {
- final TemporaryBuffer b = new TemporaryBuffer();
+ final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final byte test = (byte) new TestRng(getName()).nextInt();
try {
b.write(test);
@@ -93,7 +93,7 @@ public class TemporaryBufferTest extends TestCase {
}
public void testOneBlock_BulkWrite() throws IOException {
- final TemporaryBuffer b = new TemporaryBuffer();
+ final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ);
try {
@@ -123,7 +123,7 @@ public class TemporaryBufferTest extends TestCase {
}
public void testOneBlockAndHalf_BulkWrite() throws IOException {
- final TemporaryBuffer b = new TemporaryBuffer();
+ final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
try {
@@ -153,7 +153,7 @@ public class TemporaryBufferTest extends TestCase {
}
public void testOneBlockAndHalf_SingleWrite() throws IOException {
- final TemporaryBuffer b = new TemporaryBuffer();
+ final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
try {
@@ -181,7 +181,7 @@ public class TemporaryBufferTest extends TestCase {
}
public void testOneBlockAndHalf_Copy() throws IOException {
- final TemporaryBuffer b = new TemporaryBuffer();
+ final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
try {
@@ -210,7 +210,7 @@ public class TemporaryBufferTest extends TestCase {
}
public void testLarge_SingleWrite() throws IOException {
- final TemporaryBuffer b = new TemporaryBuffer();
+ final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3);
try {
@@ -237,7 +237,7 @@ public class TemporaryBufferTest extends TestCase {
}
public void testInCoreLimit_SwitchOnAppendByte() throws IOException {
- final TemporaryBuffer b = new TemporaryBuffer();
+ final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT + 1);
try {
@@ -265,7 +265,7 @@ public class TemporaryBufferTest extends TestCase {
}
public void testInCoreLimit_SwitchBeforeAppendByte() throws IOException {
- final TemporaryBuffer b = new TemporaryBuffer();
+ final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3);
try {
@@ -293,7 +293,7 @@ public class TemporaryBufferTest extends TestCase {
}
public void testInCoreLimit_SwitchOnCopy() throws IOException {
- final TemporaryBuffer b = new TemporaryBuffer();
+ final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2);
try {
@@ -324,7 +324,7 @@ public class TemporaryBufferTest extends TestCase {
}
public void testDestroyWhileOpen() throws IOException {
- final TemporaryBuffer b = new TemporaryBuffer();
+ final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
try {
b.write(new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2));
@@ -334,7 +334,7 @@ public class TemporaryBufferTest extends TestCase {
}
public void testRandomWrites() throws IOException {
- final TemporaryBuffer b = new TemporaryBuffer();
+ final TemporaryBuffer b = new TemporaryBuffer.LocalFile();
final TestRng rng = new TestRng(getName());
final int max = TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2;
final byte[] expect = new byte[max];
@@ -379,4 +379,16 @@ public class TemporaryBufferTest extends TestCase {
}
}
+ public void testHeap() throws IOException {
+ final TemporaryBuffer b = new TemporaryBuffer.Heap(2 * 8 * 1024);
+ final byte[] r = new byte[8 * 1024];
+ b.write(r);
+ b.write(r);
+ try {
+ b.write(1);
+ fail("accepted too many bytes of data");
+ } catch (IOException e) {
+ assertEquals("In-memory buffer limit exceeded", e.getMessage());
+ }
+ }
}