public void initDefaultMasterKey() {
        String defaultMasterKeySpec = Config.default_master_key;
        keysLock.writeLock().lock();
        try {
            if (defaultMasterKeySpec.isEmpty()) {
                if (idToKey.size() != 0) {
                    LOG.error("default_master_key removed in config");
                    System.exit(1);
                }
            } else {
                EncryptionKey masterKeyFromConfig = EncryptionKey.createFromSpec(defaultMasterKeySpec);
                if (idToKey.size() == 0) {
                    // setup default master key
                    masterKeyFromConfig.id = DEFAULT_MASTER_KYE_ID;
                    addKey(masterKeyFromConfig);
                    LOG.info("create default master key:" + masterKeyFromConfig);
                } else {
                    // check masterkey not changed
                    EncryptionKey masterKey = idToKey.get(DEFAULT_MASTER_KYE_ID);
                    Preconditions.checkState(masterKey.equals(masterKeyFromConfig),
                            "default_master_key changed meta:%s config:%s", masterKey.toSpec(),
                            masterKeyFromConfig.toSpec());
                }
                if (idToKey.size() == 1) {
                    // setup first KEK
                    generateNewKEK();
                }
            }
        } catch (Exception e) {
            LOG.fatal("init default master key failed, will exit.", e);
            System.exit(-1);
        } finally {
            keysLock.writeLock().unlock();
        }
    }
@Test
    public void testInitDefaultMasterKey() {
        new MockUp<System>() {
            @Mock
            public void exit(int value) {
                throw new RuntimeException(String.valueOf(value));
            }
        };
        String oldConfig = Config.default_master_key;
        try {
            Config.default_master_key = "plain:aes_128:enwSdCUAiCLLx2Bs9E/neQ==";
            KeyMgr keyMgr = new KeyMgr();
            keyMgr.initDefaultMasterKey();
            Assert.assertEquals(2, keyMgr.numKeys());
            Config.default_master_key = "plain:aes_128:eCsM28LaDORFTZDUMz3y4g==";
            keyMgr.initDefaultMasterKey();
            Assert.fail("should throw exception");
        } catch (RuntimeException e) {
            Assert.assertEquals("-1", e.getMessage());
        } finally {
            Config.default_master_key = oldConfig;
        }
    }