1818import org .junit .Test ;
1919import org .tron .common .utils .ByteArray ;
2020import org .tron .common .utils .FileUtil ;
21- import org .tron .core . Constant ;
21+ import org .tron .common . utils . PropUtil ;
2222import org .tron .core .config .args .Args ;
2323
2424@ Slf4j
@@ -42,7 +42,7 @@ public class RocksDbDataSourceImplTest {
4242
4343 @ Before
4444 public void initDb () {
45- Args .setParam (new String []{"--output-directory" , dbPath }, Constant . TEST_CONF );
45+ Args .setParam (new String []{"--output-directory" , dbPath }, "config-test-dbbackup.conf" );
4646 dataSourceTest = new RocksDbDataSourceImpl (dbPath + File .separator , "test_rocksDb" );
4747 }
4848
@@ -250,4 +250,35 @@ public void getValuesPrev() {
250250 dataSource .resetDb ();
251251 dataSource .closeDB ();
252252 }
253+
254+ @ Test
255+ public void testCheckOrInitEngine () {
256+ String dir = Args .getInstance ().getOutputDirectory () + Args .getInstance ().getStorage ().getDbDirectory ();
257+ String enginePath = dir + File .separator + "test_engine" + File .separator + "engine.properties" ;
258+ FileUtil .createDirIfNotExists (dir + File .separator + "test_engine" );
259+ FileUtil .createFileIfNotExists (enginePath );
260+ boolean b = PropUtil .writeProperty (enginePath , "ENGINE" , "ROCKSDB" );
261+ Assert .assertEquals (PropUtil .readProperty (enginePath , "ENGINE" ),
262+ "ROCKSDB" );
263+
264+ RocksDbDataSourceImpl dataSource ;
265+ dataSource = new RocksDbDataSourceImpl (dir , "test_engine" );
266+ dataSource .initDB ();
267+ Assert .assertNotNull (dataSource .getDatabase ());
268+ dataSource .closeDB ();
269+
270+ dataSource = null ;
271+ System .gc ();
272+ b = PropUtil .writeProperty (enginePath , "ENGINE" , "LEVELDB" );
273+ Assert .assertEquals (PropUtil .readProperty (enginePath , "ENGINE" ),
274+ "LEVELDB" );
275+ dataSource = new RocksDbDataSourceImpl (dir , "test_engine" );
276+ try {
277+ dataSource .initDB ();
278+ } catch (Exception e ) {
279+ Assert .assertTrue (e .getMessage ().contains ("Failed to" ));
280+ }
281+ Assert .assertNull (dataSource .getDatabase ());
282+ PropUtil .writeProperty (enginePath , "ENGINE" , "ROCKSDB" );
283+ }
253284}
0 commit comments