Package com.moesol.geoserver.sync.core

Examples of com.moesol.geoserver.sync.core.Sha1Value


  private void setupWithTestData(int n) throws NoSuchAlgorithmException, UnsupportedEncodingException {
    m_sha1 = MessageDigest.getInstance("SHA-1");
    m_data = new ArrayList<IdAndValueSha1s>();
    for (int i = 0; i < n; i++) {
      String v = "data" + i;
      Sha1Value aSha1 = new Sha1Value(m_sha1.digest(v.getBytes("UTF-8")));
      m_data.add(new IdAndValueSha1s(aSha1, aSha1));
    }
    m_grouper = new Sha1JsonLevelGrouper(VersionFeatures.VERSION1, m_data);
//    System.out.println(m_data);
  }
View Full Code Here


   */
  public void testGroupForLevelOneWithOneChange() throws NoSuchAlgorithmException, UnsupportedEncodingException {
    m_grouper.groupForLevel(1);
    Sha1SyncJson json = m_grouper.getJson();
   
    Sha1Value aSha1 = new Sha1Value(m_sha1.digest("extra".getBytes("UTF-8")));
    m_data.add(new IdAndValueSha1s(aSha1, aSha1));
    m_grouper = new Sha1JsonLevelGrouper(VersionFeatures.VERSION1, m_data);
    m_grouper.groupForLevel(1);
    Sha1SyncJson json2 = m_grouper.getJson();

View Full Code Here

    assertEquals(257, json.h.size());
    assertEquals(1, json.m);
  }
 
  public void testGroupSixWithCollision() {
    Sha1Value fake = new Sha1Value("");
    m_grouper = new Sha1JsonLevelGrouper(VersionFeatures.VERSION2, Arrays.asList(
        new IdAndValueSha1s(new Sha1Value("1091a76e395ba65b6a35f7ae5110eb02e0661137"), fake),
        new IdAndValueSha1s(new Sha1Value("4ef9968cef6257d719b5a8ee58037c7570270c0f"), fake),
        new IdAndValueSha1s(new Sha1Value("ba58d6e118850afcb9833c646cd5930c9edb33c3"), fake),
        new IdAndValueSha1s(new Sha1Value("c313c8e098040f0b8e7b233f589b809e80f14fc5"), fake),
        new IdAndValueSha1s(new Sha1Value("cf300c55b1d127f07005fe22d6ec12fa2501f089"), fake),
        new IdAndValueSha1s(new Sha1Value("cf64472f30a25d72b259b220cc484cab72b8fa4b"), fake)));
    m_grouper.groupForLevel(1);
    Sha1SyncJson json = m_grouper.getJson();
   
    assertEquals(1, json.level());
    assertEquals(5, json.hashes().size());
View Full Code Here

   * This prefix is empty on the server.
   *
   * @param position
   */
  private void deleteInPosition(Sha1SyncPositionHash position) {
    Sha1Value prefix = new Sha1Value(position.position());
    HashAndFeatureValue find = new HashAndFeatureValue(prefix, null, null);
    // TODO, hmm, better search?
    int i = Collections.binarySearch(m_featureSha1s, find, new IdAndValueSha1Comparator(versionFeatures));
    if (i < 0) {
      i = -i - 1;
    }
    for ( ; i < m_featureSha1s.size(); i++) {
      HashAndFeatureValue value = m_featureSha1s.get(i);
      if (!versionFeatures.getBucketPrefixSha1(value).isPrefixMatch(prefix.get())) {
        break;
      }
      FeatureId fid = value.getFeature().getIdentifier();
      m_potentialDeletes.add(fid);
    }
View Full Code Here

    }
    Collections.sort(m_featureSha1s, new IdAndValueSha1Comparator(versionFeatures));
  }

  protected HashAndFeatureValue makeHashAndFeatureValue(Feature f) {
    Sha1Value idSha1 = m_featureSha1Sync.computeIdSha1(f);
    Sha1Value valueSha1 = m_featureSha1Sync.computeValueSha1(f);
    return new HashAndFeatureValue(idSha1, valueSha1, f);
  }
View Full Code Here

  }

  public void testSha1One() throws ParseException {
    Feature feature = m_samples.buildSimpleFeature("fid1");
    FeatureSha1 sync = new FeatureSha1();
    Sha1Value sha1 = sync.computeValueSha1(feature);
    assertEquals("56e82e2d2452830bbdb9bc1ce353a2e159996308", sha1.toString());
   
    sync.parseAttributesToInclude("-all");
    sha1 = sync.computeValueSha1(feature);
    assertEquals("db90c50160c32f3517b7d3b1c78be70a7f2ba992", sha1.toString());
   
    sync.parseAttributesToInclude("name");
    sha1 = sync.computeValueSha1(feature);
    assertEquals("d4dc2740d2d92547f941bfaf677e11c9b99605ee", sha1.toString());

    sync.parseAttributesToInclude("name,classification");
    sha1 = sync.computeValueSha1(feature);
    assertEquals("c905e1c6c7eb6bad1eedae0509b7da286dbd7b48", sha1.toString());
   

    sync.parseAttributesToInclude("classification,name");
    sha1 = sync.computeValueSha1(feature);
    assertEquals("c905e1c6c7eb6bad1eedae0509b7da286dbd7b48", sha1.toString());

    sync.parseAttributesToInclude("name,classification,height");
    sha1 = sync.computeValueSha1(feature);
    assertEquals("db90c50160c32f3517b7d3b1c78be70a7f2ba992", sha1.toString());
  }
View Full Code Here

  }
 
  public void testValueIdValue() throws ParseException {
    Feature feature = m_samples.buildSimpleFeature("fid1");
    FeatureSha1 sync = new FeatureSha1();
    Sha1Value valueSha1 = sync.computeValueSha1(feature);
    assertEquals("56e82e2d2452830bbdb9bc1ce353a2e159996308", valueSha1.toString());
   
    Sha1Value idSha1 = sync.computeIdSha1(feature);
    assertEquals("56e82e2d2452830bbdb9bc1ce353a2e159996308", idSha1.toString());

    Sha1Value secondValueSha1 = sync.computeValueSha1(feature);
    assertEquals("56e82e2d2452830bbdb9bc1ce353a2e159996308", secondValueSha1.toString());
  }
View Full Code Here

    FeatureCollection<FeatureType, Feature> featureCollection = featureSource.getFeatures();
    FeatureIterator<Feature> iterator = featureCollection.features();
    try {
      Feature feature = iterator.next(); // Just get first feature
      FeatureSha1 sync = new FeatureSha1();
      Sha1Value sha1 = sync.computeValueSha1(feature);
      assertEquals("e88d59d2142c8315878752805e15ddb6521fd9e1", sha1.toString());
    } finally {
      iterator.close();
    }
  }
View Full Code Here

import junit.framework.TestCase;

public class Sha1ValueTest extends TestCase {

  public void testCompareTo() {
    Sha1Value left = new Sha1Value(new byte[0]);
    Sha1Value right = new Sha1Value(new byte[0]);
    assertEquals(0, left.compareTo(right));
   
    right = new Sha1Value(new byte[] { 0 });
    assertEquals(-1, left.compareTo(right));
   
    left = new Sha1Value(new byte[] { 0, 0 });
    assertEquals(1, left.compareTo(right));
   
    right = new Sha1Value(new byte[] { 0, 1 });
    assertEquals(-1, left.compareTo(right));
   
    left = new Sha1Value(new byte[] { 0, 2 });
    assertEquals(1, left.compareTo(right));
  }
View Full Code Here

    left = new Sha1Value(new byte[] { 0, 2 });
    assertEquals(1, left.compareTo(right));
  }
 
  public void testIsPrefixMatch() {
    Sha1Value value = new Sha1Value(new byte[] { 0, 1, 2, 3 });
    assertTrue(value.isPrefixMatch(new byte[] { 0, 1 }));
    assertFalse(value.isPrefixMatch(new byte[] { 0, 2 }));
  }
View Full Code Here

TOP

Related Classes of com.moesol.geoserver.sync.core.Sha1Value

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.