<commit_before>/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.worker.block;

import alluxio.AbstractClient;
import alluxio.Constants;
import alluxio.exception.ExceptionMessage;
import alluxio.thrift.AlluxioService;
import alluxio.thrift.AlluxioService.Client;
import alluxio.thrift.BlockMasterClientService;

import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import java.io.IOException;
import java.net.InetSocketAddress;

/**
 * Unit tests for {@link AbstractClient}.
 */
public final class AbstractClientTest {
  private static final String SERVICE_NAME = "Test Service Name";
  private static final int CLIENT_SERVICE_VERSION = 1;

  private final class TestClient extends AbstractClient {
    private TestClient() {
      super(Mockito.mock(InetSocketAddress.class), "");
    }

    @Override
    protected Client getClient() {
      return null;
    }

    @Override
    protected String getServiceName() {
      return SERVICE_NAME;
    }

    @Override
    protected long getServiceVersion() {
      return CLIENT_SERVICE_VERSION;
    }

    public void checkVersion(AlluxioService.Client thriftClient) throws IOException {
      checkVersion(thriftClient, Constants.BLOCK_MASTER_CLIENT_SERVICE_VERSION);
    }
  }

  /**
   * Tests for an unsupported version.
   */
  @Test
  public void unsupportedVersionTest() throws Exception {
    final BlockMasterClientService.Client thriftClient =
        Mockito.mock(BlockMasterClientService.Client.class);
    Mockito.when(thriftClient.getServiceVersion()).thenReturn(0L);

    try (TestClient client = new TestClient()) {
      client.checkVersion(thriftClient);
      Assert.fail("checkVersion() should fail");
    } catch (IOException e) {
      Assert.assertEquals(ExceptionMessage.INCOMPATIBLE_VERSION.getMessage(SERVICE_NAME,
          CLIENT_SERVICE_VERSION, 0), e.getMessage());
    }
  }
}<commit_msg>Clean up AbstractClientTest<commit_after>/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.worker.block;

import alluxio.AbstractClient;
import alluxio.exception.ExceptionMessage;
import alluxio.thrift.AlluxioService;
import alluxio.thrift.AlluxioService.Client;

import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import java.io.IOException;
import java.net.InetSocketAddress;

/**
 * Unit tests for {@link AbstractClient}.
 */
public final class AbstractClientTest {
  private static final String SERVICE_NAME = "Test Service Name";

  private final class TestClient extends AbstractClient {
    private TestClient() {
      super(Mockito.mock(InetSocketAddress.class), "");
    }

    @Override
    protected Client getClient() {
      return null;
    }

    @Override
    protected String getServiceName() {
      return SERVICE_NAME;
    }

    @Override
    protected long getServiceVersion() {
      return 1;
    }

    public void checkVersion(AlluxioService.Client thriftClient, long version) throws IOException {
      super.checkVersion(thriftClient, version);
    }
  }

  @Test
  public void unsupportedVersion() throws Exception {
    final AlluxioService.Client thriftClient = Mockito.mock(AlluxioService.Client.class);
    Mockito.when(thriftClient.getServiceVersion()).thenReturn(1L);

    try (TestClient client = new TestClient()) {
      client.checkVersion(thriftClient, 0);
      Assert.fail("checkVersion() should fail");
    } catch (IOException e) {
      Assert.assertEquals(ExceptionMessage.INCOMPATIBLE_VERSION.getMessage(SERVICE_NAME, 0, 1),
          e.getMessage());
    }
  }

  @Test
  public void supportedVersion() throws Exception {
    final AlluxioService.Client thriftClient = Mockito.mock(AlluxioService.Client.class);
    Mockito.when(thriftClient.getServiceVersion()).thenReturn(1L);

    try (TestClient client = new TestClient()) {
      client.checkVersion(thriftClient, 1);
    }
  }
}
{'fraction_non_alphanumeric': 0.08792350862606527, 'fraction_numerical': 0.003741425898981501, 'mean_word_length': 4.007284079084287, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5397139', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1320, 'n_words': 384}