[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/lava gzz/storm/impl/DirPool.java gzz/storm/...
From: |
Benja Fallenstein |
Subject: |
[Gzz-commits] gzz/lava gzz/storm/impl/DirPool.java gzz/storm/... |
Date: |
Thu, 14 Nov 2002 15:43:06 -0500 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Benja Fallenstein <address@hidden> 02/11/14 15:43:05
Modified files:
lava/gzz/storm/impl: DirPool.java TransientPool.java
lava/test/gzz/storm: StormPoolTest.java
lava/test/gzz/storm/impl: DirPool.test TransientPool.test
Log message:
Make adding blocks to a Storm pool tested + work
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/DirPool.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/TransientPool.java.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/StormPoolTest.java.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/impl/DirPool.test.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/impl/TransientPool.test.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
Patches:
Index: gzz/lava/gzz/storm/impl/DirPool.java
diff -u gzz/lava/gzz/storm/impl/DirPool.java:1.4
gzz/lava/gzz/storm/impl/DirPool.java:1.5
--- gzz/lava/gzz/storm/impl/DirPool.java:1.4 Thu Nov 14 15:05:23 2002
+++ gzz/lava/gzz/storm/impl/DirPool.java Thu Nov 14 15:43:05 2002
@@ -109,7 +109,17 @@
public Block get(BlockId id) throws IOException {
return new FileBlock(id);
}
- public void add(Block b) {}
+ public void add(Block b) throws IOException {
+ byte[] bytes = gzz.util.CopyUtil.readBytes(b.getRawInputStream());
+ BlockId id = BlockId.getIdForData(bytes);
+
+ if(!id.equals(b.getId()))
+ throw new IOException("Block with bad id supplied");
+
+ OutputStream os = new FileOutputStream(getFile(id));
+ os.write(bytes);
+ os.close();
+ }
public void delete(Block b) {}
public Set getIds() {
HashSet ids = new HashSet();
Index: gzz/lava/gzz/storm/impl/TransientPool.java
diff -u gzz/lava/gzz/storm/impl/TransientPool.java:1.11
gzz/lava/gzz/storm/impl/TransientPool.java:1.12
--- gzz/lava/gzz/storm/impl/TransientPool.java:1.11 Thu Nov 14 15:05:23 2002
+++ gzz/lava/gzz/storm/impl/TransientPool.java Thu Nov 14 15:43:05 2002
@@ -87,10 +87,30 @@
}
}
- public Block get(BlockId id) {
+ public Block get(BlockId id) throws FileNotFoundException {
+ if(!blocks.keySet().contains(id))
+ throw new FileNotFoundException("No such block: "+id);
+
return (Block)blocks.get(id);
}
- public void add(Block b) {}
+ public void add(Block b) throws IOException {
+ byte[] body = gzz.util.CopyUtil.readBytes(b.getInputStream());
+ byte[] raw = gzz.util.CopyUtil.readBytes(b.getRawInputStream());
+
+ InputStream is = b.getRawInputStream();
+ Header822 header = Headers822.readHeader(is);
+ is.close();
+
+ int headerLength = raw.length - body.length;
+
+ Block block = new TransientBlock(raw, header, headerLength);
+ BlockId id = block.getId();
+
+ if(!id.equals(b.getId()))
+ throw new IOException("Block with bad id supplied");
+
+ blocks.put(block.getId(), block);
+ }
public void delete(Block b) {}
public Set getIds() { return blocks.keySet(); }
public BlockOutputStream getBlockOutputStream(String contentType)
Index: gzz/lava/test/gzz/storm/StormPoolTest.java
diff -u gzz/lava/test/gzz/storm/StormPoolTest.java:1.8
gzz/lava/test/gzz/storm/StormPoolTest.java:1.9
--- gzz/lava/test/gzz/storm/StormPoolTest.java:1.8 Thu Nov 14 15:05:23 2002
+++ gzz/lava/test/gzz/storm/StormPoolTest.java Thu Nov 14 15:43:05 2002
@@ -190,4 +190,78 @@
if(!id.equals(id2))
throw new Error("bos.getBlock().getId() does not match");
}
+
+ /** Test that trying to get a nonexistent block
+ * gives a FileNotFoundException.
+ */
+ public void testGetNonexistent(StormPool pool) throws IOException {
+ final BlockId badid = new BlockId(
+ "storm:block:01E88CEE70319F016EEF00B315C0B930C953DB7776");
+
+ try {
+ pool.get(badid);
+ throw new Error();
+ } catch(FileNotFoundException _) {
+ }
+ }
+
+ /** Test adding a block from a different pool. */
+ public void testAddBlock(StormPool pool) throws IOException {
+ final byte[] bytes =
+ ("Content-Transfer-Encoding: binary\r\n"+
+ "Content-Type: text/plain; charset=UTF-8\r\n"+
+ "Date: Tue, 1 Oct 2002 12:30:30 +0000\r\n"+
+ "X-Injected-By: address@hidden"+
+ "\r\n"+
+ "foo").getBytes("US-ASCII");
+
+ final BlockId id = new BlockId(
+ "storm:block:01E88CEE7CF19F016EEF00B315C0B930C953DB7EF2");
+ final BlockId badid = new BlockId(
+ "storm:block:01E88CEE70319F016EEF00B315C0B930C953DB7776");
+
+ Block orig = new Block() {
+ public BlockId getId() { return id; }
+ public StormPool getPool() { return null; }
+ public Header822 getHeader() { return null; }
+ public InputStream getInputStream() throws IOException {
+ return new
ByteArrayInputStream("foo".getBytes("US-ASCII"));
+ }
+ public InputStream getRawInputStream() {
+ return new ByteArrayInputStream(bytes);
+ }
+ };
+
+ Block badBlock = new Block() {
+ public BlockId getId() { return badid; }
+ public StormPool getPool() { return null; }
+ public Header822 getHeader() { return null; }
+ public InputStream getInputStream() throws IOException {
+ return new
ByteArrayInputStream("foo".getBytes("US-ASCII"));
+ }
+ public InputStream getRawInputStream() {
+ return new ByteArrayInputStream(bytes);
+ }
+ };
+
+ pool.add(orig);
+ Block b = pool.get(id);
+
+ String s = new String(CopyUtil.readBytes(b.getInputStream()));
+ if(!s.equals("foo")) throw new Error();
+ if(!b.getHeader().get("X-injected-by").equals("address@hidden"))
+ throw new Error();
+
+ try {
+ pool.add(badBlock);
+ throw new Error();
+ } catch(IOException e) {
+ }
+
+ try {
+ pool.get(badid);
+ throw new Error();
+ } catch(FileNotFoundException e) {
+ }
+ }
}
Index: gzz/lava/test/gzz/storm/impl/DirPool.test
diff -u gzz/lava/test/gzz/storm/impl/DirPool.test:1.2
gzz/lava/test/gzz/storm/impl/DirPool.test:1.3
--- gzz/lava/test/gzz/storm/impl/DirPool.test:1.2 Fri Nov 8 15:54:55 2002
+++ gzz/lava/test/gzz/storm/impl/DirPool.test Thu Nov 14 15:43:05 2002
@@ -29,6 +29,8 @@
def testIdsNotNull(): s.testIdsNotNull(p)
def testAddId(): s.testAddId(p)
def testBlockId(): s.testBlockId(p)
+def testAddBlock(): s.testAddBlock(p)
+def testGetNonexistent(): s.testGetNonexistent(p)
def tearDown():
gzz.util.TestingUtil.deltree(dir)
Index: gzz/lava/test/gzz/storm/impl/TransientPool.test
diff -u gzz/lava/test/gzz/storm/impl/TransientPool.test:1.4
gzz/lava/test/gzz/storm/impl/TransientPool.test:1.5
--- gzz/lava/test/gzz/storm/impl/TransientPool.test:1.4 Thu Nov 7 16:42:50 2002
+++ gzz/lava/test/gzz/storm/impl/TransientPool.test Thu Nov 14 15:43:05 2002
@@ -28,4 +28,6 @@
def testIdsNotNull(): s.testIdsNotNull(p())
def testAddId(): s.testAddId(p())
def testBlockId(): s.testBlockId(p())
+def testAddBlock(): s.testAddBlock(p())
+def testGetNonexistent(): s.testGetNonexistent(p())