mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge pull request #896 from yvsubhash/CLOUDSTACK-8908
CLOUDSTACK-8908 After copying the template charging for that template is getting stoppedThis is happening as the zone id is not part of the query. Zone id is added to the query and unit tests are also added * pr/896: CLOUDSTACK-8908 After copying the template charging for that template is stopped Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
commit
a13ee852af
@ -41,7 +41,7 @@ public class UsageStorageDaoImpl extends GenericDaoBase<UsageStorageVO, Long> im
|
||||
public static final Logger s_logger = Logger.getLogger(UsageStorageDaoImpl.class.getName());
|
||||
|
||||
protected static final String REMOVE_BY_USERID_STORAGEID = "DELETE FROM usage_storage WHERE account_id = ? AND id = ? AND storage_type = ?";
|
||||
protected static final String UPDATE_DELETED = "UPDATE usage_storage SET deleted = ? WHERE account_id = ? AND id = ? AND storage_type = ? and deleted IS NULL";
|
||||
protected static final String UPDATE_DELETED = "UPDATE usage_storage SET deleted = ? WHERE account_id = ? AND id = ? AND storage_type = ? AND zone_id = ? and deleted IS NULL";
|
||||
protected static final String GET_USAGE_RECORDS_BY_ACCOUNT =
|
||||
"SELECT id, zone_id, account_id, domain_id, storage_type, source_id, size, created, deleted, virtual_size " + "FROM usage_storage "
|
||||
+ "WHERE account_id = ? AND ((deleted IS NULL) OR (created BETWEEN ? AND ?) OR " + " (deleted BETWEEN ? AND ?) OR ((created <= ?) AND (deleted >= ?)))";
|
||||
@ -124,6 +124,7 @@ public class UsageStorageDaoImpl extends GenericDaoBase<UsageStorageVO, Long> im
|
||||
pstmt.setLong(2, usage.getAccountId());
|
||||
pstmt.setLong(3, usage.getId());
|
||||
pstmt.setInt(4, usage.getStorageType());
|
||||
pstmt.setLong(5, usage.getZoneId());
|
||||
pstmt.executeUpdate();
|
||||
}
|
||||
}catch (SQLException e)
|
||||
|
||||
@ -0,0 +1,88 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package com.cloud.usage.dao;
|
||||
|
||||
import static org.mockito.Matchers.contains;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.db.TransactionLegacy;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.cloud.usage.UsageStorageVO;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest(TransactionLegacy.class)
|
||||
@PowerMockIgnore("javax.management.*")
|
||||
public class UsageStorageDaoImplTest {
|
||||
|
||||
@Mock
|
||||
private PreparedStatement preparedStatementMock;
|
||||
|
||||
@Mock
|
||||
private TransactionLegacy transactionMock;
|
||||
|
||||
@Mock
|
||||
private UsageStorageVO userStorageVOMock;
|
||||
|
||||
private final UsageStorageDaoImpl usageDao = new UsageStorageDaoImpl();
|
||||
|
||||
@Test
|
||||
public void testUpdate() throws Exception {
|
||||
|
||||
|
||||
long id = 21, zoneId = 31, accountId = 41;
|
||||
int storageType = 1;
|
||||
String UPDATE_DELETED = "UPDATE usage_storage SET deleted = ? WHERE account_id = ? AND id = ? AND storage_type = ? AND zone_id = ? and deleted IS NULL";
|
||||
Date deleted = new Date();
|
||||
|
||||
PowerMockito.mockStatic(TransactionLegacy.class);
|
||||
Mockito.when(TransactionLegacy.open(TransactionLegacy.USAGE_DB)).thenReturn(transactionMock);
|
||||
|
||||
when(transactionMock.prepareStatement(contains(UPDATE_DELETED))).thenReturn(preparedStatementMock);
|
||||
when(userStorageVOMock.getAccountId()).thenReturn(accountId);
|
||||
when(userStorageVOMock.getId()).thenReturn(id);
|
||||
when(userStorageVOMock.getStorageType()).thenReturn(storageType);
|
||||
when(userStorageVOMock.getZoneId()).thenReturn(zoneId);
|
||||
when(userStorageVOMock.getDeleted()).thenReturn(deleted);
|
||||
|
||||
|
||||
|
||||
usageDao.update(userStorageVOMock);
|
||||
|
||||
verify(transactionMock, times(1)).prepareStatement(UPDATE_DELETED);
|
||||
verify(preparedStatementMock, times(1)).setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), deleted));
|
||||
verify(preparedStatementMock, times(1)).setLong(2, accountId);
|
||||
verify(preparedStatementMock, times(1)).setLong(3, id);
|
||||
verify(preparedStatementMock, times(1)).setInt(4, storageType);
|
||||
verify(preparedStatementMock, times(1)).setLong(5, zoneId);
|
||||
verify(preparedStatementMock, times(1)).executeUpdate();
|
||||
}
|
||||
}
|
||||
70
engine/schema/test/resources/db.properties
Normal file
70
engine/schema/test/resources/db.properties
Normal file
@ -0,0 +1,70 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
|
||||
# management server clustering parameters, change cluster.node.IP to the machine IP address
|
||||
# in which the management server(Tomcat) is running
|
||||
cluster.node.IP=127.0.0.1
|
||||
cluster.servlet.port=9090
|
||||
region.id=1
|
||||
|
||||
# CloudStack database settings
|
||||
db.cloud.username=cloud
|
||||
db.cloud.password=cloud
|
||||
db.root.password=
|
||||
db.cloud.host=localhost
|
||||
db.cloud.port=3306
|
||||
db.cloud.name=cloud
|
||||
|
||||
# CloudStack database tuning parameters
|
||||
db.cloud.maxActive=250
|
||||
db.cloud.maxIdle=30
|
||||
db.cloud.maxWait=10000
|
||||
db.cloud.autoReconnect=true
|
||||
db.cloud.validationQuery=SELECT 1
|
||||
db.cloud.testOnBorrow=true
|
||||
db.cloud.testWhileIdle=true
|
||||
db.cloud.timeBetweenEvictionRunsMillis=40000
|
||||
db.cloud.minEvictableIdleTimeMillis=240000
|
||||
db.cloud.poolPreparedStatements=false
|
||||
db.cloud.url.params=prepStmtCacheSize=517&cachePrepStmts=true&prepStmtCacheSqlLimit=4096
|
||||
|
||||
# usage database settings
|
||||
db.usage.username=cloud
|
||||
db.usage.password=cloud
|
||||
db.usage.host=localhost
|
||||
db.usage.port=3306
|
||||
db.usage.name=cloud_usage
|
||||
|
||||
# usage database tuning parameters
|
||||
db.usage.maxActive=100
|
||||
db.usage.maxIdle=30
|
||||
db.usage.maxWait=10000
|
||||
db.usage.autoReconnect=true
|
||||
|
||||
# Simulator database settings
|
||||
db.simulator.username=cloud
|
||||
db.simulator.password=cloud
|
||||
db.simulator.host=localhost
|
||||
db.simulator.port=3306
|
||||
db.simulator.name=simulator
|
||||
db.simulator.maxActive=250
|
||||
db.simulator.maxIdle=30
|
||||
db.simulator.maxWait=10000
|
||||
db.simulator.autoReconnect=true
|
||||
Loading…
x
Reference in New Issue
Block a user