Package org.apache.sirona.status

Source Code of org.apache.sirona.status.ValidationTest

/*
* 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 org.apache.sirona.status;

import org.apache.sirona.configuration.ioc.IoCs;
import org.apache.sirona.spi.SpiTestImpl;
import org.apache.sirona.store.status.PeriodicNodeStatusDataStore;
import org.junit.Test;

import java.util.Date;

import static org.junit.Assert.assertEquals;

public class ValidationTest {
    @Test
    public void globalStatus() {
        final Date date = new Date();
        assertEquals(Status.OK, new NodeStatus(new ValidationResult[]{new ValidationResult(null, Status.OK, null)}, date).getStatus());
        assertEquals(Status.KO, new NodeStatus(new ValidationResult[]{new ValidationResult(null, Status.KO, null)}, date).getStatus());
        assertEquals(Status.DEGRADED, new NodeStatus(new ValidationResult[]{new ValidationResult(null, Status.DEGRADED, null)}, date).getStatus());
        assertEquals(Status.KO, new NodeStatus(new ValidationResult[]{new ValidationResult(null, Status.DEGRADED, null), new ValidationResult(null, Status.KO, null)}, date).getStatus());
        assertEquals(Status.DEGRADED, new NodeStatus(new ValidationResult[]{new ValidationResult(null, Status.DEGRADED, null), new ValidationResult(null, Status.OK, null)}, date).getStatus());
    }

    @Test
    public void periodicNodeReporter() throws InterruptedException {
        final PeriodicNodeStatusDataStore store = IoCs.processInstance(new PeriodicNodeStatusDataStore() {
            @Override
            protected int getPeriod(final String name) {
                return 100;
            }
        });
        Thread.sleep(200);
        assertEquals(Status.OK, store.statuses().values().iterator().next().getStatus());

        SpiTestImpl.status = new ValidationResult("", Status.KO, "");
        Thread.sleep(200);
        assertEquals(Status.KO, store.statuses().values().iterator().next().getStatus());
        store.shutdown();
    }
}
TOP

Related Classes of org.apache.sirona.status.ValidationTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.