<commit_before>/*
 * Licensed to the University of California, Berkeley under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package tachyon.master.next.block.meta;

import java.util.List;
import java.util.Set;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import tachyon.Constants;
import tachyon.thrift.NetAddress;
import tachyon.thrift.WorkerInfo;

/**
 * Unit tests for MasterWorkerInfo.
 */
public final class MasterWorkerInfoTest {
  private MasterWorkerInfo mInfo;
  private static final List<Long> TOTAL_BYTES_ON_TIERS =
      Lists.newArrayList(Constants.KB * 3L, Constants.KB * 3L);
  private static final List<Long> USED_BYTES_ON_TIERS =
      Lists.newArrayList(Constants.KB * 1L, Constants.KB * 1L);
  private static final Set<Long> NEW_BLOCKS = Sets.newHashSet(1L, 2L);

  @Before
  public void before() {
    // register
    mInfo = new MasterWorkerInfo(0, new NetAddress());
    mInfo.register(TOTAL_BYTES_ON_TIERS, USED_BYTES_ON_TIERS, NEW_BLOCKS);
  }

  @Test
  public void registerTest() {
    Assert.assertEquals(NEW_BLOCKS, mInfo.getBlocks());
    Assert.assertEquals(TOTAL_BYTES_ON_TIERS, mInfo.getTotalBytesOnTiers());
    Assert.assertEquals(Constants.KB * 6L, mInfo.getCapacityBytes());
    Assert.assertEquals(USED_BYTES_ON_TIERS, mInfo.getUsedBytesOnTiers());
    Assert.assertEquals(Constants.KB * 2L, mInfo.getUsedBytes());
  }

  @Test
  public void registerAgainTest() {
    Set<Long> newBlocks = Sets.newHashSet(3L);
    Set<Long> removedBlocks = mInfo.register(TOTAL_BYTES_ON_TIERS, USED_BYTES_ON_TIERS, newBlocks);
    Assert.assertEquals(NEW_BLOCKS, removedBlocks);
    Assert.assertEquals(newBlocks, mInfo.getBlocks());
  }

  @Test
  public void blockOperationTest() {
    // add existing block
    mInfo.addBlock(1L);
    Assert.assertEquals(NEW_BLOCKS, mInfo.getBlocks());
    // add a new block
    mInfo.addBlock(3L);
    Assert.assertTrue(mInfo.getBlocks().contains(3L));
    // remove block
    mInfo.removeBlock(3L);
    Assert.assertFalse(mInfo.getBlocks().contains(3L));
  }

  @Test
  public void workerInfoGenerationTest() {
    WorkerInfo workerInfo = mInfo.generateClientWorkerInfo();
    Assert.assertEquals(mInfo.getId(), workerInfo.id);
    Assert.assertEquals(mInfo.getAddress(), workerInfo.address);
    Assert.assertEquals("In Service", workerInfo.state);
    Assert.assertEquals(mInfo.getCapacityBytes(), workerInfo.capacityBytes);
    Assert.assertEquals(mInfo.getUsedBytes(), workerInfo.usedBytes);
    Assert.assertEquals(mInfo.getStartTime(), workerInfo.starttimeMs);
  }

  @Test
  public void getFreeBytesOnTiersTest() {
    Assert.assertEquals(Lists.newArrayList(Constants.KB * 2L, Constants.KB * 2L),
        mInfo.getFreeBytesOnTiers());
  }
}<commit_msg>Added test case for updateToRemovedBlock<commit_after>/*
 * Licensed to the University of California, Berkeley under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for additional information regarding
 * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package tachyon.master.next.block.meta;

import java.util.List;
import java.util.Set;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import tachyon.Constants;
import tachyon.thrift.NetAddress;
import tachyon.thrift.WorkerInfo;

/**
 * Unit tests for MasterWorkerInfo.
 */
public final class MasterWorkerInfoTest {
  private MasterWorkerInfo mInfo;
  private static final List<Long> TOTAL_BYTES_ON_TIERS =
      Lists.newArrayList(Constants.KB * 3L, Constants.KB * 3L);
  private static final List<Long> USED_BYTES_ON_TIERS =
      Lists.newArrayList(Constants.KB * 1L, Constants.KB * 1L);
  private static final Set<Long> NEW_BLOCKS = Sets.newHashSet(1L, 2L);

  @Before
  public void before() {
    // register
    mInfo = new MasterWorkerInfo(0, new NetAddress());
    mInfo.register(TOTAL_BYTES_ON_TIERS, USED_BYTES_ON_TIERS, NEW_BLOCKS);
  }

  @Test
  public void registerTest() {
    Assert.assertEquals(NEW_BLOCKS, mInfo.getBlocks());
    Assert.assertEquals(TOTAL_BYTES_ON_TIERS, mInfo.getTotalBytesOnTiers());
    Assert.assertEquals(Constants.KB * 6L, mInfo.getCapacityBytes());
    Assert.assertEquals(USED_BYTES_ON_TIERS, mInfo.getUsedBytesOnTiers());
    Assert.assertEquals(Constants.KB * 2L, mInfo.getUsedBytes());
  }

  @Test
  public void registerAgainTest() {
    Set<Long> newBlocks = Sets.newHashSet(3L);
    Set<Long> removedBlocks = mInfo.register(TOTAL_BYTES_ON_TIERS, USED_BYTES_ON_TIERS, newBlocks);
    Assert.assertEquals(NEW_BLOCKS, removedBlocks);
    Assert.assertEquals(newBlocks, mInfo.getBlocks());
  }

  @Test
  public void blockOperationTest() {
    // add existing block
    mInfo.addBlock(1L);
    Assert.assertEquals(NEW_BLOCKS, mInfo.getBlocks());
    // add a new block
    mInfo.addBlock(3L);
    Assert.assertTrue(mInfo.getBlocks().contains(3L));
    // remove block
    mInfo.removeBlock(3L);
    Assert.assertFalse(mInfo.getBlocks().contains(3L));
  }

  @Test
  public void workerInfoGenerationTest() {
    WorkerInfo workerInfo = mInfo.generateClientWorkerInfo();
    Assert.assertEquals(mInfo.getId(), workerInfo.id);
    Assert.assertEquals(mInfo.getAddress(), workerInfo.address);
    Assert.assertEquals("In Service", workerInfo.state);
    Assert.assertEquals(mInfo.getCapacityBytes(), workerInfo.capacityBytes);
    Assert.assertEquals(mInfo.getUsedBytes(), workerInfo.usedBytes);
    Assert.assertEquals(mInfo.getStartTime(), workerInfo.starttimeMs);
  }

  @Test
  public void getFreeBytesOnTiersTest() {
    Assert.assertEquals(Lists.newArrayList(Constants.KB * 2L, Constants.KB * 2L),
        mInfo.getFreeBytesOnTiers());
  }

  @Test
  public void updateToRemovedBlockTest() {
    // remove a non-existing block
    mInfo.updateToRemovedBlock(true, 10L);
    Assert.assertTrue(mInfo.getToRemoveBlocks().isEmpty());
    // remove block 1
    mInfo.updateToRemovedBlock(true, 1L);
    Assert.assertTrue(mInfo.getToRemoveBlocks().contains(1L));
    // cancel the removal
    mInfo.updateToRemovedBlock(false, 1L);
    Assert.assertTrue(mInfo.getToRemoveBlocks().isEmpty());
    // actually remove 1 for real
    mInfo.updateToRemovedBlock(true, 1L);
    mInfo.removeBlock(1L);
    Assert.assertTrue(mInfo.getToRemoveBlocks().isEmpty());
  }
}
{'fraction_non_alphanumeric': 0.10511215440792905, 'fraction_numerical': 0.006651017214397496, 'mean_word_length': 4.501434720229555, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3112715', 'n_tokens_mistral': 2373, 'n_tokens_neox': 2299, 'n_words': 566}