(String[] args)
| 14 | private static final Logger logger = LogManager.getLogger(TestDatabaseHalt.class); |
| 15 | |
| 16 | @SuppressWarnings({"InfiniteLoopStatement", "CallToPrintStackTrace"}) |
| 17 | public static void main(String[] args) throws Exception { |
| 18 | Thread.setDefaultUncaughtExceptionHandler((t, e) -> { |
| 19 | //noinspection CallToPrintStackTrace |
| 20 | e.printStackTrace(); |
| 21 | logger.error("uncaught exception in {}:", t, e); |
| 22 | }); |
| 23 | |
| 24 | var config = Config.load(); |
| 25 | var zeze = new Application("TestDatabaseHalt", config); |
| 26 | zeze.getServiceManager().start(); |
| 27 | zeze.getServiceManager().waitReady(); |
| 28 | var defaultDatabaseConf = config.getDatabaseConfMap().get(""); |
| 29 | logger.info(defaultDatabaseConf.getDatabaseUrl()); |
| 30 | zeze.getDbh2AgentManager().start(); |
| 31 | var database = Config.createDatabase(zeze, defaultDatabaseConf); |
| 32 | var tableCount = 5; |
| 33 | var tables = new Database.AbstractKVTable[tableCount]; |
| 34 | for (var i = 0; i < tableCount; ++i) { |
| 35 | var tableName = "TableTestDatabaseHalt" + i; |
| 36 | tables[i] = (Database.AbstractKVTable)database.openTable(tableName, Bean.hash32(tableName)); |
| 37 | } |
| 38 | for (var table : tables) |
| 39 | table.waitReady(); |
| 40 | // verify and get |
| 41 | var count = 0L; |
| 42 | { |
| 43 | ByteBuffer key = ByteBuffer.Allocate(); |
| 44 | key.WriteInt(1); |
| 45 | var counts = new ArrayList<Long>(); |
| 46 | for (Database.AbstractKVTable table : tables) { |
| 47 | var value = table.find(key); |
| 48 | if (null != value) |
| 49 | counts.add(ByteBuffer.Wrap(value).ReadLong()); |
| 50 | } |
| 51 | logger.info("counts={}", counts); |
| 52 | if (!counts.isEmpty()) { |
| 53 | if (counts.size() != tables.length) |
| 54 | throw new RuntimeException("table count mismatch that has value."); // empty is ok. |
| 55 | count = counts.get(0); |
| 56 | for (var i = 1; i < counts.size(); ++i) { |
| 57 | if (!counts.get(i).equals(count)) |
| 58 | throw new RuntimeException("halt test fail!!!"); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | // start halt thread |
| 63 | new Thread(() -> { |
| 64 | try { |
| 65 | Thread.sleep(new Random().nextInt(500) + 500); |
| 66 | logger.info("halt!"); |
| 67 | Runtime.getRuntime().halt(1314); |
| 68 | } catch (Exception ex) { |
| 69 | logger.error("", ex); |
| 70 | } |
| 71 | }).start(); |
| 72 | // infinite loop |
| 73 | { |
nothing calls this directly
no test coverage detected