gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/lava gzz/storm/util/DiffBlock.java gzz/stor...


From: Benja Fallenstein
Subject: [Gzz-commits] gzz/lava gzz/storm/util/DiffBlock.java gzz/stor...
Date: Sat, 18 Jan 2003 17:09:40 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Benja Fallenstein <address@hidden>      03/01/18 17:09:40

Modified files:
        lava/gzz/storm/util: DiffBlock.java DiffIndexType.java 
        lava/test/gzz/storm/util: DiffIndexType.test 
                                  StormFilerBlock.test 

Log message:
        more

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/util/DiffBlock.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/util/DiffIndexType.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/util/DiffIndexType.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/util/StormFilerBlock.test.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gzz/lava/gzz/storm/util/DiffBlock.java
diff -u gzz/lava/gzz/storm/util/DiffBlock.java:1.2 
gzz/lava/gzz/storm/util/DiffBlock.java:1.3
--- gzz/lava/gzz/storm/util/DiffBlock.java:1.2  Sat Jan 18 12:37:25 2003
+++ gzz/lava/gzz/storm/util/DiffBlock.java      Sat Jan 18 17:09:39 2003
@@ -22,6 +22,24 @@
        this.headerTo = headerTo;
     }
 
+    public DiffBlock(Block block, VersionFormat format) throws IOException {
+       super(block.getHeader(), format);
+
+       InputStream in = block.getInputStream();
+       this.headerFrom = Headers822.readHeader(in);
+       this.headerTo = Headers822.readHeader(in);
+       this.diff = format.readDiff(in);
+       in.close();
+    }
+
+    public BlockId getFromId() throws IOException {
+       return BlockId.getMediaserverId(header.get("X-Gzz-Diff-From"));
+    }
+
+    public BlockId getToId() throws IOException {
+       return BlockId.getMediaserverId(header.get("X-Gzz-Diff-To"));
+    }
+
     public void writeTo(OutputStream out) throws IOException {
        header.writeTo(out);
        headerFrom.writeTo(out);
Index: gzz/lava/gzz/storm/util/DiffIndexType.java
diff -u gzz/lava/gzz/storm/util/DiffIndexType.java:1.1 
gzz/lava/gzz/storm/util/DiffIndexType.java:1.2
--- gzz/lava/gzz/storm/util/DiffIndexType.java:1.1      Tue Jan 14 10:43:07 2003
+++ gzz/lava/gzz/storm/util/DiffIndexType.java  Sat Jan 18 17:09:39 2003
@@ -23,10 +23,12 @@
 package gzz.storm.util;
 import gzz.storm.*;
 import gzz.util.HexUtil;
+import gzz.util.VersionFormat;
 import java.io.IOException;
+import java.io.FileNotFoundException;
 import java.util.*;
 
-/** For testing purposes: An index of blocks by content-type 
+/** An index of Gzz diffs, by the block they're from/to.
  */
 public class DiffIndexType implements IndexedPool.IndexType {
 
@@ -56,6 +58,7 @@
 
        /** Get all diffs from/to something.
         *  XXX Shouldn't block...
+        *  @return A set of block ids (of the diffs).
         */
        protected Set getDiffs(BlockId id, byte fromOrTo) throws IOException {
            byte[] key = getKey(id.getBytes(), fromOrTo);
@@ -77,6 +80,50 @@
 
        public Set getDiffsTo(BlockId id) throws IOException {
            return getDiffs(id, toByte);
+       }
+
+       protected Set getDiffBlocks(BlockId id, VersionFormat format,
+                                   byte fromOrTo) throws IOException {
+           Set ids = getDiffs(id, fromOrTo);
+           Set result = new HashSet(ids.size());
+
+           for(Iterator i=ids.iterator(); i.hasNext();) {
+               BlockId diff_id = (BlockId)i.next();
+               try {
+                   Block b = pool.get(diff_id);
+                   result.add(new DiffBlock(b, format));
+               } catch(FileNotFoundException e) {
+                   // We have a diff in our index, but
+                   // the block isn't in the pool.
+                   // This means that the DB of the pool
+                   // has returned a mapping for a block
+                   // that isn't there; we have to cope
+                   // with that, since DBs are best-effort
+                   // in the case of e.g. DHTs and
+                   // cannot be relied upon. (A bigger
+                   // issue is that we should not
+                   // be synchronous. ;-) )
+               } catch(IOException e) {
+                   // Here we *might* have a real problem...
+                   // but again, there may simply be wrong data
+                   // in the DB. E.g., someone else on the DHT 
+                   // trying to spoof us. We give a warning
+                   // on the console and ignore the DB entry.
+
+                   System.err.println("Exception when loading diff: "+e);
+                   System.err.println("Ignore.");
+               }
+           }
+
+           return result;
+       }
+
+       public Set getDiffBlocksFrom(BlockId id, VersionFormat format) throws 
IOException {
+           return getDiffBlocks(id, format, fromByte);
+       }
+
+       public Set getDiffBlocksTo(BlockId id, VersionFormat format) throws 
IOException {
+           return getDiffBlocks(id, format, toByte);
        }
     }
 
Index: gzz/lava/test/gzz/storm/util/DiffIndexType.test
diff -u gzz/lava/test/gzz/storm/util/DiffIndexType.test:1.2 
gzz/lava/test/gzz/storm/util/DiffIndexType.test:1.3
--- gzz/lava/test/gzz/storm/util/DiffIndexType.test:1.2 Fri Jan 17 18:35:52 2003
+++ gzz/lava/test/gzz/storm/util/DiffIndexType.test     Sat Jan 18 17:09:40 2003
@@ -17,7 +17,7 @@
 
 ids = [gzz.storm.BlockId(__id) for __id in ids]
 
-def testSimple():
+def testDiffIndexType():
     assert index.getDiffsFrom(ids[0]) == set([])
     
     h = gzz.storm.headers.UniqueHeader822()
@@ -26,6 +26,7 @@
     h.add('X-Gzz-Diff-From', ids[0].getHex())
     h.add('X-Gzz-Diff-To', ids[1].getHex())
     bos = pool.getBlockOutputStream(h)
+    for ch in '\r\n\r\n255': bos.write(ch)
     bos.close()
     b1 = bos.getBlockId()
 
@@ -33,6 +34,17 @@
     assert index.getDiffsTo(ids[1]) == set([b1])
     assert index.getDiffsFrom(ids[1]) == set([])
     assert index.getDiffsTo(ids[0]) == set([])
+
+    format = gzz.storm.util.TestVersion.Format()
+    diffsFrom = index.getDiffBlocksFrom(ids[0], format)
+    diffsTo = index.getDiffBlocksTo(ids[1], format)
+    diffBlock = diffsFrom.iterator().next()
+
+    assert diffsFrom.size() == diffsTo.size() == 1
+    assert diffsTo.iterator().next().diff == diffBlock.diff
+
+    assert diffBlock.diff == gzz.storm.util.TestVersion.Diff(255)
+    
 
     
 
Index: gzz/lava/test/gzz/storm/util/StormFilerBlock.test
diff -u gzz/lava/test/gzz/storm/util/StormFilerBlock.test:1.1 
gzz/lava/test/gzz/storm/util/StormFilerBlock.test:1.2
--- gzz/lava/test/gzz/storm/util/StormFilerBlock.test:1.1       Sat Jan 18 
12:37:26 2003
+++ gzz/lava/test/gzz/storm/util/StormFilerBlock.test   Sat Jan 18 17:09:40 2003
@@ -25,7 +25,6 @@
     block.writeTo(out)
     s = read(out)
 
-    print repr(s)
     assert s == (
         'Content-Type: x-foo/x-foo\r\n'
         '\r\n'
@@ -62,7 +61,6 @@
     block.writeTo(out)
     s = read(out)
 
-    print repr(s)
     assert s == (
         'Content-Type: x-foo/x-bar\r\n'
         '\r\n'
@@ -83,3 +81,25 @@
         pass
     else:
         assert 0
+
+
+def testDiffBlockFromTo():
+    id1 = gzz.storm.BlockId(
+        'storm:block:01863883B88742323BAF6BDB580EA97431AED22518')
+    id2 = gzz.storm.BlockId(
+        'storm:block:01882751458742323BAF6BDB5CC484FA52A52BFF34')
+    
+    diff = TestVersion.Diff(714)
+    header  = gzz.storm.headers.VerbatimHeader822()
+    header.add("X-Gzz-Diff-From", id1.getHex())
+    header.add("foo", "bar")
+    header.add("x-gzz-diff-TO", id2.getHex())
+    format = TestVersion.Format()
+
+    headerFrom = gzz.storm.headers.VerbatimHeader822()
+    headerTo = gzz.storm.headers.VerbatimHeader822()
+    
+    block = DiffBlock(header, diff, headerFrom, headerTo, format)
+    assert block.getFromId() == id1
+    assert block.getToId() == id2
+    




reply via email to

[Prev in Thread] Current Thread [Next in Thread]