Search in sources :

Example 1 with QueueXml

use of com.google.apphosting.utils.config.QueueXml in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueue method parseQueueConfiguration.

/**
 * Parse the queue configuration from application directory, either from xml or yaml configuration
 *
 * @param appDir the application war directory.
 * @param queueXmlPath a user provided path that overrides the default path of queue.xml. This is
 *     used by local unit tests.
 * @param queueYamlPath a user provided path that overrides the default path of queue.yaml. This
 *     is used by local unit tests.
 * @return the parsed queue configuration.
 * @throws ConfigurationException if both yaml and xml path are not null.
 */
QueueXml parseQueueConfiguration(String appDir, @Nullable final String queueXmlPath, @Nullable final String queueYamlPath) {
    if (queueXmlPath != null && queueYamlPath != null) {
        throw new ConfigurationException("Found both queue.xml and queue.yaml. Please use queue.yaml and remove queue.xml. " + "For more information: " + DOC_LINK);
    }
    QueueXml resultFromXml = null;
    QueueXml resultFromYaml = null;
    if (queueXmlPath != null) {
        // user wants a custom queue.xml loaded
        QueueXmlReader xmlReader = new QueueXmlReader(appDir) {

            @Override
            public String getFilename() {
                return queueXmlPath;
            }
        };
        resultFromXml = xmlReader.readQueueXml();
    } else if (queueYamlPath != null) {
        // user wants a custom queue.yaml loaded
        QueueYamlReader yamlReader = new QueueYamlReader(appDir) {

            @Override
            public String getFilename() {
                return queueYamlPath;
            }
        };
        resultFromYaml = yamlReader.parse();
    } else {
        // Tries default path for xml or yaml configuration.
        QueueXmlReader xmlReader = new QueueXmlReader(appDir);
        // TODO Consider reloading queue.xml if changed.
        // resultFromXml would be null iff the xml file does not exist.
        resultFromXml = xmlReader.readQueueXml();
        QueueYamlReader yamlReader = new QueueYamlReader(Paths.get(appDir, "WEB-INF").toString());
        resultFromYaml = yamlReader.parse();
    }
    if (!ApiUtils.isPromotingYaml()) {
        return (resultFromXml != null) ? resultFromXml : resultFromYaml;
    }
    // When promoting yaml, given proper messages if queue.xml is present.
    if (resultFromXml != null && resultFromYaml == null) {
        logger.warning("Using queue.xml. Please migrate to queue.yaml. For more information: " + DOC_LINK);
    }
    return (resultFromYaml != null) ? resultFromYaml : resultFromXml;
}
Also used : QueueYamlReader(com.google.apphosting.utils.config.QueueYamlReader) ConfigurationException(com.google.apphosting.utils.config.ConfigurationException) QueueXml(com.google.apphosting.utils.config.QueueXml) ByteString(com.google.protobuf.ByteString) QueueXmlReader(com.google.apphosting.utils.config.QueueXmlReader)

Example 2 with QueueXml

use of com.google.apphosting.utils.config.QueueXml in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueConfigTest method testOnlyXml_PromotingYaml.

@Test
public void testOnlyXml_PromotingYaml() {
    System.setProperty("appengine.promoteYaml", "true");
    QueueXml queueConfig = getQueueConfig("xml-only");
    verifyIsXmlContent(queueConfig);
}
Also used : QueueXml(com.google.apphosting.utils.config.QueueXml) Test(org.junit.Test)

Example 3 with QueueXml

use of com.google.apphosting.utils.config.QueueXml in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueConfigTest method testXmlWithYaml_NotPromotingYaml.

@Test
public void testXmlWithYaml_NotPromotingYaml() {
    System.setProperty("appengine.promoteYaml", "false");
    QueueXml queueConfig = getQueueConfigFromImplicitXmlAndYaml();
    verifyIsXmlContent(queueConfig);
}
Also used : QueueXml(com.google.apphosting.utils.config.QueueXml) Test(org.junit.Test)

Example 4 with QueueXml

use of com.google.apphosting.utils.config.QueueXml in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueConfigTest method testOnlyYaml_NotPromotingYaml.

@Test
public void testOnlyYaml_NotPromotingYaml() {
    System.setProperty("appengine.promoteYaml", "false");
    QueueXml queueConfig = getQueueConfigFromYaml("yaml-only");
    verifyIsYamlContent(queueConfig);
}
Also used : QueueXml(com.google.apphosting.utils.config.QueueXml) Test(org.junit.Test)

Example 5 with QueueXml

use of com.google.apphosting.utils.config.QueueXml in project appengine-java-standard by GoogleCloudPlatform.

the class LocalTaskQueueTest method testMultipleQueuesWithDefault.

@Test
public void testMultipleQueuesWithDefault() throws Exception {
    QueueXml queueXml = makeQueueXml();
    QueueXml.Entry tmpEntry = queueXml.addNewEntry();
    tmpEntry.setBucketSize(1);
    tmpEntry.setName(QueueXml.defaultEntry().getName());
    tmpEntry.setRate("2/d");
    queueXml.validateLastEntry();
    localService.stop();
    localService = LocalTaskQueueTestConfig.getLocalTaskQueue();
    initLocalTaskQueue(Clock.DEFAULT);
    localService.setQueueXml(queueXml);
    localService.start();
    Status status = new Status();
    TaskQueueBulkAddResponse response = localService.bulkAdd(status, bulkAddRequest.build());
    assertThat(response).isEqualTo(expectedBulkAddResponse.build());
    Map<String, QueueStateInfo> queueInfo = localService.getQueueStateInfo();
    assertThat(queueInfo).hasSize(queueXml.getEntries().size());
}
Also used : Status(com.google.appengine.tools.development.LocalRpcService.Status) QueueXml(com.google.apphosting.utils.config.QueueXml) TaskQueueBulkAddResponse(com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

QueueXml (com.google.apphosting.utils.config.QueueXml)12 Test (org.junit.Test)10 ByteString (com.google.protobuf.ByteString)5 Status (com.google.appengine.tools.development.LocalRpcService.Status)4 TaskQueueBulkAddResponse (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddResponse)3 TaskQueueBulkAddRequest (com.google.appengine.api.taskqueue.TaskQueuePb.TaskQueueBulkAddRequest)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ApiProxy (com.google.apphosting.api.ApiProxy)1 ConfigurationException (com.google.apphosting.utils.config.ConfigurationException)1 QueueXmlReader (com.google.apphosting.utils.config.QueueXmlReader)1 QueueYamlReader (com.google.apphosting.utils.config.QueueYamlReader)1