@@ -0,0 +1,3305 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage org.apache.rocketmq.client.consumer.store;%0A%0Aimport java.util.Collections;%0Aimport java.util.HashSet;%0Aimport org.apache.rocketmq.client.ClientConfig;%0Aimport org.apache.rocketmq.client.impl.factory.MQClientInstance;%0Aimport org.apache.rocketmq.common.message.MessageQueue;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0Aimport org.mockito.Mock;%0Aimport org.mockito.Mockito;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0Aimport static org.mockito.Mockito.when;%0A%0Apublic class LocalFileOffsetStoreTest %7B%0A%0A    @Mock%0A    private static MQClientInstance mQClientFactory;%0A    private static String group = %22FooBarGroup%22;%0A    private static String topic = %22FooBar%22;%0A    private static String brokerName = %22DefaultBrokerName%22;%0A%0A    @BeforeClass%0A    public static void init() %7B%0A        System.setProperty(%22rocketmq.client.localOffsetStoreDir%22, System.getProperty(%22java.io.tmpdir%22) + %22.rocketmq_offsets%22);%0A        mQClientFactory = Mockito.mock(MQClientInstance.class);%0A        String clientId = new ClientConfig().buildMQClientId() + %22#TestNamespace%22 + System.currentTimeMillis();%0A        when(mQClientFactory.getClientId()).thenReturn(clientId);%0A    %7D%0A%0A    @Test%0A    public void testUpdateOffset() throws Exception %7B%0A        OffsetStore offsetStore = new LocalFileOffsetStore(mQClientFactory, group);%0A        MessageQueue messageQueue = new MessageQueue(topic, brokerName, 1);%0A        offsetStore.updateOffset(messageQueue, 1024, false);%0A%0A        assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_MEMORY)).isEqualTo(1024);%0A%0A        offsetStore.updateOffset(messageQueue, 1023, false);%0A        assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_MEMORY)).isEqualTo(1023);%0A%0A        offsetStore.updateOffset(messageQueue, 1022, true);%0A        assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_MEMORY)).isEqualTo(1023);%0A    %7D%0A%0A    @Test%0A    public void testReadOffset_FromStore() throws Exception %7B%0A        OffsetStore offsetStore = new LocalFileOffsetStore(mQClientFactory, group);%0A        MessageQueue messageQueue = new MessageQueue(topic, brokerName, 2);%0A%0A        offsetStore.updateOffset(messageQueue, 1024, false);%0A        assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(-1);%0A%0A        offsetStore.persistAll(new HashSet%3C%3E(Collections.singletonList(messageQueue)));%0A        assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1024);%0A    %7D%0A%7D

Add unit tests for LocalFileOffsetStore