gnodet-bot commented on code in PR #29238:
URL: https://github.com/apache/camel/pull/29238#discussion_r4490630244
##########
components/camel-azure/camel-azure-functions/src/test/java/org/apache/camel/component/azure/functions/integration/FunctionsProducerManagementIT.java:
##########
@@ -50,50 +68,113 @@
* -DAZURE_CLIENT_ID=xxx -DAZURE_CLIENT_SECRET=xxx -DAZURE_TENANT_ID=xxx
* </pre>
*/
-@EnabledIfSystemProperty(named =
BaseFunctionsTestSupport.SUBSCRIPTION_ID_PROPERTY, matches = ".*",
- disabledReason = "Azure subscription credentials must
be supplied to run this test, e.g: "
- + "mvn verify -D" +
BaseFunctionsTestSupport.FUNCTION_APP_PROPERTY + "=myApp "
- + "-D" +
BaseFunctionsTestSupport.SUBSCRIPTION_ID_PROPERTY + "=mySubscription "
- + "-D" +
BaseFunctionsTestSupport.RESOURCE_GROUP_PROPERTY + "=myResourceGroup")
public class FunctionsProducerManagementIT extends BaseFunctionsTestSupport {
+ // against Floci AZ, unless a subscription is given
+ private static final boolean REMOTE = SUBSCRIPTION_ID != null;
+
+ static {
+ if (REMOTE) {
+ System.setProperty("azure.instance.type", "remote");
+ }
+ }
+
+ @RegisterExtension
+ static AzureFunctionsService service =
AzureFunctionsServiceFactory.createSingletonService();
+
+ // the function app of the tests: the given one, or one they create on
Floci AZ
+ private static final String APP = REMOTE ? FUNCTION_APP :
"camel-functions-it";
+ // the function app the delete test creates on Floci AZ
+ private static final String APP_TO_DELETE = "camel-functions-it-delete";
+
+ private static final String FLOCI_AZ_GAP
+ = "Floci AZ does not serve the config/logs of a site, which the
Azure SDK reads to get a function app"
+ + " (GET .../sites/{name}/config/logs answers 404
ResourceNotFound)";
+ private static final String REMOTE_ONLY = ". Supply an Azure subscription
to run this test, e.g: mvn verify -D"
+ + FUNCTION_APP_PROPERTY +
"=myApp -D" + SUBSCRIPTION_ID_PROPERTY
+ + "=mySubscription -D" +
RESOURCE_GROUP_PROPERTY + "=myResourceGroup";
+
private static final String DIRECT_LIST_APPS = "direct:listApps";
private static final String DIRECT_GET_APP = "direct:getApp";
private static final String DIRECT_LIST_FUNCTIONS = "direct:listFunctions";
private static final String DIRECT_GET_CONFIG = "direct:getConfig";
private static final String DIRECT_LIST_TAGS = "direct:listTags";
+ private static final String DIRECT_DELETE_APP = "direct:deleteApp";
+
+ private static AppServiceManager appServiceManager;
private ProducerTemplate producerTemplate;
+ @BeforeAll
+ static void createFunctionApp() {
+ if (!REMOTE) {
+ appServiceManager =
AzureFunctionsClientUtils.createLocalAppServiceManager(service);
+
appServiceManager.resourceManager().resourceGroups().define(service.resourceGroup())
+ .withRegion(Region.EUROPE_WEST)
+ .create();
+ createSite(APP);
+ }
+ }
+
+ /**
+ * Creates a function app as a Microsoft.Web/sites resource: Floci AZ
serves no App Service plan, which the
+ * createFunctionApp operation creates first.
+ */
+ private static void createSite(String name) {
+ SiteInner site = new SiteInner()
+ .withKind("functionapp,linux")
+ .withSiteConfig(new
SiteConfigInner().withLinuxFxVersion("Java|21"))
+ .withLocation(Region.EUROPE_WEST.name());
+
appServiceManager.serviceClient().getWebApps().createOrUpdate(service.resourceGroup(),
name, site);
+ }
+
@BeforeEach
void beforeEach() {
producerTemplate = contextExtension.getProducerTemplate();
}
+ @Override
+ @ContextFixture
+ public void configureComponent(CamelContext context) {
+ super.configureComponent(context);
+
+ if (!REMOTE) {
+ FunctionsConfiguration configuration
+ = context.getComponent("azure-functions",
FunctionsComponent.class).getConfiguration();
+ configuration.setSubscriptionId(service.subscriptionId());
+ configuration.setResourceGroup(service.resourceGroup());
+ configuration.setAppServiceManager(appServiceManager);
+ }
+ }
Review Comment:
💡 **Note (low severity):** `createSingletonService()` returns a JVM-global
singleton initialized once (via `SingletonServiceHolder`). The
`System.setProperty("azure.instance.type", "remote")` in the static block above
only works because this is currently the sole consumer of that singleton. If a
future test class calls `createSingletonService()` first (and its class loads
before this one), the singleton locks to local mode regardless of whether
`REMOTE` is `true` here.
Consider using `createService()` instead, or document that this class must
own the singleton initialization.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]