List of usage examples for java.util.concurrent CompletableFuture completedFuture
public static <U> CompletableFuture<U> completedFuture(U value)
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<List<TableDescriptor>> listTableDescriptors(List<TableName> tableNames) { Preconditions.checkNotNull(tableNames, "tableNames is null. If you don't specify tableNames, " + "use listTables(boolean) instead"); if (tableNames.isEmpty()) { return CompletableFuture.completedFuture(Collections.emptyList()); }/* w w w .j av a 2 s .c o m*/ return getTableDescriptors(RequestConverter.buildGetTableDescriptorsRequest(tableNames)); }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Boolean> isTableEnabled(TableName tableName) { if (TableName.isMetaTableName(tableName)) { return CompletableFuture.completedFuture(true); }/*from ww w. j av a2 s .c o m*/ CompletableFuture<Boolean> future = new CompletableFuture<>(); addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error) -> { if (error != null) { future.completeExceptionally(error); return; } if (state.isPresent()) { future.complete(state.get().inStates(TableState.State.ENABLED)); } else { future.completeExceptionally(new TableNotFoundException(tableName)); } }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Boolean> isTableDisabled(TableName tableName) { if (TableName.isMetaTableName(tableName)) { return CompletableFuture.completedFuture(false); }//w ww. j ava2s. co m CompletableFuture<Boolean> future = new CompletableFuture<>(); addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error) -> { if (error != null) { future.completeExceptionally(error); return; } if (state.isPresent()) { future.complete(state.get().inStates(TableState.State.DISABLED)); } else { future.completeExceptionally(new TableNotFoundException(tableName)); } }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
/** * Get the region info for the passed region name. The region name may be a full region name or * encoded region name. If the region does not found, then it'll throw an UnknownRegionException * wrapped by a {@link CompletableFuture} * @param regionNameOrEncodedRegionName/*from w w w .j ava 2 s .c o m*/ * @return region info, wrapped by a {@link CompletableFuture} */ private CompletableFuture<RegionInfo> getRegionInfo(byte[] regionNameOrEncodedRegionName) { if (regionNameOrEncodedRegionName == null) { return failedFuture(new IllegalArgumentException("Passed region name can't be null")); } if (Bytes.equals(regionNameOrEncodedRegionName, RegionInfoBuilder.FIRST_META_REGIONINFO.getRegionName()) || Bytes.equals(regionNameOrEncodedRegionName, RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes())) { return CompletableFuture.completedFuture(RegionInfoBuilder.FIRST_META_REGIONINFO); } CompletableFuture<RegionInfo> future = new CompletableFuture<>(); addListener(getRegionLocation(regionNameOrEncodedRegionName), (location, err) -> { if (err != null) { future.completeExceptionally(err); } else { future.complete(location.getRegion()); } }); return future; }
From source file:org.apache.james.backends.cassandra.migration.CassandraMigrationServiceTest.java
@Before public void setUp() throws Exception { schemaVersionDAO = mock(CassandraSchemaVersionDAO.class); when(schemaVersionDAO.updateVersion(any())).thenReturn(CompletableFuture.completedFuture(null)); successfulMigration = mock(Migration.class); when(successfulMigration.run()).thenReturn(Migration.Result.COMPLETED); Map<SchemaVersion, Migration> allMigrationClazz = ImmutableMap.<SchemaVersion, Migration>builder() .put(OLDER_VERSION, successfulMigration).put(CURRENT_VERSION, successfulMigration) .put(LATEST_VERSION, successfulMigration).build(); testee = new CassandraMigrationService(schemaVersionDAO, allMigrationClazz, LATEST_VERSION); executorService = Executors.newFixedThreadPool(2, NamedThreadFactory.withClassName(getClass())); }
From source file:org.apache.james.backends.cassandra.migration.CassandraMigrationServiceTest.java
@Test public void getCurrentVersionShouldReturnCurrentVersion() { when(schemaVersionDAO.getCurrentSchemaVersion()) .thenReturn(CompletableFuture.completedFuture(Optional.of(CURRENT_VERSION))); assertThat(testee.getCurrentVersion()).contains(CURRENT_VERSION); }
From source file:org.apache.james.backends.cassandra.migration.CassandraMigrationServiceTest.java
@Test public void upgradeToVersionShouldNotThrowWhenCurrentVersionIsUpToDate() { when(schemaVersionDAO.getCurrentSchemaVersion()) .thenReturn(CompletableFuture.completedFuture(Optional.of(CURRENT_VERSION))); assertThat(testee.upgradeToVersion(OLDER_VERSION).run()).isEqualTo(Task.Result.COMPLETED); }
From source file:org.apache.james.backends.cassandra.migration.CassandraMigrationServiceTest.java
@Test public void upgradeToVersionShouldUpdateToVersion() { when(schemaVersionDAO.getCurrentSchemaVersion()) .thenReturn(CompletableFuture.completedFuture(Optional.of(OLDER_VERSION))); testee.upgradeToVersion(CURRENT_VERSION).run(); verify(schemaVersionDAO, times(1)).updateVersion(eq(CURRENT_VERSION)); }
From source file:org.apache.james.backends.cassandra.migration.CassandraMigrationServiceTest.java
@Test public void upgradeToLastVersionShouldNotThrowWhenVersionIsUpToDate() { when(schemaVersionDAO.getCurrentSchemaVersion()) .thenReturn(CompletableFuture.completedFuture(Optional.of(LATEST_VERSION))); assertThat(testee.upgradeToLastVersion().run()).isEqualTo(Task.Result.COMPLETED); }
From source file:org.apache.james.backends.cassandra.migration.CassandraMigrationServiceTest.java
@Test public void upgradeToLastVersionShouldUpdateToLatestVersion() { when(schemaVersionDAO.getCurrentSchemaVersion()) .thenReturn(CompletableFuture.completedFuture(Optional.of(OLDER_VERSION))); testee.upgradeToLastVersion().run(); verify(schemaVersionDAO, times(1)).updateVersion(eq(LATEST_VERSION)); }