private LocalWaveletContainer getLocalWavelet(WaveletName waveletName) throws WaveletStateException { Preconditions.checkArgument(isLocalWavelet(waveletName), "%s is not local", waveletName); return waveMap.getLocalWavelet(waveletName); }
/** * Tries to fetch the wavelet as remote, if not found - fetches as local * wavelet. * * @param waveletName the wavelet name * @return the local or remote wavelet. * @throws WaveletStateException if something goes wrong */ public WaveletContainer getWavelet(WaveletName waveletName) throws WaveletStateException { WaveletContainer waveletContainer = null; try { waveletContainer = getRemoteWavelet(waveletName); } catch (WaveletStateException | NullPointerException e) { // Ignored. } if (waveletContainer == null) { waveletContainer = getLocalWavelet(waveletName); } return waveletContainer; }
/** * Returns a generic wavelet container, when the caller doesn't need to validate whether * its a local or remote wavelet. * * @param waveletName name of wavelet. * @return an wavelet container or null if it doesn't exist. * @throw WaveServerException if storage lookup fails */ private WaveletContainer getWavelet(WaveletName waveletName) throws WaveServerException { return isLocalWavelet(waveletName) ? waveMap.getLocalWavelet(waveletName) : waveMap.getRemoteWavelet(waveletName); }
public void testGetOrCreateCreatesWavelets() throws WaveletStateException, PersistenceException { when(waveletStore.lookup(WAVE_ID)).thenReturn(ImmutableSet.<WaveletId>of()); LocalWaveletContainer wavelet = waveMap.getOrCreateLocalWavelet(WAVELET_NAME); assertSame(wavelet, waveMap.getLocalWavelet(WAVELET_NAME)); }
public void testGetOrCreateCreatesWavelets() throws WaveletStateException, PersistenceException { when(waveletStore.lookup(WAVE_ID)).thenReturn(ImmutableSet.<WaveletId>of()); LocalWaveletContainer wavelet = waveMap.getOrCreateLocalWavelet(WAVELET_NAME); assertSame(wavelet, waveMap.getLocalWavelet(WAVELET_NAME)); }
public void testWaveletAvailableAfterLoad() throws WaveletStateException, PersistenceException { when(waveletStore.getWaveIdIterator()).thenReturn(eitr(WAVE_ID)); when(waveletStore.lookup(WAVE_ID)).thenReturn(ImmutableSet.<WaveletId>of(WAVELET_ID)); waveMap.loadAllWavelets(); assertNotNull(waveMap.getLocalWavelet(WAVELET_NAME)); }
public void testWaveletAvailableAfterLoad() throws WaveletStateException, PersistenceException { when(waveletStore.getWaveIdIterator()).thenReturn(eitr(WAVE_ID)); when(waveletStore.lookup(WAVE_ID)).thenReturn(ImmutableSet.<WaveletId>of(WAVELET_ID)); waveMap.loadAllWavelets(); assertNotNull(waveMap.getLocalWavelet(WAVELET_NAME)); }
public void testWavesStartWithNoWavelets() throws WaveletStateException, PersistenceException { when(waveletStore.lookup(WAVE_ID)).thenReturn(ImmutableSet.<WaveletId>of()); assertNull(waveMap.getLocalWavelet(WAVELET_NAME)); assertNull(waveMap.getRemoteWavelet(WAVELET_NAME)); }
public void testWavesStartWithNoWavelets() throws WaveletStateException, PersistenceException { when(waveletStore.lookup(WAVE_ID)).thenReturn(ImmutableSet.<WaveletId>of()); assertNull(waveMap.getLocalWavelet(WAVELET_NAME)); assertNull(waveMap.getRemoteWavelet(WAVELET_NAME)); }
@Override protected void setUp() throws Exception { super.setUp(); LocalWaveletContainer.Factory localFactory = mock(LocalWaveletContainer.Factory.class); WaveletNotificationSubscriber notifiee = mock(WaveletNotificationSubscriber.class); SettableFuture<ImmutableSet<WaveletId>> lookedupWavelets = SettableFuture.create(); lookedupWavelets.set(ImmutableSet.of(WAVELET_NAME.waveletId)); Wave wave = new Wave(WAVELET_NAME.waveId, lookedupWavelets, notifiee, localFactory, null, WAVELET_NAME.waveId.getDomain()); Map<WaveId, Wave> waves = Maps.newHashMap(); waves.put(WAVELET_NAME.waveId, wave); when(waveMap.getWaves()).thenReturn(waves); ImmutableSet<WaveletId> wavelets = ImmutableSet.of(WAVELET_NAME.waveletId); when(waveMap.lookupWavelets(WAVELET_NAME.waveId)).thenReturn(wavelets); LocalWaveletContainer c = mock(LocalWaveletContainer.class); when(c.hasParticipant(PARTICIPANT)).thenReturn(true); when(waveMap.getLocalWavelet(WAVELET_NAME)).thenReturn(c); }
@Override protected void setUp() throws Exception { super.setUp(); LocalWaveletContainer.Factory localFactory = mock(LocalWaveletContainer.Factory.class); WaveletNotificationSubscriber notifiee = mock(WaveletNotificationSubscriber.class); SettableFuture<ImmutableSet<WaveletId>> lookedupWavelets = SettableFuture.create(); lookedupWavelets.set(ImmutableSet.of(WAVELET_NAME.waveletId)); Wave wave = new Wave(WAVELET_NAME.waveId, lookedupWavelets, notifiee, localFactory, null, WAVELET_NAME.waveId.getDomain()); Map<WaveId, Wave> waves = Maps.newHashMap(); waves.put(WAVELET_NAME.waveId, wave); when(waveMap.getWaves()).thenReturn(waves); ImmutableSet<WaveletId> wavelets = ImmutableSet.of(WAVELET_NAME.waveletId); when(waveMap.lookupWavelets(WAVELET_NAME.waveId)).thenReturn(wavelets); LocalWaveletContainer c = mock(LocalWaveletContainer.class); when(c.hasParticipant(PARTICIPANT)).thenReturn(true); when(waveMap.getLocalWavelet(WAVELET_NAME)).thenReturn(c); }