Repository: apache/kafka
File: streams/src/test/java/org/apache/kafka/streams/state/internals/MeteredSessionStoreTest.java (Java)

Code before:
        init();

        final KeyValueIterator<Windowed<String>, String> iterator = store.findSessions(KEY, KEY, systemTime - RETENTION_PERIOD, systemTime);
        assertFalse(iterator.hasNext());
        iterator.close();
    }

    @Test
    public void shouldNotFindExpiredSessionRangeInBackwardOrderFromStore() {
        setUp();
        final long systemTime = Time.SYSTEM.milliseconds();
        when(innerStore.backwardFindSessions(KEY_BYTES, KEY_BYTES, systemTime - RETENTION_PERIOD, systemTime))
                .thenReturn(new KeyValueIteratorStub<>(KeyValueIterators.emptyIterator()));
        init();

        final KeyValueIterator<Windowed<String>, String> iterator = store.backwardFindSessions(KEY, KEY, systemTime - RETENTION_PERIOD, systemTime);
        assertFalse(iterator.hasNext());
        iterator.close();
    }

    @Test
    public void shouldRecordRestoreLatencyOnRecordRestoreTime() {
        setUp();
        init();

        final long restoreTimeNs = 1000;
        store.recordRestoreTime(restoreTimeNs);

        // it suffices to verify one restore metric since all restore metrics are recorded by the same sensor
        // and the sensor is tested elsewhere
        final KafkaMetric metric = metric("restore-rate");
        assertTrue((Double) metric.metricValue() > 0);
    }

    @Test
    public void shouldNotThrowNullPointerExceptionIfFetchSessionReturnsNull() {
        setUp();
        when(innerStore.fetchSession(Bytes.wrap("a".getBytes()), 0, Long.MAX_VALUE)).thenReturn(null);

        init();
        assertNull(store.fetchSession("a", 0, Long.MAX_VALUE));
    }

    @Test
    public void shouldThrowNullPointerOnPutIfKeyIsNull() {
        setUpWithoutContext();
        assertThrows(NullPointerException.class, () -> store.put(null, "a"));
    }

    @Test
    public void shouldThrowNullPointerOnRemoveIfKeyIsNull() {

Review comment (suggestion):
```suggestion
        final long restoreTimeNs = 1000L;
```

Code after:
        init();

        final KeyValueIterator<Windowed<String>, String> iterator = store.findSessions(KEY, KEY, systemTime - RETENTION_PERIOD, systemTime);
        assertFalse(iterator.hasNext());
        iterator.close();
    }

    @Test
    public void shouldNotFindExpiredSessionRangeInBackwardOrderFromStore() {
        setUp();
        final long systemTime = Time.SYSTEM.milliseconds();
        when(innerStore.backwardFindSessions(KEY_BYTES, KEY_BYTES, systemTime - RETENTION_PERIOD, systemTime))
                .thenReturn(new KeyValueIteratorStub<>(KeyValueIterators.emptyIterator()));
        init();

        final KeyValueIterator<Windowed<String>, String> iterator = store.backwardFindSessions(KEY, KEY, systemTime - RETENTION_PERIOD, systemTime);
        assertFalse(iterator.hasNext());
        iterator.close();
    }

    @Test
    public void shouldRecordRestoreLatencyOnRecordRestoreTime() {
        setUp();
        init();

        final long restoreTimeNs = 1000L;
        store.recordRestoreTime(restoreTimeNs);

        // it suffices to verify one restore metric since all restore metrics are recorded by the same sensor
        // and the sensor is tested elsewhere
        final KafkaMetric metric = metric("restore-latency-max");
        assertThat((Double) metric.metricValue(), equalTo((double) restoreTimeNs));
    }

    @Test
    public void shouldNotThrowNullPointerExceptionIfFetchSessionReturnsNull() {
        setUp();
        when(innerStore.fetchSession(Bytes.wrap("a".getBytes()), 0, Long.MAX_VALUE)).thenReturn(null);

        init();
        assertNull(store.fetchSession("a", 0, Long.MAX_VALUE));
    }

    @Test
    public void shouldThrowNullPointerOnPutIfKeyIsNull() {
        setUpWithoutContext();
        assertThrows(NullPointerException.class, () -> store.put(null, "a"));
    }

    @Test
    public void shouldThrowNullPointerOnRemoveIfKeyIsNull() {