This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new b614a74027d Fixup CheckedReservationTest (#7997)
b614a74027d is described below
commit b614a74027d6743a3256ee5b02d79f096bb62dd5
Author: Vishesh <[email protected]>
AuthorDate: Mon Sep 25 20:20:45 2023 +0530
Fixup CheckedReservationTest (#7997)
---
.../com/cloud/resourcelimit/CheckedReservationTest.java | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git
a/server/src/test/java/com/cloud/resourcelimit/CheckedReservationTest.java
b/server/src/test/java/com/cloud/resourcelimit/CheckedReservationTest.java
index 0b7a384050d..b8b35e2ce87 100644
--- a/server/src/test/java/com/cloud/resourcelimit/CheckedReservationTest.java
+++ b/server/src/test/java/com/cloud/resourcelimit/CheckedReservationTest.java
@@ -31,12 +31,14 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -70,14 +72,16 @@ public class CheckedReservationTest {
@Test
public void getId() {
when(account.getDomainId()).thenReturn(4l);
- boolean fail = false;
- try (CheckedReservation cr = new CheckedReservation(account,
Resource.ResourceType.user_vm,1l, reservationDao, resourceLimitService); ) {
+ // Some weird behaviour depending on whether the database is up or not.
+
lenient().when(reservationDao.persist(Mockito.any())).thenReturn(reservation);
+ lenient().when(reservation.getId()).thenReturn(1L);
+ try (CheckedReservation cr = new CheckedReservation(account,
Resource.ResourceType.user_vm,1l, reservationDao, resourceLimitService) ) {
long id = cr.getId();
- assertEquals(1l, id);
+ assertEquals(1L, id);
} catch (NullPointerException npe) {
fail("NPE caught");
} catch (ResourceAllocationException rae) {
- // this does not work on all plafroms because of the static
methods being used in the global lock mechanism
+ // this does not work on all platforms because of the static
methods being used in the global lock mechanism
// normally one would
// throw new CloudRuntimeException(rae);
// but we'll ignore this for platforms that can not humour the
static bits of the system.
@@ -88,8 +92,7 @@ public class CheckedReservationTest {
@Test
public void getNoAmount() {
- boolean fail = false;
- try (CheckedReservation cr = new CheckedReservation(account,
Resource.ResourceType.cpu,-11l, reservationDao, resourceLimitService); ) {
+ try (CheckedReservation cr = new CheckedReservation(account,
Resource.ResourceType.cpu,-11l, reservationDao, resourceLimitService) ) {
Long amount = cr.getReservedAmount();
assertNull(amount);
} catch (NullPointerException npe) {