Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devabhishekpal committed Dec 30, 2024
1 parent 6f47856 commit fbaebb3
Show file tree
Hide file tree
Showing 17 changed files with 239 additions and 204 deletions.
116 changes: 0 additions & 116 deletions hadoop-ozone/dist/src/main/smoketest/recon/recon-taskstatus-api.robot

This file was deleted.

109 changes: 109 additions & 0 deletions hadoop-ozone/dist/src/main/smoketest/recon/recon-taskstatus.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# 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.

*** Settings ***
Documentation Test to validate the recon task status API works properly
Library OperatingSystem
Library String
Library BuiltIn
Library Collections
Resource ../ozone-lib/freon.robot
Resource ../commonlib.robot
Test Timeout 5 minutes

*** Variables ***
${BASE_URL} http://recon:9888
${TASK_STATUS_ENDPOINT} ${BASE_URL}/api/v1/task/status
${TRIGGER_SYNC_ENDPOINT} ${BASE_URL}/api/v1/triggerdbsync/om
${TASK_NAME_1} ContainerHealthTask
${TASK_NAME_2} OmDeltaRequest
${BUCKET} testbucket
${VOLUME} testvolume
${KEYPATH} ${VOLUME}/${BUCKET}/testkey

*** Keywords ***
Kinit as ozone admin
Run Keyword Kinit test user testuser testuser.keytab


Fetch Task Status
Log To Console Sending CURL request to ${TASK_STATUS_ENDPOINT}
${result} = Execute curl -H "Accepts: application/json" --negotiate -u : -LSs ${TASK_STATUS_ENDPOINT}
Log To Console Loading data into json
${parsed_response} = Evaluate json.loads('''${result}''')
Log To Console Data: ${parsed_response}
${tasks} = Evaluate [task for task in ${parsed_response}]
[return] ${tasks}

*** Test Cases ***

Prepopulate Data and Trigger OM DB Sync
[Documentation] Use Freon to prepopulate the OM DB with data and trigger OM DB sync.
Freon DFSG n=1000 path=${KEYPATH}

${result} = Execute curl --negotiate -u : -LSs ${TRIGGER_SYNC_ENDPOINT}
Should contain ${result} true # Sync should return true if successful

Validate Task Status After Sync
[Documentation] Validate that task status is updated after triggering the OM DB sync.
${tasks} = Fetch Task Status
Should Not Be Empty ${tasks}

FOR ${task} IN @{tasks}
Dictionary Should Contain Key ${task} taskName
Dictionary Should Contain Key ${task} successes
Dictionary Should Contain Key ${task} failures
Dictionary Should Contain Key ${task} counterStartedAt
Dictionary Should Contain Key ${task} lastUpdatedSeqNumber
Dictionary Should Contain Key ${task} lastUpdatedTimestamp
Dictionary Should Contain Key ${task} isTaskCurrentlyRunning
Dictionary Should Contain Key ${task} lastTaskRunStatus
END

Validate Counters for Specific Task
[Documentation] Validate success and failure counters for a specific task after OM DB sync.
${tasks} = Fetch Task Status

${task_list} = Evaluate [task for task in ${tasks} if task["taskName"] == "${TASK_NAME_1}"]
${list_length} = Get Length ${task_list}
Should Be Equal As Integers ${list_length} 1

${task} = Get From List ${task_list} 0

# Validate success and failure counters
Should Be Greater Than Or Equal As Integers ${task["successes"]} 0
Should Be Greater Than Or Equal As Integers ${task["failures"]} 0

# Validate table fields
Should Not Be None ${task["lastUpdatedTimestamp"]}
Should Not Be None ${task["lastUpdatedSeqNumber"]}
Should Not Be None ${task["isTaskCurrentlyRunning"]}
Should Not Be None ${task["lastTaskRunStatus"]}

Validate All Tasks Updated After Sync
[Documentation] Ensure all tasks have been updated after an OM DB sync operation.
${tasks} = Fetch Task Status
Should Not Be Empty ${tasks}

FOR ${task} IN @{tasks}
Should Not Be None ${task["lastUpdatedTimestamp"]}
Should Not Be None ${task["lastUpdatedSeqNumber"]}
Should Be Greater Than Or Equal As Integers ${task["successes"]} 0
Should Be Greater Than Or Equal As Integers ${task["failures"]} 0
END
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ private void addPropertiesNotInXml() {
));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public final class ReconServerConfigKeys {
OZONE_RECON_SCM_CLIENT_FAILOVER_MAX_RETRY_DEFAULT = 3;

public static final String OZONE_RECON_TASK_STATUS_COUNTER_CYCLES_LIMIT =
"ozone.recon.task.status.counter.duration";
"ozone.recon.task.status.counter.cycles.limit";

public static final int OZONE_RECON_TASK_STATUS_COUNTER_CYCLES_LIMIT_DEFAULT = 5;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.hadoop.ozone.recon.api;

import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.ozone.recon.api.types.ReconTaskStatusResponse;
import org.apache.hadoop.ozone.recon.api.types.ReconTaskStatusStat;
import org.apache.hadoop.ozone.recon.metrics.ReconTaskStatusCounter;
Expand All @@ -40,11 +41,15 @@
@Produces(MediaType.APPLICATION_JSON)
public class TaskStatusService {

@Inject
private ReconTaskStatusDao reconTaskStatusDao;
@Inject
private ReconTaskStatusCounter taskStatusCounter;

@Inject
TaskStatusService(ReconTaskStatusDao reconTaskStatusDao, ReconTaskStatusCounter reconTaskStatusCounter) {
this.reconTaskStatusDao = reconTaskStatusDao;
this.taskStatusCounter = reconTaskStatusCounter;
}

// Internal function to combine counter value with DerbyDB values
private ReconTaskStatusResponse convertToTaskStatusResponse(ReconTaskStatus task) {
ReconTaskStatusStat counter = taskStatusCounter.getTaskStatsFor(task.getTaskName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public ReconTaskStatusStat() {
public ReconTaskStatusStat(AtomicInteger successCount, AtomicInteger failureCount) {
this.successCount = successCount;
this.failureCount = failureCount;
this.initializationTime = System.currentTimeMillis();
}

public void incrementSuccess() {
Expand All @@ -52,10 +53,6 @@ public void incrementFailure() {
failureCount.incrementAndGet();
}

public void setInitializationTime(long time) {
this.initializationTime = time;
}

public long getInitializationTime() {
return initializationTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.hadoop.ozone.recon.metrics;

import com.google.common.annotations.VisibleForTesting;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
Expand Down Expand Up @@ -64,6 +65,11 @@ public ReconTaskStatusCounter(OzoneConfiguration conf) {
timeoutDuration = taskSyncInterval * countCycles;
}

@VisibleForTesting
public long getTimeoutDuration() {
return this.timeoutDuration;
}

/**
* Checks if the counter has exceeded the number of OM DB sync cycles for which it is configured
* to store the count. <br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,8 @@ public void checkAndValidateReconDbPermissions() {
* Get OM RocksDB's latest sequence number.
* @return latest sequence number.
*/
private long getCurrentOMDBSequenceNumber() {
@VisibleForTesting
public long getCurrentOMDBSequenceNumber() {
return omMetadataManager.getLastSequenceNumberFromDB();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.hadoop.ozone.recon.tasks.updater;

import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.ozone.recon.metrics.ReconTaskStatusCounter;
import org.hadoop.ozone.recon.schema.tables.daos.ReconTaskStatusDao;
import org.hadoop.ozone.recon.schema.tables.pojos.ReconTaskStatus;
Expand Down Expand Up @@ -59,6 +60,15 @@ public ReconTaskStatusUpdater(ReconTaskStatusDao reconTaskStatusDao,
lastTaskRunStatus, isCurrentTaskRunning);
}

@VisibleForTesting
public ReconTaskStatusUpdater(String taskName, ReconTaskStatusDao reconTaskStatusDao,
ReconTaskStatusCounter reconTaskStatusCounter) {
this.taskName = taskName;
this.reconTaskStatusDao = reconTaskStatusDao;
this.taskStatusCounter = reconTaskStatusCounter;
this.reconTaskStatus = new ReconTaskStatus(taskName, 0L, 0L, 0, 0);
}

public void setTaskName(String taskName) {
this.taskName = taskName;
this.reconTaskStatus.setTaskName(taskName);
Expand Down
Loading

0 comments on commit fbaebb3

Please sign in to comment.