View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.omid.transaction;
19  
20  import org.apache.phoenix.thirdparty.com.google.common.base.Preconditions;
21  import com.google.inject.AbstractModule;
22  import com.google.inject.Provider;
23  import com.google.inject.Provides;
24  import org.apache.omid.committable.CommitTable;
25  import org.apache.omid.committable.hbase.HBaseCommitTable;
26  import org.apache.omid.metrics.MetricsRegistry;
27  import org.apache.omid.metrics.NullMetricsProvider;
28  import org.apache.omid.timestamp.storage.HBaseTimestampStorage;
29  import org.apache.omid.timestamp.storage.TimestampStorage;
30  import org.apache.omid.tso.BatchPoolModule;
31  import org.apache.omid.tso.DisruptorModule;
32  import org.apache.omid.tso.LowWatermarkWriter;
33  import org.apache.omid.tso.LowWatermarkWriterImpl;
34  import org.apache.omid.tso.RuntimeExceptionPanicker;
35  import org.apache.omid.tso.NetworkInterfaceUtils;
36  import org.apache.omid.tso.Panicker;
37  import org.apache.omid.tso.PausableTimestampOracle;
38  import org.apache.omid.tso.PersistenceProcessorHandler;
39  import org.apache.omid.tso.TSOChannelHandler;
40  import org.apache.omid.tso.TSOServerConfig;
41  import org.apache.omid.tso.TSOStateManager;
42  import org.apache.omid.tso.TSOStateManagerImpl;
43  import org.apache.omid.tso.TimestampOracle;
44  
45  import org.apache.hadoop.conf.Configuration;
46  
47  import javax.inject.Named;
48  import javax.inject.Singleton;
49  
50  import java.net.SocketException;
51  import java.net.UnknownHostException;
52  
53  import static org.apache.omid.tso.TSOServer.TSO_HOST_AND_PORT_KEY;
54  
55  class TestTSOModule extends AbstractModule {
56  
57      private final Configuration hBaseConfig;
58      private final TSOServerConfig config;
59  
60      TestTSOModule(Configuration hBaseConfig, TSOServerConfig config) {
61          Preconditions.checkArgument(config.getNumConcurrentCTWriters() >= 2, "# of Commit Table writers must be >= 2");
62          this.hBaseConfig = hBaseConfig;
63          this.config = config;
64      }
65  
66      @Override
67      protected void configure() {
68  
69          bind(TSOChannelHandler.class).in(Singleton.class);
70  
71          bind(TSOStateManager.class).to(TSOStateManagerImpl.class).in(Singleton.class);
72  
73          bind(CommitTable.class).to(HBaseCommitTable.class).in(Singleton.class);
74          bind(TimestampStorage.class).to(HBaseTimestampStorage.class).in(Singleton.class);
75          bind(TimestampOracle.class).to(PausableTimestampOracle.class).in(Singleton.class);
76          bind(Panicker.class).to(RuntimeExceptionPanicker.class).in(Singleton.class);
77          bind(LowWatermarkWriter.class).to(LowWatermarkWriterImpl.class).in(Singleton.class);
78  
79          install(new BatchPoolModule(config));
80  
81          // Disruptor setup
82          install(new DisruptorModule(config));
83  
84          // LeaseManagement setup
85          install(config.getLeaseModule());
86      }
87  
88      @Provides
89      Configuration provideHBaseConfig() {
90          return hBaseConfig;
91      }
92  
93      @Provides
94      TSOServerConfig provideTSOServerConfig() {
95          return config;
96      }
97  
98      @Provides
99      @Singleton
100     MetricsRegistry provideMetricsRegistry() {
101         return new NullMetricsProvider();
102     }
103 
104     @Provides
105     @Named(TSO_HOST_AND_PORT_KEY)
106     String provideTSOHostAndPort() throws SocketException, UnknownHostException {
107         return NetworkInterfaceUtils.getTSOHostAndPort(config);
108     }
109 
110     @Provides
111     PersistenceProcessorHandler[] getPersistenceProcessorHandler(Provider<PersistenceProcessorHandler> provider) {
112         PersistenceProcessorHandler[] persistenceProcessorHandlers = new PersistenceProcessorHandler[config.getNumConcurrentCTWriters()];
113         for (int i = 0; i < persistenceProcessorHandlers.length; i++) {
114             persistenceProcessorHandlers[i] = provider.get();
115         }
116         return persistenceProcessorHandlers;
117     }
118 
119 }