PrecomputedJoinStorageSupplier implements Supplier<PrecomputedJoinStorage> { @Override public PrecomputedJoinStorage get() { final Configuration config = configSupplier.get(); checkNotNull(config, "Could not build the PrecomputedJoinStorage until the PrecomputedJoinIndexer has been configured."); final PrecomputedJoinIndexerConfig indexerConfig = new PrecomputedJoinIndexerConfig(config); final Optional<PrecomputedJoinStorageType> storageType = indexerConfig.getPcjStorageType(); checkArgument(storageType.isPresent(), "The '" + PrecomputedJoinIndexerConfig.PCJ_STORAGE_TYPE + "' property must have one of the following values: " + Arrays.toString(PrecomputedJoinStorageType.values())); switch(storageType.get()) { case ACCUMULO: return accumuloSupplier.get(); default: throw new IllegalArgumentException("Unsupported PrecomputedJoinStorageType: " + storageType.get()); } } PrecomputedJoinStorageSupplier(
            final Supplier<Configuration> configSupplier,
            final AccumuloPcjStorageSupplier accumuloSupplier); @Override PrecomputedJoinStorage get();  }
@Test(expected = NullPointerException.class) public void notConfigured() { final Supplier<Configuration> configSupplier = mock(Supplier.class); final PrecomputedJoinStorageSupplier storageSupplier = new PrecomputedJoinStorageSupplier(configSupplier, mock(AccumuloPcjStorageSupplier.class)); storageSupplier.get(); }
@Test(expected = IllegalArgumentException.class) public void storageTypeNotSet() { final Supplier<Configuration> configSupplier = mock(Supplier.class); when(configSupplier.get()).thenReturn( new Configuration() ); final PrecomputedJoinStorageSupplier storageSupplier = new PrecomputedJoinStorageSupplier(configSupplier, mock(AccumuloPcjStorageSupplier.class)); storageSupplier.get(); }
@Test public void configuredForAccumulo() { final Supplier<Configuration> configSupplier = mock(Supplier.class); final Configuration config = new Configuration(); config.set(PrecomputedJoinIndexerConfig.PCJ_STORAGE_TYPE, PrecomputedJoinStorageType.ACCUMULO.toString()); when(configSupplier.get()).thenReturn( config ); final AccumuloPcjStorageSupplier accumuloSupplier = mock(AccumuloPcjStorageSupplier.class); final AccumuloPcjStorage mockAccumuloStorage = mock(AccumuloPcjStorage.class); when(accumuloSupplier.get()).thenReturn(mockAccumuloStorage); final PrecomputedJoinStorageSupplier storageSupplier = new PrecomputedJoinStorageSupplier(configSupplier, accumuloSupplier); final PrecomputedJoinStorage storage = storageSupplier.get(); assertEquals(mockAccumuloStorage, storage); }