use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class MySqlStorageUsageRefresherTest method testStartRefresher.
/**
* Tests to start refresher with or without back up files.
* @throws Exception
*/
@Test
public void testStartRefresher() throws Exception {
// Store something to mysql database as container usage and monthly container usage
Map<String, Map<String, Long>> containerStorageUsages = TestUtils.makeStorageMap(10, 10, 100000, 1000);
StatsSnapshot snapshot = TestUtils.makeAccountStatsSnapshotFromContainerStorageMap(containerStorageUsages);
accountStatsMySqlStore.storeAggregatedAccountStats(snapshot);
accountStatsMySqlStore.takeSnapshotOfAggregatedAccountStatsAndUpdateMonth(MySqlStorageUsageRefresher.getCurrentMonth());
StorageQuotaConfig storageQuotaConfig = new StorageQuotaConfig(new VerifiableProperties(properties));
// use new mysql store, so we don't have connection conflict with the accountStatsMySqlStore.
AccountStatsMySqlStore newAccountStatsMysqlStore = createAccountStatsMySqlStore();
MySqlStorageUsageRefresher refresher = new MySqlStorageUsageRefresher(newAccountStatsMysqlStore, scheduler, storageQuotaConfig, metrics);
// we should get an container storage usage full of zero
Map<String, Map<String, Long>> usage = refresher.getContainerStorageUsage();
assertContainerUsageMapAllZero(usage);
// we should have backup files now
Path backupDirPath = Paths.get(properties.getProperty(StorageQuotaConfig.BACKUP_FILE_DIR));
Path backupFilePath = backupDirPath.resolve(MySqlStorageUsageRefresher.getCurrentMonth());
Map<String, Map<String, Long>> backupContainerStorageUsages = new ObjectMapper().readValue(backupFilePath.toFile(), new TypeReference<Map<String, Map<String, Long>>>() {
});
assertEquals(containerStorageUsages, backupContainerStorageUsages);
// recreate a refresher, but change the monthly container usages, new refresher should load it from backup
containerStorageUsages = TestUtils.makeStorageMap(10, 10, 100000, 1000);
accountStatsMySqlStore.storeAggregatedAccountStats(TestUtils.makeAccountStatsSnapshotFromContainerStorageMap(containerStorageUsages));
accountStatsMySqlStore.takeSnapshotOfAggregatedAccountStatsAndUpdateMonth(MySqlStorageUsageRefresher.getCurrentMonth());
refresher = new MySqlStorageUsageRefresher(newAccountStatsMysqlStore, scheduler, storageQuotaConfig, metrics);
Map<String, Map<String, Long>> currentMonthlyStorageUsages = refresher.getContainerStorageUsageMonthlyBase();
assertEquals(backupContainerStorageUsages, currentMonthlyStorageUsages);
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class DiskTokenPersistorTest method setup.
/**
* Create the one time setup for the tests.
* @throws Exception if Exception happens during setup.
*/
@BeforeClass
public static void setup() throws Exception {
clusterMap = new MockClusterMap();
mountPathToPartitionInfoList = new HashMap<>();
mountPathToReplicaTokenInfos = new HashMap<>();
BlobIdFactory blobIdFactory = new BlobIdFactory(clusterMap);
StoreFindTokenFactory factory = new StoreFindTokenFactory(blobIdFactory);
DataNodeId dataNodeId = clusterMap.getDataNodeIds().get(0);
List<? extends ReplicaId> localReplicas = clusterMap.getReplicaIds(dataNodeId);
replicaId = localReplicas.get(0);
for (ReplicaId replicaId : localReplicas) {
List<? extends ReplicaId> peerReplicas = replicaId.getPeerReplicaIds();
List<RemoteReplicaInfo> remoteReplicas = new ArrayList<>();
for (ReplicaId remoteReplica : peerReplicas) {
RemoteReplicaInfo remoteReplicaInfo = new RemoteReplicaInfo(remoteReplica, replicaId, null, factory.getNewFindToken(), 10, SystemTime.getInstance(), remoteReplica.getDataNodeId().getPortToConnectTo());
remoteReplicas.add(remoteReplicaInfo);
mountPathToReplicaTokenInfos.computeIfAbsent(replicaId.getMountPath(), k -> new ArrayList<>()).add(new RemoteReplicaInfo.ReplicaTokenInfo(remoteReplicaInfo));
}
PartitionInfo partitionInfo = new PartitionInfo(remoteReplicas, replicaId.getPartitionId(), null, replicaId);
mountPathToPartitionInfoList.computeIfAbsent(replicaId.getMountPath(), key -> ConcurrentHashMap.newKeySet()).add(partitionInfo);
}
Properties replicationProperties = new Properties();
replicationProperties.setProperty("replication.cloud.token.factory", MockFindTokenFactory.class.getName());
ReplicationConfig replicationConfig = new ReplicationConfig(new VerifiableProperties(replicationProperties));
findTokenHelper = new FindTokenHelper(blobIdFactory, replicationConfig);
mockStoreManager = Mockito.mock(StoreManager.class);
Mockito.when(mockStoreManager.checkLocalPartitionStatus(any(), any())).thenReturn(ServerErrorCode.No_Error);
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class AmbryCUQuotaSourceTest method testInit.
public void testInit() throws Exception {
QuotaSource quotaSource = new AmbryCUQuotaSourceFactory(new QuotaConfig(new VerifiableProperties(new Properties())), inMemAccountService).getQuotaSource();
Assert.assertFalse(quotaSource.isReady());
quotaSource.init();
Assert.assertTrue(quotaSource.isReady());
quotaSource.shutdown();
Assert.assertFalse(quotaSource.isReady());
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class AmbryCUQuotaSourceTest method setup.
/**
* Create test setup by creating the {@link AmbryCUQuotaSource} object and updating account service.
* @throws IOException
* @throws AccountServiceException
*/
@Before
public void setup() throws IOException, AccountServiceException {
Properties properties = new Properties();
properties.setProperty(QuotaConfig.RESOURCE_CU_QUOTA_IN_JSON, DEFAULT_CU_QUOTA_IN_JSON);
properties.setProperty(QuotaConfig.FRONTEND_CU_CAPACITY_IN_JSON, DEFAULT_FRONTEND_CAPACITY_JSON);
quotaConfig = new QuotaConfig(new VerifiableProperties(properties));
inMemAccountService = new InMemAccountService(false, true);
ObjectMapper objectMapper = new ObjectMapper();
testQuotas = objectMapper.readValue(quotaConfig.resourceCUQuotaInJson, new TypeReference<Map<String, JsonCUQuotaDataProviderUtil.MapOrQuota>>() {
});
for (String s : testQuotas.keySet()) {
inMemAccountService.updateAccounts(Collections.singletonList(createAccountForQuota(testQuotas.get(s), s)));
}
ambryCUQuotaSource = (AmbryCUQuotaSource) new AmbryCUQuotaSourceFactory(quotaConfig, inMemAccountService).getQuotaSource();
ambryCUQuotaSource.init();
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class LeaderBasedReplicationTest method setUp.
public void setUp() throws IOException {
properties.setProperty("replication.model.across.datacenters", "LEADER_BASED");
replicationConfig = new ReplicationConfig(new VerifiableProperties(properties));
clusterMap = new MockClusterMap();
clusterMapConfig = new ClusterMapConfig(verifiableProperties);
MockHelixParticipant.metricRegistry = new MetricRegistry();
mockHelixParticipant = new MockHelixParticipant(clusterMapConfig);
/*
Setup:
we have 3 nodes that have replicas belonging to same partitions:
a) localNode (local node that hosts partitions)
b) remoteNodeInLocalDC (remote node in local data center that shares the partitions)
c) remoteNodeInRemoteDC (remote node in remote data center that shares the partitions)
Each node have few of its partitions as leaders and others are standby. They are randomly assigned during creation
of replicas for mock partitions.
*/
DataNodeId localNode = clusterMap.getDataNodeIds().get(0);
List<DataNodeId> remoteNodes = getRemoteNodesFromLocalAndRemoteDCs(clusterMap, localNode);
remoteNodeInLocalDC = remoteNodes.get(0);
remoteNodeInRemoteDC = remoteNodes.get(1);
// mock hosts for remote nodes
localHost = new MockHost(localNode, clusterMap);
remoteHostInLocalDC = new MockHost(remoteNodeInLocalDC, clusterMap);
remoteHostInRemoteDC = new MockHost(remoteNodeInRemoteDC, clusterMap);
}
Aggregations