Skip to content

Commit ec74cfb

Browse files
Fixing and beatify small things
1 parent 4a78744 commit ec74cfb

File tree

8 files changed

+124
-3
lines changed

8 files changed

+124
-3
lines changed

adrestus-core/src/test/java/io/Adrestus/core/DeleteDBTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.Adrestus.core;
22

3+
import com.google.common.reflect.TypeToken;
34
import io.distributedLedger.*;
45
import org.junit.jupiter.api.Test;
56

@@ -8,6 +9,8 @@ public class DeleteDBTest {
89

910
@Test
1011
public void delete_test() {
12+
IDatabase<String, LevelDBTransactionWrapper<Transaction>> transaction_database = new DatabaseFactory(String.class, Transaction.class, new TypeToken<LevelDBTransactionWrapper<Transaction>>() {
13+
}.getType()).getDatabase(DatabaseType.LEVEL_DB);
1114
IDatabase<String, TransactionBlock> transaction_block1 = new DatabaseFactory(String.class, TransactionBlock.class).getDatabase(DatabaseType.ROCKS_DB, DatabaseInstance.ZONE_0_TRANSACTION_BLOCK);
1215
IDatabase<String, TransactionBlock> transaction_block2 = new DatabaseFactory(String.class, TransactionBlock.class).getDatabase(DatabaseType.ROCKS_DB, DatabaseInstance.ZONE_1_TRANSACTION_BLOCK);
1316
IDatabase<String, TransactionBlock> transaction_block3 = new DatabaseFactory(String.class, TransactionBlock.class).getDatabase(DatabaseType.ROCKS_DB, DatabaseInstance.ZONE_2_TRANSACTION_BLOCK);
@@ -34,5 +37,6 @@ public void delete_test() {
3437

3538

3639
commit.delete_db();
40+
transaction_database.delete_db();
3741
}
3842
}

adrestus-core/src/test/java/io/Adrestus/core/RPCExampleTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,38 @@ public void myCdownload2() throws Exception {
223223
assertEquals(transactionBlock, blocks.get(0));
224224

225225

226+
client.close();
227+
example.close();
228+
example = null;
229+
database.delete_db();
230+
} catch (Exception e) {
231+
System.out.println("Exception caught: " + e.toString());
232+
}
233+
}
234+
@Test
235+
public void myCadownload2() throws Exception {
236+
try {
237+
IDatabase<String, TransactionBlock> database = new DatabaseFactory(String.class, TransactionBlock.class).getDatabase(DatabaseType.ROCKS_DB, DatabaseInstance.ZONE_1_TRANSACTION_BLOCK);
238+
IDatabase<String, TransactionBlock> database2 = new DatabaseFactory(String.class, TransactionBlock.class).getDatabase(DatabaseType.ROCKS_DB, DatabaseInstance.ZONE_2_TRANSACTION_BLOCK);
239+
TransactionBlock transactionBlock = new TransactionBlock();
240+
TransactionBlock transactionBlock2 = new TransactionBlock();
241+
String hash = HashUtil.sha256_bytetoString(encode.encode(transactionBlock));
242+
transactionBlock.setHash(hash);
243+
transactionBlock2.setHash("1");
244+
database.save(transactionBlock.getHash(), transactionBlock);
245+
database2.save(transactionBlock2.getHash(), transactionBlock2);
246+
247+
RpcAdrestusServer<AbstractBlock> example = new RpcAdrestusServer<AbstractBlock>(new TransactionBlock(), DatabaseInstance.ZONE_2_TRANSACTION_BLOCK, "localhost", 8095, eventloop);
248+
new Thread(example).start();
249+
RpcAdrestusClient<AbstractBlock> client = new RpcAdrestusClient<AbstractBlock>(new TransactionBlock(), "localhost", 8095, eventloop);
250+
client.connect();
251+
List<AbstractBlock> blocks = client.getBlocksList("1");
252+
if (blocks.isEmpty()) {
253+
System.out.println("error");
254+
}
255+
assertEquals(transactionBlock2, blocks.get(0));
256+
257+
226258
client.close();
227259
example.close();
228260
example = null;

adrestus-core/src/test/java/io/Adrestus/core/RocksDBBlockTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,48 @@ public void find_between_range() {
359359
assertEquals("hash1", firstKey.get());
360360
database.delete_db();
361361
}
362+
@Test
363+
public void find_between_range2() {
364+
IDatabase<String, TransactionBlock> database = new DatabaseFactory(String.class, TransactionBlock.class).getDatabase(DatabaseType.ROCKS_DB, DatabaseInstance.ZONE_1_TRANSACTION_BLOCK);
365+
String hash = "Hash";
366+
TransactionBlock transactionBlock1 = new TransactionBlock();
367+
transactionBlock1.setHeight(1);
368+
transactionBlock1.setHash("hash1");
369+
370+
TransactionBlock transactionBlock2 = new TransactionBlock();
371+
transactionBlock2.setHeight(2);
372+
transactionBlock2.setHash("hash2");
373+
374+
TransactionBlock transactionBlock3 = new TransactionBlock();
375+
transactionBlock3.setHeight(3);
376+
transactionBlock3.setHash("hash3");
377+
378+
TransactionBlock transactionBlock4 = new TransactionBlock();
379+
transactionBlock4.setHeight(4);
380+
transactionBlock4.setHash("hash4");
381+
382+
TransactionBlock transactionBlock5 = new TransactionBlock();
383+
transactionBlock5.setHeight(5);
384+
transactionBlock5.setHash("hash5");
385+
386+
TransactionBlock transactionBlock6 = new TransactionBlock();
387+
transactionBlock6.setHeight(6);
388+
transactionBlock6.setHash("hash6");
389+
390+
Map<String, TransactionBlock> map = new HashMap<>();
391+
map.put("hash1", transactionBlock1);
392+
map.put("hash2", transactionBlock2);
393+
map.put("hash3", transactionBlock3);
394+
map.put("hash4", transactionBlock4);
395+
map.put("hash5", transactionBlock5);
396+
map.put("hash6", transactionBlock6);
397+
398+
database.saveAll(map);
399+
400+
Map<String, TransactionBlock> map_returned = database.findBetweenRange("hash145");
401+
assertEquals(0, map_returned.size());
402+
database.delete_db();
403+
}
362404

363405
@Test
364406
public void save_all_tree() throws Exception {

adrestus-distributed-ledger/src/main/java/io/distributedLedger/RocksDBConnectionManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ public Map<K, V> findBetweenRange(K key) {
459459
do {
460460
byte[] serializedKey = iterator.key();
461461
byte[] serializedValue = iterator.value();
462+
final byte[] res = rocksDB.get(serializedKey);
463+
if(res==null){
464+
return (Map<K, V>) hashmap;
465+
}
462466
hashmap.put(keyMapper.decode(serializedKey), valueMapper.decode(serializedValue));
463467
iterator.next();
464468
} while (iterator.isValid());

adrestus-distributed-ledger/src/test/java/io/distributedLedger/LevelDBConnectionTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ public void myBfind_between_range() {
6666

6767
database.delete_db();
6868
}
69+
@Test
70+
public void myBfind_between_range2() {
71+
IDatabase<String, String> database = new DatabaseFactory(String.class, String.class).getDatabase(DatabaseType.LEVEL_DB);
72+
Map<String, String> map = new HashMap<>();
73+
map.put("key1", "value1");
74+
map.put("key2", "value2");
75+
map.put("key3", "value3");
76+
map.put("key4", "value4");
77+
78+
database.saveAll(map);
79+
assertEquals(4, database.findDBsize());
80+
Map<String, String> res = database.findBetweenRange("key234");
81+
assertEquals(0, res.entrySet().size());
82+
83+
database.delete_db();
84+
}
6985

7086
@Test
7187
public void myAdelete() {

adrestus-network/src/main/java/io/Adrestus/rpc/Service.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public Service(Class<T> typeParameterClass, PatriciaTreeInstance instance) {
4242

4343
@Override
4444
public List<T> download(String hash) throws Exception {
45+
ZoneDatabaseFactory.getZoneInstance(0);
4546
Map<String, T> map;
4647
if (hash.equals(""))
4748
map = database.seekFromStart();

adrestus-protocol/src/main/java/io/Adrestus/protocol/Example/SyncConsensusNotExistedMain.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ private static void setup() throws InterruptedException {
160160
TreeFactory.getMemoryTree(0).store(address10, new PatriciaTreeNode(3000, 0));
161161
TreeFactory.getMemoryTree(0).store(address11, new PatriciaTreeNode(3000, 0));
162162
TreeFactory.getMemoryTree(0).store(address12, new PatriciaTreeNode(3000, 0));
163+
TreeFactory.getMemoryTree(0).store("ADR-GBIV-HG2J-27P5-BNVN-MLN6-DL5V-M3YZ-PKEJ-CFFG-FK4L", new PatriciaTreeNode(1000, 0));
164+
TreeFactory.getMemoryTree(0).store("ADR-GBZX-XXCW-LWJC-J7RZ-Q6BJ-RFBA-J5WU-NBAG-4RL7-7G6Z",new PatriciaTreeNode(1000,0));
165+
TreeFactory.getMemoryTree(0).store("ADR-GD3G-DK4I-DKM2-IQSB-KBWL-HWRV-BBQA-MUAS-MGXA-5QPP",new PatriciaTreeNode(1000,0));
163166

164167
TreeFactory.getMemoryTree(1).store(address1, new PatriciaTreeNode(3000, 0));
165168
TreeFactory.getMemoryTree(1).store(address2, new PatriciaTreeNode(3000, 0));
@@ -173,6 +176,9 @@ private static void setup() throws InterruptedException {
173176
TreeFactory.getMemoryTree(1).store(address10, new PatriciaTreeNode(3000, 0));
174177
TreeFactory.getMemoryTree(1).store(address11, new PatriciaTreeNode(3000, 0));
175178
TreeFactory.getMemoryTree(1).store(address12, new PatriciaTreeNode(3000, 0));
179+
TreeFactory.getMemoryTree(1).store("ADR-GBIV-HG2J-27P5-BNVN-MLN6-DL5V-M3YZ-PKEJ-CFFG-FK4L", new PatriciaTreeNode(1000, 0));
180+
TreeFactory.getMemoryTree(1).store("ADR-GBZX-XXCW-LWJC-J7RZ-Q6BJ-RFBA-J5WU-NBAG-4RL7-7G6Z",new PatriciaTreeNode(2000,0));
181+
TreeFactory.getMemoryTree(1).store("ADR-GD3G-DK4I-DKM2-IQSB-KBWL-HWRV-BBQA-MUAS-MGXA-5QPP",new PatriciaTreeNode(2000,0));
176182

177183

178184
TreeFactory.getMemoryTree(2).store(address1, new PatriciaTreeNode(3000, 0));
@@ -187,6 +193,9 @@ private static void setup() throws InterruptedException {
187193
TreeFactory.getMemoryTree(2).store(address10, new PatriciaTreeNode(3000, 0));
188194
TreeFactory.getMemoryTree(2).store(address11, new PatriciaTreeNode(3000, 0));
189195
TreeFactory.getMemoryTree(2).store(address12, new PatriciaTreeNode(3000, 0));
196+
TreeFactory.getMemoryTree(2).store("ADR-GBIV-HG2J-27P5-BNVN-MLN6-DL5V-M3YZ-PKEJ-CFFG-FK4L", new PatriciaTreeNode(1000, 0));
197+
TreeFactory.getMemoryTree(2).store("ADR-GBZX-XXCW-LWJC-J7RZ-Q6BJ-RFBA-J5WU-NBAG-4RL7-7G6Z",new PatriciaTreeNode(3000,0));
198+
TreeFactory.getMemoryTree(2).store("ADR-GD3G-DK4I-DKM2-IQSB-KBWL-HWRV-BBQA-MUAS-MGXA-5QPP",new PatriciaTreeNode(3000,0));
190199

191200

192201
TreeFactory.getMemoryTree(3).store(address1, new PatriciaTreeNode(3000, 0));
@@ -201,6 +210,9 @@ private static void setup() throws InterruptedException {
201210
TreeFactory.getMemoryTree(3).store(address10, new PatriciaTreeNode(3000, 0));
202211
TreeFactory.getMemoryTree(3).store(address11, new PatriciaTreeNode(3000, 0));
203212
TreeFactory.getMemoryTree(3).store(address12, new PatriciaTreeNode(3000, 0));
213+
TreeFactory.getMemoryTree(3).store("ADR-GBIV-HG2J-27P5-BNVN-MLN6-DL5V-M3YZ-PKEJ-CFFG-FK4L", new PatriciaTreeNode(1000, 0));
214+
TreeFactory.getMemoryTree(3).store("ADR-GBZX-XXCW-LWJC-J7RZ-Q6BJ-RFBA-J5WU-NBAG-4RL7-7G6Z",new PatriciaTreeNode(4000,0));
215+
TreeFactory.getMemoryTree(3).store("ADR-GD3G-DK4I-DKM2-IQSB-KBWL-HWRV-BBQA-MUAS-MGXA-5QPP",new PatriciaTreeNode(4000,0));
204216

205217
TransactionBlock TransactionBlockZone2 = new TransactionBlock();
206218
TransactionBlockZone2.setHeight(1);

adrestus-protocol/src/test/java/io/Adrestus/protocol/BootstrapConsensusTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ public static void setup() throws Exception {
228228
TreeFactory.getMemoryTree(0).store(address10, new PatriciaTreeNode(3000, 0));
229229
TreeFactory.getMemoryTree(0).store(address11, new PatriciaTreeNode(3000, 0));
230230
TreeFactory.getMemoryTree(0).store(address12, new PatriciaTreeNode(3000, 0));
231+
TreeFactory.getMemoryTree(0).store("ADR-GBIV-HG2J-27P5-BNVN-MLN6-DL5V-M3YZ-PKEJ-CFFG-FK4L", new PatriciaTreeNode(1000, 0));
232+
TreeFactory.getMemoryTree(0).store("ADR-GBZX-XXCW-LWJC-J7RZ-Q6BJ-RFBA-J5WU-NBAG-4RL7-7G6Z",new PatriciaTreeNode(1000,0));
233+
TreeFactory.getMemoryTree(0).store("ADR-GD3G-DK4I-DKM2-IQSB-KBWL-HWRV-BBQA-MUAS-MGXA-5QPP",new PatriciaTreeNode(1000,0));
231234

232235
TreeFactory.getMemoryTree(1).store(address1, new PatriciaTreeNode(3000, 0));
233236
TreeFactory.getMemoryTree(1).store(address2, new PatriciaTreeNode(3000, 0));
@@ -241,7 +244,9 @@ public static void setup() throws Exception {
241244
TreeFactory.getMemoryTree(1).store(address10, new PatriciaTreeNode(3000, 0));
242245
TreeFactory.getMemoryTree(1).store(address11, new PatriciaTreeNode(3000, 0));
243246
TreeFactory.getMemoryTree(1).store(address12, new PatriciaTreeNode(3000, 0));
244-
247+
TreeFactory.getMemoryTree(1).store("ADR-GBIV-HG2J-27P5-BNVN-MLN6-DL5V-M3YZ-PKEJ-CFFG-FK4L", new PatriciaTreeNode(1000, 0));
248+
TreeFactory.getMemoryTree(1).store("ADR-GBZX-XXCW-LWJC-J7RZ-Q6BJ-RFBA-J5WU-NBAG-4RL7-7G6Z",new PatriciaTreeNode(2000,0));
249+
TreeFactory.getMemoryTree(1).store("ADR-GD3G-DK4I-DKM2-IQSB-KBWL-HWRV-BBQA-MUAS-MGXA-5QPP",new PatriciaTreeNode(2000,0));
245250

246251
TreeFactory.getMemoryTree(2).store(address1, new PatriciaTreeNode(3000, 0));
247252
TreeFactory.getMemoryTree(2).store(address2, new PatriciaTreeNode(3000, 0));
@@ -255,7 +260,9 @@ public static void setup() throws Exception {
255260
TreeFactory.getMemoryTree(2).store(address10, new PatriciaTreeNode(3000, 0));
256261
TreeFactory.getMemoryTree(2).store(address11, new PatriciaTreeNode(3000, 0));
257262
TreeFactory.getMemoryTree(2).store(address12, new PatriciaTreeNode(3000, 0));
258-
263+
TreeFactory.getMemoryTree(2).store("ADR-GBIV-HG2J-27P5-BNVN-MLN6-DL5V-M3YZ-PKEJ-CFFG-FK4L", new PatriciaTreeNode(1000, 0));
264+
TreeFactory.getMemoryTree(2).store("ADR-GBZX-XXCW-LWJC-J7RZ-Q6BJ-RFBA-J5WU-NBAG-4RL7-7G6Z",new PatriciaTreeNode(3000,0));
265+
TreeFactory.getMemoryTree(2).store("ADR-GD3G-DK4I-DKM2-IQSB-KBWL-HWRV-BBQA-MUAS-MGXA-5QPP",new PatriciaTreeNode(3000,0));
259266

260267
TreeFactory.getMemoryTree(3).store(address1, new PatriciaTreeNode(3000, 0));
261268
TreeFactory.getMemoryTree(3).store(address2, new PatriciaTreeNode(3000, 0));
@@ -269,6 +276,9 @@ public static void setup() throws Exception {
269276
TreeFactory.getMemoryTree(3).store(address10, new PatriciaTreeNode(3000, 0));
270277
TreeFactory.getMemoryTree(3).store(address11, new PatriciaTreeNode(3000, 0));
271278
TreeFactory.getMemoryTree(3).store(address12, new PatriciaTreeNode(3000, 0));
279+
TreeFactory.getMemoryTree(3).store("ADR-GBIV-HG2J-27P5-BNVN-MLN6-DL5V-M3YZ-PKEJ-CFFG-FK4L", new PatriciaTreeNode(1000, 0));
280+
TreeFactory.getMemoryTree(3).store("ADR-GBZX-XXCW-LWJC-J7RZ-Q6BJ-RFBA-J5WU-NBAG-4RL7-7G6Z",new PatriciaTreeNode(4000,0));
281+
TreeFactory.getMemoryTree(3).store("ADR-GD3G-DK4I-DKM2-IQSB-KBWL-HWRV-BBQA-MUAS-MGXA-5QPP",new PatriciaTreeNode(4000,0));
272282

273283
kad1 = new KademliaData(new SecurityAuditProofs(address1, vk1, ecKeyPair1.getPublicKey(), signatureData1), new NettyConnectionInfo("192.168.1.106", KademliaConfiguration.PORT));
274284
kad2 = new KademliaData(new SecurityAuditProofs(address2, vk2, ecKeyPair2.getPublicKey(), signatureData2), new NettyConnectionInfo("192.168.1.113", KademliaConfiguration.PORT));
@@ -457,7 +467,7 @@ public void test() throws IOException, InterruptedException {
457467
}
458468

459469

460-
CountDownLatch latch = new CountDownLatch(20);
470+
CountDownLatch latch = new CountDownLatch(50);
461471
ConsensusState c = new ConsensusState(latch);
462472
c.getTransaction_block_timer().scheduleAtFixedRate(new ConsensusState.TransactionBlockConsensusTask(), ConsensusConfiguration.CONSENSUS_TIMER, ConsensusConfiguration.CONSENSUS_TIMER);
463473
//c.getCommittee_block_timer().scheduleAtFixedRate(new ConsensusState.CommitteeBlockConsensusTask(), ConsensusConfiguration.CONSENSUS_COMMITTEE_TIMER, ConsensusConfiguration.CONSENSUS_COMMITTEE_TIMER);

0 commit comments

Comments
 (0)