View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.hadoop.hbase.quotas;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.hadoop.hbase.TableName;
25  import org.apache.hadoop.hbase.client.Connection;
26  
27  /**
28   * A SpaceQuotaViolationNotifier implementation for verifying testing.
29   */
30  public class SpaceQuotaSnapshotNotifierForTest implements SpaceQuotaSnapshotNotifier {
31    private static final Log LOG = LogFactory.getLog(SpaceQuotaSnapshotNotifierForTest.class);
32  
33    private final Map<TableName,SpaceQuotaSnapshot> tableQuotaSnapshots = new HashMap<>();
34  
35    @Override
36    public void initialize(Connection conn) {}
37  
38    @Override
39    public synchronized void transitionTable(TableName tableName, SpaceQuotaSnapshot snapshot) {
40      if (LOG.isTraceEnabled()) {
41        LOG.trace("Persisting " + tableName + "=>" + snapshot);
42      }
43      tableQuotaSnapshots.put(tableName, snapshot);
44    }
45  
46    public synchronized Map<TableName,SpaceQuotaSnapshot> copySnapshots() {
47      return new HashMap<>(this.tableQuotaSnapshots);
48    }
49  
50    public synchronized void clearSnapshots() {
51      this.tableQuotaSnapshots.clear();
52    }
53  }