/[storm]/storm/org/nongnu/storm/StormPool.meta
ViewVC logotype

Diff of /storm/org/nongnu/storm/StormPool.meta

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by benja, Mon Apr 7 20:16:28 2003 UTC revision 1.3 by benja, Mon Apr 7 23:23:01 2003 UTC
# Line 1  Line 1 
1  #  #
2  # Copyright (c) 2003, Benja Fallenstein  # Copyright (c) 2003, Anton Feldmann and Benja Fallenstein
3  #  #
4  # This file is part of Gzz.  # This file is part of Gzz.
5  #  #
# Line 31  from org.nongnu.storm import * Line 31  from org.nongnu.storm import *
31  from org.nongnu.storm.util import CopyUtil  from org.nongnu.storm.util import CopyUtil
32    
33  from java.io import *  from java.io import *
34    from java.util import *
35    
36  def testNewBlock():  def testNewBlock():
37        """
38        Create a new block in the pool, request it from the pool by ID,
39        check its body (contents) and its Content-Type.
40        """
41      bos = pool.getBlockOutputStream("text/plain")      bos = pool.getBlockOutputStream("text/plain")
42    
43      assert bos.getContentType() == 'text/plain'      assert bos.getContentType() == 'text/plain'
# Line 56  def testNewBlock(): Line 61  def testNewBlock():
61      assert s == "Hallo, Welt!"      assert s == "Hallo, Welt!"
62    
63      assert b.getId().getContentType() == "text/plain"      assert b.getId().getContentType() == "text/plain"
64    
65    
66    def testAddTwice():
67        """
68        Test adding the same block to a pool twice.
69        """
70    
71        bos = pool.getBlockOutputStream("text/plain")
72        bos.close()
73    
74        pool.add(bos.getBlock())
75    
76    
77    def testCloseTwice():
78        """
79        Test closing the same BlockOutputStream twice.
80        """
81    
82        bos = pool.getBlockOutputStream("text/plain")
83        bos.write(0x01)
84        bos.close()
85        bos.close()
86        
87        block = bos.getBlock()
88        block.getId().check(CopyUtil.readBytes(block.getInputStream()));
89        stream = block.getInputStream();
90        assert stream.read() == 0x01
91        assert stream.read() < 0
92        stream.close()
93    
94    
95    def testIdsNotNull():
96        """
97        Assert that getIds() does not return null.
98        This is required of all pools. (They can return
99        the canonical empty set from java.util.Collections
100        at no extra cost, after all...)
101        """
102        
103        assert not (pool.getIds() is None)
104        assert pool.getIds().isEmpty()
105    
106    
107    def testAddRemoveId():
108        """
109        Create a new block, check that the ID appears
110        in the pool's getIds() set. Then, delete the block
111        and check that the block disappears.
112    
113        NOTE: getIds() is NOT REQUIRED to return all ids in the pool;
114        this is implementation-dependent. Obviously, this method
115        should only be called for pools that guarantee the id to be
116        in getIds().
117        """
118    
119        oldIds = HashSet(pool.getIds())
120    
121        bos = pool.getBlockOutputStream("text/plain")
122        bos.close();
123            
124        newIds = HashSet(pool.getIds())
125    
126        assert oldIds != newIds
127        assert newIds.contains(bos.getBlockId())
128        
129        pool.delete(bos.getBlock())
130    
131        assert not pool.getIds().contains(bos.getBlockId())
132    
133    
134    def testDelete():
135        """
136        Remove a block from the pool.
137        """
138    
139        bos = pool.getBlockOutputStream("text/plain")
140        bos.close()
141        
142        pool.get(bos.getBlockId())
143        
144        pool.delete(bos.getBlock())
145        
146        try: pool.get(bos.getBlockId())
147        except FileNotFoundException: pass
148        else: assert 0
149        
150    
151    def testBlockId():
152        """
153        Add a block and check its id.
154        """
155    
156        body = 'A' * 1025
157        id = BlockId("urn:x-storm:1.0:text/plain,"
158                     "UUHHSQPHQXN5X6EMYK6CD7IJ7BHZTE77."
159                     "PZMRYHGY6LTBEH63ZWAHDORHSYTLO4LEFUIKHWY")
160    
161        bos = pool.getBlockOutputStream("text/plain")
162        bos.write(body)
163        bos.close()
164    
165        id1 = bos.getBlockId()
166        id2 = bos.getBlock().getId()
167    
168        assert id == id1 == id2
169    
170        bytes = CopyUtil.readBytes(bos.getBlock().getInputStream())
171        id.check(bytes)
172        id1.check(bytes)
173        id2.check(bytes)
174    
175    
176    def testGetNonexistent():
177        """
178        Test that trying to get a nonexistent block
179        gives a FileNotFoundException.
180        """
181    
182        badid = BlockId("urn:x-storm:1.0:application/sometype,"
183                        "1E88CEE70319F016EEF00B315C0B930C."
184                        "ILOPTKERWIPAPSZEPFN953DB7776EAAWGBAGKKE")
185    
186        try: pool.get(badid)
187        except FileNotFoundException: pass
188        else: assert 0
189    
190    
191    def testAddBlock():
192        """
193        Test adding a block from a different pool. XXX!!!
194        """
195    
196        pass
197    
198    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26