<commit_before>/*
 * Copyright 2022 LinkedIn Corp. All rights reserved.
 *
 * Licensed 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.
 */
package com.github.ambry.quota;

import com.codahale.metrics.MetricRegistry;
import com.github.ambry.account.Account;
import com.github.ambry.account.InMemAccountService;
import com.github.ambry.config.QuotaConfig;
import com.github.ambry.config.VerifiableProperties;
import com.github.ambry.messageformat.BlobInfo;
import com.github.ambry.messageformat.BlobProperties;
import com.github.ambry.quota.capacityunit.AmbryCUQuotaEnforcer;
import com.github.ambry.rest.RestMethod;
import com.github.ambry.rest.RestRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;


/**
 * Tests for {@link AmbryQuotaManager} and {@link AtomicAmbryQuotaManager}.
 */
@RunWith(Parameterized.class)
public class AmbryQuotaManagerTest {
  private final static InMemAccountService ACCOUNT_SERVICE = new InMemAccountService(false, true);
  private final static Account ACCOUNT = ACCOUNT_SERVICE.createAndAddRandomAccount(QuotaResourceType.ACCOUNT);
  private final static Account ANOTHER_ACCOUNT = ACCOUNT_SERVICE.createAndAddRandomAccount(QuotaResourceType.ACCOUNT);
  private final static BlobInfo BLOB_INFO = new BlobInfo(
      new BlobProperties(2, "test", ACCOUNT.getId(), ACCOUNT.getAllContainers().iterator().next().getId(), false),
      new byte[2]);
  private final TestCUQuotaEnforcerFactory.TestQuotaRecommendationMergePolicy testQuotaRecommendationMergePolicy =
      new TestCUQuotaEnforcerFactory.TestQuotaRecommendationMergePolicy(
          new QuotaConfig(new VerifiableProperties(new Properties())));
  private final boolean isAtomic;
  private TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer testAmbryCUQuotaEnforcer;
  private QuotaConfig quotaConfig;

  /**
   * Constructor for {@link AmbryQuotaManagerTest}.
   * @param isAtomic flag. If set to {@code true} {@link AtomicAmbryQuotaManager} is tested.
   *                 Otherwise {@link AmbryQuotaManager} is tested.
   */
  public AmbryQuotaManagerTest(boolean isAtomic) {
    this.isAtomic = isAtomic;
    TestCUQuotaEnforcerFactory.TestQuotaRecommendationMergePolicy.quotaRecommendationsCount = 0;
  }

  /**
   * Running for both {@link AmbryQuotaManager} as well as {@link AtomicAmbryQuotaManager}.<commit_msg>Remove unused variable from AmbryQuotaManagerTest. (#2062)<commit_after>/*
 * Copyright 2022 LinkedIn Corp. All rights reserved.
 *
 * Licensed 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.
 */
package com.github.ambry.quota;

import com.codahale.metrics.MetricRegistry;
import com.github.ambry.account.Account;
import com.github.ambry.account.InMemAccountService;
import com.github.ambry.config.QuotaConfig;
import com.github.ambry.config.VerifiableProperties;
import com.github.ambry.quota.capacityunit.AmbryCUQuotaEnforcer;
import com.github.ambry.rest.RestMethod;
import com.github.ambry.rest.RestRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;


/**
 * Tests for {@link AmbryQuotaManager} and {@link AtomicAmbryQuotaManager}.
 */
@RunWith(Parameterized.class)
public class AmbryQuotaManagerTest {
  private final static InMemAccountService ACCOUNT_SERVICE = new InMemAccountService(false, true);
  private final static Account ACCOUNT = ACCOUNT_SERVICE.createAndAddRandomAccount(QuotaResourceType.ACCOUNT);
  private final static Account ANOTHER_ACCOUNT = ACCOUNT_SERVICE.createAndAddRandomAccount(QuotaResourceType.ACCOUNT);
  private final TestCUQuotaEnforcerFactory.TestQuotaRecommendationMergePolicy testQuotaRecommendationMergePolicy =
      new TestCUQuotaEnforcerFactory.TestQuotaRecommendationMergePolicy(
          new QuotaConfig(new VerifiableProperties(new Properties())));
  private final boolean isAtomic;
  private TestCUQuotaEnforcerFactory.TestAmbryCUQuotaEnforcer testAmbryCUQuotaEnforcer;
  private QuotaConfig quotaConfig;

  /**
   * Constructor for {@link AmbryQuotaManagerTest}.
   * @param isAtomic flag. If set to {@code true} {@link AtomicAmbryQuotaManager} is tested.
   *                 Otherwise {@link AmbryQuotaManager} is tested.
   */
  public AmbryQuotaManagerTest(boolean isAtomic) {
    this.isAtomic = isAtomic;
    TestCUQuotaEnforcerFactory.TestQuotaRecommendationMergePolicy.quotaRecommendationsCount = 0;
  }

  /**
   * Running for both {@link AmbryQuotaManager} as well as {@link AtomicAmbryQuotaManager}.
{'fraction_non_alphanumeric': 0.0861244019138756, 'fraction_numerical': 0.004101161995898838, 'mean_word_length': 5.3207343412527, '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': '4942397', 'n_tokens_mistral': 1750, 'n_tokens_neox': 1706, 'n_words': 437}