Examples of TrieImpl


Examples of org.ethereum.trie.TrieImpl

        List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);

        // *** Part - 1 ***
        // 1. load the data from massive-upload.dmp
        //    which includes deletes/upadtes (5000 operations)
        TrieImpl trieSingle = new TrieImpl(mockDb_2);
        for (int i = 0; i < strData.size() ; ++i){

            String[] keyVal= strData.get(i).split("=");

            if (keyVal[0].equals("*"))
                trieSingle.delete(keyVal[1].trim());
            else
                trieSingle.update(keyVal[0].trim(), keyVal[1].trim());
        }


        System.out.println("root_1:  => " + Hex.toHexString(trieSingle.getRootHash()));

        // *** Part - 2 ***
        // pre. we use the same data from massive-upload.dmp
        //      which includes deletes/upadtes (100000 operations)
        // 1. part of the data loaded
        // 2. the trie cache sync to the db
        // 3. the rest of the data loaded with part of the trie not in the cache
        TrieImpl trie = new TrieImpl(mockDb);

        for (int i = 0; i < 2000; ++i){

            String[] keyVal= strData.get(i).split("=");

            if (keyVal[0].equals("*"))
                trie.delete(keyVal[1].trim());
            else
                trie.update(keyVal[0].trim(), keyVal[1].trim());
        }

        trie.cleanCache();
        trie.sync();

        TrieImpl trie2 = new TrieImpl(mockDb, trie.getRootHash());

        for (int i = 2000; i < strData.size(); ++i){

            String[] keyVal= strData.get(i).split("=");

            if (keyVal[0].equals("*"))
                trie2.delete(keyVal[1].trim());
            else
                trie2.update(keyVal[0].trim(), keyVal[1].trim());
        }

        System.out.println("root_2:  => " + Hex.toHexString( trie2.getRootHash()));

        assertEquals(trieSingle.getRootHash(), trie2.getRootHash());

    }
View Full Code Here

Examples of org.ethereum.trie.TrieImpl

     
      if(massiveUpdateFromDBEnabled) {
          List<String> randomWords = Arrays.asList(randomDictionary.split(","));
          Map<String, String> testerMap = new HashMap<>();

          TrieImpl trie = new TrieImpl(mockDb);
          Random generator = new Random();
 
          // Random insertion
          for (int i = 0; i < 50000; ++i ){
 
              int randomIndex1 = generator.nextInt(randomWords.size());
              int randomIndex2 = generator.nextInt(randomWords.size());
 
              String word1 = randomWords.get(randomIndex1).trim();
              String word2 = randomWords.get(randomIndex2).trim();
 
              trie.update(word1, word2);
              testerMap.put(word1, word2);
          }
 
          trie.cleanCache();
          trie.sync();
 
          // Assert the result now
          Iterator<String> keys = testerMap.keySet().iterator();
          while (keys.hasNext()){
 
              String mapWord1 = keys.next();
              String mapWord2 = testerMap.get(mapWord1);
              String treeWord2 = new String(trie.get(mapWord1));
 
              Assert.assertEquals(mapWord2, treeWord2);
          }
 
          TrieImpl trie2 = new TrieImpl(mockDb, trie.getRootHash());
 
          // Assert the result now
          keys = testerMap.keySet().iterator();
          while (keys.hasNext()){
 
              String mapWord1 = keys.next();
              String mapWord2 = testerMap.get(mapWord1);
              String treeWord2 = new String(trie2.get(mapWord1));
 
              Assert.assertEquals(mapWord2, treeWord2);
          }
      }
    }
View Full Code Here

Examples of org.ethereum.trie.TrieImpl

        mockDb_2.close();
    }

    @Test
    public void testEmptyKey() {
        TrieImpl trie = new TrieImpl(mockDb);

        trie.update("", dog);
        assertEquals(dog, new String(trie.get("")));
    }
View Full Code Here

Examples of org.ethereum.trie.TrieImpl

        assertEquals(dog, new String(trie.get("")));
    }

    @Test
    public void testInsertShortString() {
        TrieImpl trie = new TrieImpl(mockDb);

        trie.update(cat, dog);
        assertEquals(dog, new String(trie.get(cat)));
    }
View Full Code Here

Examples of org.ethereum.trie.TrieImpl

        assertEquals(dog, new String(trie.get(cat)));
    }

    @Test
    public void testInsertLongString() {
        TrieImpl trie = new TrieImpl(mockDb);

        trie.update(cat, LONG_STRING);
        assertEquals(LONG_STRING, new String(trie.get(cat)));
    }
View Full Code Here

Examples of org.ethereum.trie.TrieImpl

        assertEquals(LONG_STRING, new String(trie.get(cat)));
    }

    @Test
    public void testInsertMultipleItems1() {
        TrieImpl trie = new TrieImpl(mockDb);
        trie.update(ca, dude);
        assertEquals(dude, new String(trie.get(ca)));

        trie.update(cat, dog);
        assertEquals(dog, new String(trie.get(cat)));

        trie.update(dog, test);
        assertEquals(test, new String(trie.get(dog)));

        trie.update(doge, LONG_STRING);
        assertEquals(LONG_STRING, new String(trie.get(doge)));

        trie.update(test, LONG_STRING);
        assertEquals(LONG_STRING, new String(trie.get(test)));

        // Test if everything is still there
        assertEquals(dude, new String(trie.get(ca)));
        assertEquals(dog, new String(trie.get(cat)));
        assertEquals(test, new String(trie.get(dog)));
        assertEquals(LONG_STRING, new String(trie.get(doge)));
        assertEquals(LONG_STRING, new String(trie.get(test)));
    }
View Full Code Here

Examples of org.ethereum.trie.TrieImpl

        assertEquals(LONG_STRING, new String(trie.get(test)));
    }

    @Test
    public void testInsertMultipleItems2() {
        TrieImpl trie = new TrieImpl(mockDb);

        trie.update(cat, dog);
        assertEquals(dog, new String(trie.get(cat)));

        trie.update(ca, dude);
        assertEquals(dude, new String(trie.get(ca)));

        trie.update(doge, LONG_STRING);
        assertEquals(LONG_STRING, new String(trie.get(doge)));

        trie.update(dog, test);
        assertEquals(test, new String(trie.get(dog)));

        trie.update(test, LONG_STRING);
        assertEquals(LONG_STRING, new String(trie.get(test)));

        // Test if everything is still there
        assertEquals(dog, new String(trie.get(cat)));
        assertEquals(dude, new String(trie.get(ca)));
        assertEquals(LONG_STRING, new String(trie.get(doge)));
        assertEquals(test, new String(trie.get(dog)));
        assertEquals(LONG_STRING, new String(trie.get(test)));
    }
View Full Code Here

Examples of org.ethereum.trie.TrieImpl

        assertEquals(LONG_STRING, new String(trie.get(test)));
    }

    @Test
    public void testUpdateShortToShortString() {
        TrieImpl trie = new TrieImpl(mockDb);

        trie.update(cat, dog);
        assertEquals(dog, new String(trie.get(cat)));

        trie.update(cat, dog+"1");
        assertEquals(dog+"1", new String(trie.get(cat)));
    }
View Full Code Here

Examples of org.ethereum.trie.TrieImpl

        assertEquals(dog+"1", new String(trie.get(cat)));
    }

    @Test
    public void testUpdateLongToLongString() {
        TrieImpl trie = new TrieImpl(mockDb);
        trie.update(cat, LONG_STRING);
        assertEquals(LONG_STRING, new String(trie.get(cat)));
        trie.update(cat, LONG_STRING+"1");
        assertEquals(LONG_STRING+"1", new String(trie.get(cat)));
    }
View Full Code Here

Examples of org.ethereum.trie.TrieImpl

        assertEquals(LONG_STRING+"1", new String(trie.get(cat)));
    }

    @Test
    public void testUpdateShortToLongString() {
        TrieImpl trie = new TrieImpl(mockDb);

        trie.update(cat, dog);
        assertEquals(dog, new String(trie.get(cat)));

        trie.update(cat, LONG_STRING+"1");
        assertEquals(LONG_STRING+"1", new String(trie.get(cat)));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.