DatabaseFreezeServiceImpl extends StateGuardLifecycleSupport implements DatabaseFreezeService, EventAware, EventAware.Asynchronous { @Override public ReadOnlyState getReadOnlyState() { return new DefaultReadOnlyState(getState(), securityHelper.allPermitted(READ_ONLY_PERMISSION)); } @Inject  DatabaseFreezeServiceImpl(final Set<Provider<DatabaseInstance>> providers,
                                   final EventManager eventManager,
                                   final DatabaseFrozenStateManager databaseFrozenStateManager,
                                   final Provider<OServer> server,
                                   final NodeAccess nodeAccess,
                                   final SecurityHelper securityHelper,
                                   final List<Freezable> freezables); @Override @Guarded(by = STARTED) boolean isFrozen(); @Override @Guarded(by = STARTED) void checkUnfrozen(); @Override @Guarded(by = STARTED) void checkUnfrozen(final String message); @Override @Guarded(by = STARTED) synchronized FreezeRequest requestFreeze(final InitiatorType type, final String initiatorId); @Override @Guarded(by = STARTED) List<FreezeRequest> getState(); @Override @Guarded(by = STARTED) synchronized boolean releaseRequest(final FreezeRequest request); @Override @Guarded(by = STARTED) synchronized boolean releaseUserInitiatedIfPresent(); @Override synchronized List<FreezeRequest> releaseAllRequests(); @Override synchronized void freezeLocalDatabases(); @Override synchronized void releaseLocalDatabases(); @Override ReadOnlyState getReadOnlyState(); @Subscribe void onNodeMerged(final NodeMergedEvent event); static final String SERVER_NAME; }
@Test public void getReadOnlyState() { verifyState(underTest.getReadOnlyState(), false, "", false); FreezeRequest request = underTest.requestFreeze(InitiatorType.USER_INITIATED, INITIATOR_ID); verifyState(underTest.getReadOnlyState(), true, "", false); when(securityHelper.allPermitted(any())).thenReturn(true); verifyState(underTest.getReadOnlyState(), true, s -> s.contains("activated by an administrator"), false); when(securityHelper.allPermitted(any())).thenReturn(false); underTest.releaseRequest(request); verifyState(underTest.getReadOnlyState(), false, "", false); underTest.requestFreeze(InitiatorType.SYSTEM, INITIATOR_ID); verifyState(underTest.getReadOnlyState(), true, "", true); when(securityHelper.allPermitted(any())).thenReturn(true); verifyState(underTest.getReadOnlyState(), true, s -> s.contains("activated by 1 running system"), true); when(securityHelper.allPermitted(any())).thenReturn(false); underTest.requestFreeze(InitiatorType.SYSTEM, INITIATOR_ID); verifyState(underTest.getReadOnlyState(), true, "", true); when(securityHelper.allPermitted(any())).thenReturn(true); verifyState(underTest.getReadOnlyState(), true, s -> s.contains("activated by 2 running system"), true); when(securityHelper.allPermitted(any())).thenReturn(false); underTest.releaseAllRequests(); verifyState(underTest.getReadOnlyState(), false, "", false); }