### Question:
CreateSchemaTask implements DataDefinitionTask<CreateSchema> { @VisibleForTesting ListenableFuture<?> internalExecute(CreateSchema statement, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters) { CatalogSchemaName schema = createCatalogSchemaName(session, statement, Optional.of(statement.getSchemaName())); accessControl.checkCanCreateSchema(session.toSecurityContext(), schema); if (metadata.schemaExists(session, schema)) { if (!statement.isNotExists()) { throw semanticException(SCHEMA_ALREADY_EXISTS, statement, "Schema '%s' already exists", schema); } return immediateFuture(null); } CatalogName catalogName = metadata.getCatalogHandle(session, schema.getCatalogName()) .orElseThrow(() -> new PrestoException(NOT_FOUND, "Catalog does not exist: " + schema.getCatalogName())); Map<String, Object> properties = metadata.getSchemaPropertyManager().getProperties( catalogName, schema.getCatalogName(), mapFromProperties(statement.getProperties()), session, metadata, accessControl, parameterExtractor(statement, parameters)); PrestoPrincipal principal = getCreatePrincipal(statement, session, metadata); try { metadata.createSchema(session, schema, properties, principal); } catch (PrestoException e) { if (!e.getErrorCode().equals(ALREADY_EXISTS.toErrorCode()) || !statement.isNotExists()) { throw e; } } return immediateFuture(null); }  @Override String getName(); @Override String explain(CreateSchema statement, List<Expression> parameters); @Override ListenableFuture<?> execute(CreateSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters);  }### Answer:
@Test public void testDuplicatedCreateSchema() { String schemaName = "test_db"; CreateSchema statement = new CreateSchema(QualifiedName.of(schemaName), false, ImmutableList.of()); getFutureValue(new CreateSchemaTask().internalExecute(statement, metadata, new AllowAllAccessControl(), testSession, emptyList())); assertEquals(metadata.getCreateSchemaCount(), 1); assertThatExceptionOfType(PrestoException.class) .isThrownBy(() -> getFutureValue(new CreateSchemaTask().internalExecute(statement, metadata, new AllowAllAccessControl(), testSession, emptyList()))) .withMessage("Schema already exists"); }
@Test public void testDuplicatedCreateSchemaIfNotExists() { String schemaName = "test_db"; CreateSchema statement = new CreateSchema(QualifiedName.of(schemaName), true, ImmutableList.of()); getFutureValue(new CreateSchemaTask().internalExecute(statement, metadata, new AllowAllAccessControl(), testSession, emptyList())); assertEquals(metadata.getCreateSchemaCount(), 1); getFutureValue(new CreateSchemaTask().internalExecute(statement, metadata, new AllowAllAccessControl(), testSession, emptyList())); assertEquals(metadata.getCreateSchemaCount(), 1); }