[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] storm/org/nongnu/storm StormPool.meta
From: |
Benja Fallenstein |
Subject: |
[Gzz-commits] storm/org/nongnu/storm StormPool.meta |
Date: |
Mon, 07 Apr 2003 19:23:02 -0400 |
CVSROOT: /cvsroot/storm
Module name: storm
Changes by: Benja Fallenstein <address@hidden> 03/04/07 19:23:01
Modified files:
org/nongnu/storm: StormPool.meta
Log message:
more tests
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/storm/storm/org/nongnu/storm/StormPool.meta.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
Patches:
Index: storm/org/nongnu/storm/StormPool.meta
diff -u storm/org/nongnu/storm/StormPool.meta:1.2
storm/org/nongnu/storm/StormPool.meta:1.3
--- storm/org/nongnu/storm/StormPool.meta:1.2 Mon Apr 7 16:16:28 2003
+++ storm/org/nongnu/storm/StormPool.meta Mon Apr 7 19:23:01 2003
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2003, Benja Fallenstein
+# Copyright (c) 2003, Anton Feldmann and Benja Fallenstein
#
# This file is part of Gzz.
#
@@ -31,8 +31,13 @@
from org.nongnu.storm.util import CopyUtil
from java.io import *
+from java.util import *
def testNewBlock():
+ """
+ Create a new block in the pool, request it from the pool by ID,
+ check its body (contents) and its Content-Type.
+ """
bos = pool.getBlockOutputStream("text/plain")
assert bos.getContentType() == 'text/plain'
@@ -56,3 +61,138 @@
assert s == "Hallo, Welt!"
assert b.getId().getContentType() == "text/plain"
+
+
+def testAddTwice():
+ """
+ Test adding the same block to a pool twice.
+ """
+
+ bos = pool.getBlockOutputStream("text/plain")
+ bos.close()
+
+ pool.add(bos.getBlock())
+
+
+def testCloseTwice():
+ """
+ Test closing the same BlockOutputStream twice.
+ """
+
+ bos = pool.getBlockOutputStream("text/plain")
+ bos.write(0x01)
+ bos.close()
+ bos.close()
+
+ block = bos.getBlock()
+ block.getId().check(CopyUtil.readBytes(block.getInputStream()));
+ stream = block.getInputStream();
+ assert stream.read() == 0x01
+ assert stream.read() < 0
+ stream.close()
+
+
+def testIdsNotNull():
+ """
+ Assert that getIds() does not return null.
+ This is required of all pools. (They can return
+ the canonical empty set from java.util.Collections
+ at no extra cost, after all...)
+ """
+
+ assert not (pool.getIds() is None)
+ assert pool.getIds().isEmpty()
+
+
+def testAddRemoveId():
+ """
+ Create a new block, check that the ID appears
+ in the pool's getIds() set. Then, delete the block
+ and check that the block disappears.
+
+ NOTE: getIds() is NOT REQUIRED to return all ids in the pool;
+ this is implementation-dependent. Obviously, this method
+ should only be called for pools that guarantee the id to be
+ in getIds().
+ """
+
+ oldIds = HashSet(pool.getIds())
+
+ bos = pool.getBlockOutputStream("text/plain")
+ bos.close();
+
+ newIds = HashSet(pool.getIds())
+
+ assert oldIds != newIds
+ assert newIds.contains(bos.getBlockId())
+
+ pool.delete(bos.getBlock())
+
+ assert not pool.getIds().contains(bos.getBlockId())
+
+
+def testDelete():
+ """
+ Remove a block from the pool.
+ """
+
+ bos = pool.getBlockOutputStream("text/plain")
+ bos.close()
+
+ pool.get(bos.getBlockId())
+
+ pool.delete(bos.getBlock())
+
+ try: pool.get(bos.getBlockId())
+ except FileNotFoundException: pass
+ else: assert 0
+
+
+def testBlockId():
+ """
+ Add a block and check its id.
+ """
+
+ body = 'A' * 1025
+ id = BlockId("urn:x-storm:1.0:text/plain,"
+ "UUHHSQPHQXN5X6EMYK6CD7IJ7BHZTE77."
+ "PZMRYHGY6LTBEH63ZWAHDORHSYTLO4LEFUIKHWY")
+
+ bos = pool.getBlockOutputStream("text/plain")
+ bos.write(body)
+ bos.close()
+
+ id1 = bos.getBlockId()
+ id2 = bos.getBlock().getId()
+
+ assert id == id1 == id2
+
+ bytes = CopyUtil.readBytes(bos.getBlock().getInputStream())
+ id.check(bytes)
+ id1.check(bytes)
+ id2.check(bytes)
+
+
+def testGetNonexistent():
+ """
+ Test that trying to get a nonexistent block
+ gives a FileNotFoundException.
+ """
+
+ badid = BlockId("urn:x-storm:1.0:application/sometype,"
+ "1E88CEE70319F016EEF00B315C0B930C."
+ "ILOPTKERWIPAPSZEPFN953DB7776EAAWGBAGKKE")
+
+ try: pool.get(badid)
+ except FileNotFoundException: pass
+ else: assert 0
+
+
+def testAddBlock():
+ """
+ Test adding a block from a different pool. XXX!!!
+ """
+
+ pass
+
+
- [Gzz-commits] storm/org/nongnu/storm StormPool.meta,
Benja Fallenstein <=