@Override
    public void demote(NodeId instance, DeviceId deviceId) {
        checkNotNull(instance, NODE_ID_NULL);
        checkNotNull(deviceId, DEVICE_ID_NULL);
        checkPermission(CLUSTER_WRITE);

        store.demote(instance, deviceId);
    }
@Test
    public void demote() {
        mgr.setRole(NID1, DID1, MASTER);
        mgr.setRole(NID2, DID1, STANDBY);
        mgr.setRole(NID3, DID1, STANDBY);
        List<NodeId> stdbys = Lists.newArrayList(NID2, NID3);
        MastershipInfo mastershipInfo = mgr.getMastershipFor(DID1);
        assertTrue(mastershipInfo.master().isPresent());
        assertEquals("wrong role", NID1, mastershipInfo.master().get());
        assertEquals("wrong backups", stdbys, mastershipInfo.backups());
        // No effect, it is the master
        mgr.demote(NID1, DID1);
        assertEquals("wrong role", NID1, mastershipInfo.master().get());
        assertEquals("wrong backups", stdbys, mastershipInfo.backups());
        // No effect, it is not part of the mastership
        mgr.demote(NID4, DID1);
        assertEquals("wrong role", NID1, mastershipInfo.master().get());
        assertEquals("wrong backups", stdbys, mastershipInfo.backups());
        // Demote N2
        mgr.demote(NID2, DID1);
        stdbys = Lists.newArrayList(NID3, NID2);
        mastershipInfo = mgr.getMastershipFor(DID1);
        assertEquals("wrong role", NID1, mastershipInfo.master().get());
        assertEquals("wrong backups", stdbys, mastershipInfo.backups());
    }