From c82a929d303cd9377f8c72fa3dd76ba9c825d7f2 Mon Sep 17 00:00:00 2001 From: nicksavers Date: Sat, 28 Jun 2014 13:18:43 +0200 Subject: [PATCH] Delete temp database after unit test --- .../org/ethereum/config/SystemProperties.java | 15 ++++----- .../java/org/ethereum/db/DatabaseImpl.java | 4 +-- .../org/ethereum/gui/ContractCallDialog.java | 2 +- .../src/main/resources/system.properties | 6 ++-- .../org/ethereum/db/TrackDatabaseTest.java | 31 +++++++++++++++---- .../src/test/resources/system.properties | 17 ++-------- 6 files changed, 41 insertions(+), 34 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java b/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java index 43588888..3c5b5520 100644 --- a/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java +++ b/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java @@ -27,6 +27,7 @@ public class SystemProperties { private static String DEFAULT_SAMPLES_DIR = "samples"; private static String DEFAULT_COINBASE_SECRET = "monkey"; private static int DEFAULT_ACTIVE_PEER_CHANNEL_TIMEOUT = 5; + private static Boolean DEFAULT_DB_RESET = false; private static Boolean DEFAULT_DUMP_FULL = false; private static String DEFAULT_DUMP_DIR = "dmp"; private static Boolean DEFAULT_DUMP_CLEAN_ON_RESTART = true; @@ -38,14 +39,14 @@ public class SystemProperties { public SystemProperties() { try { - File file = null; - String dir = System.getProperty("user.dir"); - String fileName = dir + "/config/system.properties"; - file = new File(fileName); + String userDir = System.getProperty("user.dir"); + System.out.println(userDir); + String fileName = userDir + "/config/system.properties"; + File file = new File(fileName); if (file.exists()) { input = new FileInputStream(file); - } else{ + } else { fileName = "system.properties"; input = SystemProperties.class.getClassLoader().getResourceAsStream(fileName); if (input == null) { @@ -101,9 +102,9 @@ public class SystemProperties { if(prop.isEmpty()) return DEFAULT_DISCOVERY_PORT; return Integer.parseInt(prop.getProperty("peer.discovery.port")); } - + public boolean databaseReset() { - if(prop.isEmpty()) return false; + if(prop.isEmpty()) return DEFAULT_DB_RESET; return Boolean.parseBoolean(prop.getProperty("database.reset")); } diff --git a/ethereumj-core/src/main/java/org/ethereum/db/DatabaseImpl.java b/ethereumj-core/src/main/java/org/ethereum/db/DatabaseImpl.java index c63005d6..75913654 100644 --- a/ethereumj-core/src/main/java/org/ethereum/db/DatabaseImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/db/DatabaseImpl.java @@ -27,8 +27,8 @@ public class DatabaseImpl implements Database { private static Logger logger = LoggerFactory.getLogger(DatabaseImpl.class); private DB db; - private String name; - + private String name; + public DatabaseImpl(String name) { // Initialize Database this.name = name; diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java b/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java index 78a29718..2358fa8c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/ContractCallDialog.java @@ -22,7 +22,6 @@ import javax.swing.table.DefaultTableModel; import java.awt.*; import java.awt.event.*; -import java.io.Serializable; import java.math.BigInteger; import java.net.URL; import java.util.Collection; @@ -156,6 +155,7 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog { gasInput.setText("1000"); JComboBox creatorAddressCombo = new JComboBox() { + private static final long serialVersionUID = -3748305421049121671L; @Override public ComboBoxUI getUI() { return super.getUI(); diff --git a/ethereumj-core/src/main/resources/system.properties b/ethereumj-core/src/main/resources/system.properties index 306ed585..993dcc75 100644 --- a/ethereumj-core/src/main/resources/system.properties +++ b/ethereumj-core/src/main/resources/system.properties @@ -23,11 +23,11 @@ peer.discovery.port = 30303 #peer.active.ip = 131.104.247.135 #peer.active.port = 30303 -# RomanJ general +# RomanJ #peer.active.ip = 54.211.14.10 #peer.active.port = 30303 - #poc5.testnet.ethereum.org +# PoC-5 testnet peer.active.ip = 54.72.69.180 peer.active.port = 30303 @@ -75,7 +75,7 @@ samples.dir = samples # the existing database will be # destroyed and all the data will be # downloaded from peers again -database.reset = true +database.reset = false # this string is computed # to be eventually the address diff --git a/ethereumj-core/src/test/java/org/ethereum/db/TrackDatabaseTest.java b/ethereumj-core/src/test/java/org/ethereum/db/TrackDatabaseTest.java index cb39a622..7834933c 100644 --- a/ethereumj-core/src/test/java/org/ethereum/db/TrackDatabaseTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/db/TrackDatabaseTest.java @@ -1,6 +1,15 @@ package org.ethereum.db; -import org.junit.Assert; +import static org.iq80.leveldb.impl.Iq80DBFactory.factory; + +import java.io.File; +import java.io.IOException; + +import org.iq80.leveldb.Options; +import org.junit.AfterClass; + +import static org.junit.Assert.*; + import org.junit.Test; import org.spongycastle.util.encoders.Hex; @@ -11,7 +20,7 @@ import org.spongycastle.util.encoders.Hex; * Created on: 11/06/2014 14:54 */ public class TrackDatabaseTest { - + @Test public void test1() { @@ -20,23 +29,33 @@ public class TrackDatabaseTest { trackDatabase1.put(Hex.decode("abcdef"), Hex.decode("abcdef")); byte[] value = trackDatabase1.get(Hex.decode("abcdef")); - Assert.assertEquals("abcdef", Hex.toHexString(value)); + assertEquals("abcdef", Hex.toHexString(value)); trackDatabase1.startTrack(); trackDatabase1.put(Hex.decode("abcdef"), Hex.decode("ffffff")); value = trackDatabase1.get(Hex.decode("abcdef")); - Assert.assertEquals("ffffff", Hex.toHexString(value)); + assertEquals("ffffff", Hex.toHexString(value)); trackDatabase1.rollbackTrack(); value = trackDatabase1.get(Hex.decode("abcdef")); - Assert.assertEquals("abcdef", Hex.toHexString(value)); + assertEquals("abcdef", Hex.toHexString(value)); trackDatabase1.startTrack(); trackDatabase1.put(Hex.decode("abcdef"), Hex.decode("ffffff")); trackDatabase1.commitTrack(); value = trackDatabase1.get(Hex.decode("abcdef")); - Assert.assertEquals("ffffff", Hex.toHexString(value)); + assertEquals("ffffff", Hex.toHexString(value)); db1.close(); } + + @AfterClass + public static void destroyDB() { + try { + Options options = new Options(); + factory.destroy(new File("temp"), options); + } catch (IOException e) { + fail("Destroying temp-db failed"); + } + } } diff --git a/ethereumj-core/src/test/resources/system.properties b/ethereumj-core/src/test/resources/system.properties index d9f01eb1..11eb10a8 100644 --- a/ethereumj-core/src/test/resources/system.properties +++ b/ethereumj-core/src/test/resources/system.properties @@ -19,26 +19,14 @@ peer.discovery.port = 30303 #peer.active.ip = 54.204.10.41 #peer.active.port = 30303 -# Some dude in Canada -#peer.active.ip = 131.104.247.135 -#peer.active.port = 30303 - -# Nick -#peer.active.ip = 82.217.72.169 -#peer.active.port = 30303 - - -# RomanJ general +# RomanJ peer.active.ip = 54.211.14.10 peer.active.port = 50505 - #poc5.testnet.ethereum.org +# PoC-5 testnet #peer.active.ip = 54.72.69.180 #peer.active.port = 30303 -#peer.active.ip = 151.64.223.120 -#peer.active.port = 30304 - # specify if the mechanism # to discover more and more # peers and check the already @@ -82,7 +70,6 @@ samples.dir = samples # downloaded from peers again database.reset = true - # this string is computed # to be eventually the address # that get the miner reward