Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Yuta HIGUCHI | 41f2ec0 | 2014-10-27 09:54:43 -0700 | [diff] [blame] | 16 | package org.onlab.onos.store.hz; |
Yuta HIGUCHI | b4139d8 | 2014-09-23 18:41:33 -0700 | [diff] [blame] | 17 | |
| 18 | import java.io.FileNotFoundException; |
| 19 | import java.util.UUID; |
| 20 | |
| 21 | import com.hazelcast.config.Config; |
| 22 | import com.hazelcast.config.FileSystemXmlConfig; |
| 23 | import com.hazelcast.core.HazelcastInstance; |
| 24 | |
| 25 | /** |
| 26 | * Dummy StoreManager to use specified Hazelcast instance. |
| 27 | */ |
| 28 | public class TestStoreManager extends StoreManager { |
| 29 | |
| 30 | /** |
| 31 | * Gets the Hazelcast Config for testing. |
| 32 | * |
| 33 | * @return |
| 34 | */ |
| 35 | public static Config getTestConfig() { |
| 36 | Config config; |
| 37 | try { |
| 38 | config = new FileSystemXmlConfig(HAZELCAST_XML_FILE); |
| 39 | } catch (FileNotFoundException e) { |
| 40 | // falling back to default |
| 41 | config = new Config(); |
| 42 | } |
| 43 | // avoid accidentally joining other cluster |
| 44 | config.getGroupConfig().setName(UUID.randomUUID().toString()); |
| 45 | // quickly form single node cluster |
| 46 | config.getNetworkConfig().getJoin() |
| 47 | .getTcpIpConfig() |
| 48 | .setEnabled(true).setConnectionTimeoutSeconds(0); |
| 49 | config.getNetworkConfig().getJoin() |
| 50 | .getMulticastConfig() |
| 51 | .setEnabled(false); |
| 52 | return config; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Constructor. |
| 57 | * |
| 58 | * @param instance Hazelast instance to return on #getHazelcastInstance() |
| 59 | */ |
| 60 | public TestStoreManager(HazelcastInstance instance) { |
| 61 | this.instance = instance; |
| 62 | } |
| 63 | |
Yuta HIGUCHI | b4139d8 | 2014-09-23 18:41:33 -0700 | [diff] [blame] | 64 | @Override |
| 65 | public void activate() { |
Yuta HIGUCHI | ad4c218 | 2014-09-29 11:16:23 -0700 | [diff] [blame] | 66 | // Hazelcast setup removed from original code. |
Yuta HIGUCHI | b4139d8 | 2014-09-23 18:41:33 -0700 | [diff] [blame] | 67 | } |
| 68 | } |