@Override
    public void onPartitionChangeMsg(TbContext ctx, PartitionChangeMsg msg) {
        rateLimits.entrySet().removeIf(entry -> !ctx.isLocalEntity(entry.getKey()));
    }
@Test
    public void givenHasNonLocalDevices_whenOnPartitionChange_thenRemovesEntriesForNonLocalDevices() {
        // GIVEN
        ConcurrentReferenceHashMap<DeviceId, TbRateLimits> rateLimits = new ConcurrentReferenceHashMap<>();
        ReflectionTestUtils.setField(node, "rateLimits", rateLimits);

        rateLimits.put(DEVICE_ID, new TbRateLimits("1:1"));
        given(ctxMock.isLocalEntity(eq(DEVICE_ID))).willReturn(true);

        DeviceId nonLocalDeviceId1 = new DeviceId(UUID.randomUUID());
        rateLimits.put(nonLocalDeviceId1, new TbRateLimits("2:2"));
        given(ctxMock.isLocalEntity(eq(nonLocalDeviceId1))).willReturn(false);

        DeviceId nonLocalDeviceId2 = new DeviceId(UUID.randomUUID());
        rateLimits.put(nonLocalDeviceId2, new TbRateLimits("3:3"));
        given(ctxMock.isLocalEntity(eq(nonLocalDeviceId2))).willReturn(false);

        // WHEN
        node.onPartitionChangeMsg(ctxMock, new PartitionChangeMsg(ServiceType.TB_RULE_ENGINE));

        // THEN
        assertThat(rateLimits)
                .containsKey(DEVICE_ID)
                .doesNotContainKey(nonLocalDeviceId1)
                .doesNotContainKey(nonLocalDeviceId2)
                .size().isOne();
    }