@Override public void clearState() throws Exception { sqlStore.clearData(); }
/** * Get the name of the tenant with the given id. Id to name mapping is cached, so this will not involve an io * operation except for the first time it is called. * * @param id Id of the tenant to get the name for * @return Name of the tenant with the given id, or null if the tenant does not exist * @throws IOException */ @Override public String getNameForId(String id) throws IOException { if (idToNameMap.containsKey(id)) { return idToNameMap.get(id); } String name = getNameFromDB(id); // if there is no tenant, return null if (name == null) { return null; } // cache the result since id to name will never change idToNameMap.put(id, name); return name; }
@Override protected void startUp() throws Exception { if (dbConnectionPool.isEmbeddedDerbyDB()) { DBHelper.createDerbyTableIfNotExists( "CREATE TABLE tenants ( " + "id VARCHAR(255), " + "name VARCHAR(255), " + "workers INT, " + "deleted BOOLEAN, " + "create_time TIMESTAMP, " + "delete_time TIMESTAMP, " + "tenant BLOB )", dbConnectionPool); } // add superadmin if it doesn't exist Tenant superadminTenant = getTenantByName(Constants.SUPERADMIN_TENANT); if (superadminTenant == null) { writeTenant(Tenant.DEFAULT_SUPERADMIN); } }
@BeforeClass public static void beforeClass() throws SQLException, ClassNotFoundException { Configuration sqlConf = BaseTest.createTestConf(); Injector injector = Guice.createInjector( new ConfigurationModule(sqlConf), new TestStoreModule(), new CodecModules().getModule() ); sqlStore = injector.getInstance(SQLTenantStore.class); sqlStore.startAndWait(); sqlStore.clearData(); store = sqlStore; }
@Before public void setupSuperadminHandlerTest() throws SQLException, IOException { // base tests will write some tenants that we don't want. ((SQLTenantStore) tenantStore).clearData(); ((SQLProvisionerStore) provisionerStore).clearData(); ((SQLEntityStoreService) entityStoreService).clearData(); tenantProvisionerService.writeProvisioner( new Provisioner("p1", "host", 12345, 100, ImmutableMap.<String, Integer>of(), ImmutableMap.<String, Integer>of()) ); }
@After public void cleanupBaseTest() throws Exception { if (shouldClearDataBetweenTests()) { sqlTenantStore.clearData(); sqlClusterStoreService.clearData(); sqlProvisionerStore.clearData(); sqlMetaStoreService.clearData(); sqlUserStore.clearData(); pluginStore.clearData(); credentialStore.wipe(); } }