001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to you under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.hadoop.hbase.quotas;
018
019import java.util.HashMap;
020import java.util.Map;
021
022import org.apache.hadoop.hbase.TableName;
023import org.apache.yetus.audience.InterfaceAudience;
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026import org.apache.hadoop.hbase.client.Connection;
027
028/**
029 * A SpaceQuotaSnapshotNotifier implementation for testing.
030 */
031@InterfaceAudience.Private
032public class SpaceQuotaSnapshotNotifierForTest implements SpaceQuotaSnapshotNotifier {
033  private static final Logger LOG =
034      LoggerFactory.getLogger(SpaceQuotaSnapshotNotifierForTest.class);
035
036  private final Map<TableName,SpaceQuotaSnapshot> tableQuotaSnapshots = new HashMap<>();
037
038  @Override
039  public void initialize(Connection conn) {}
040
041  @Override
042  public synchronized void transitionTable(TableName tableName, SpaceQuotaSnapshot snapshot) {
043    if (LOG.isTraceEnabled()) {
044      LOG.trace("Persisting " + tableName + "=>" + snapshot);
045    }
046    tableQuotaSnapshots.put(tableName, snapshot);
047  }
048
049  public synchronized Map<TableName,SpaceQuotaSnapshot> copySnapshots() {
050    return new HashMap<>(this.tableQuotaSnapshots);
051  }
052
053  public synchronized void clearSnapshots() {
054    this.tableQuotaSnapshots.clear();
055  }
056}