Skip to Content

Mocking of imported services sometimes not working

Hi All,
When importing a service definition with cds import and running cds watch, then sometimes mocking for the imported service is not working. Actually, it seems to be an alternating issue. Restarting the watch-server in sequence, let mocking be active/no-active in an alternating way ...

Is anyone making the same observation?

I'm running Windows with:

>> cds -v
@sap/cds: 3.34.2
@sap/cds-compiler: 1.26.2
@sap/cds-dk: 1.8.5
@sap/cds-foss: 1.2.0
@sap/cds-reflect: 2.11.0
@sap/cds-runtime: 1.2.2
Node.js: v12.16.3
home: C:\Users\\AppData\Roaming\npm\node_modules\@sap\cds-dk\node_modules\@sap\cds
prod-cat: 1.0.0

Regards,

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Jul 10, 2020 at 04:29 AM

    Hi Klaus,

    I've never experienced this.

    The command `cds watch` should only mock an external system if no credentials are provided, i.e. there is no `credentials` section in the `cds.requires.youExternalService`.

    Can execute `cds env` to see if there are some credentials given?

    Thanks and best regards,
    David

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 15, 2020 at 07:49 PM

    Hi David,

    It's really funny.

    No, credentials are stable in package.json:

    "cds": {
      "requires": {
       "API_BUSINESS_PARTNER": {
         "kind": "odata",
         "model": "srv\\external\\API_BUSINESS_PARTNER"
       }
     }
    }
    

    Starting ``cds watch`` for the first time leads to:

    >> cds watch [cds] - running nodemon... --ext cds,csn,csv,ts,mjs,cjs,js,json,properties,edmx,xml --exec cds serve all --with-mocks --in-memory? 
    [cds] - model loaded from 3 file(s):  db\schema.cds  srv\admin-service.cds  srv\external\API_BUSINESS_PARTNER.csn[cds] - using bindings from: { registry: '~/.cds-services.json' }
    [cds] - connect to sqlite db { database: ':memory:' } > filling my.domain.OrderItems from db\data\my.domain-OrderItems.csv > filling my.domain.Orders from db\data\my.domain-Orders.csv > filling my.domain.Products from db\data\my.domain-Products.csv > filling my.domain.Suppliers from db\data\my.domain-Suppliers.csv/> successfully deployed to sqlite in-memory db
    [cds] - mocking API_BUSINESS_PARTNER { at: '/api-business-partner' }
    [cds] - serving AdminService { at: '/admin', impl: 'srv\\admin-service.js' }
    [cds] - launched in: 2815.136ms[cds] - server listening on { url: 'http://localhost:4004' }
    [ terminate with ^C ]

    Stopping with ^C and restarting ``cds watch`` leads to:

    >> cds watch [cds] - running nodemon... --ext cds,csn,csv,ts,mjs,cjs,js,json,properties,edmx,xml --exec cds serve all --with-mocks --in-memory? 
    [cds] - model loaded from 3 file(s):  db\schema.cds  srv\admin-service.cds  srv\external\API_BUSINESS_PARTNER.csn[cds] - using bindings from: { registry: '~/.cds-services.json' }
    [cds] - connect to sqlite db { database: ':memory:' } > filling my.domain.OrderItems from db\data\my.domain-OrderItems.csv > filling my.domain.Orders from db\data\my.domain-Orders.csv > filling my.domain.Products from db\data\my.domain-Products.csv > filling my.domain.Suppliers from db\data\my.domain-Suppliers.csv/> successfully deployed to sqlite in-memory db
    [cds] - serving AdminService { at: '/admin', impl: 'srv\\admin-service.js' }
    [cds] - launched in: 2702.617ms[cds] - server listening on { url: 'http://localhost:4004' }
    [ terminate with ^C ]

    So, the second time, no mocking happens. Stopping ``cds watch`` and restarting leads again to mocking mode, and so on ...

    As usual, I can imagine that this is something special to Windows. Did you test this on Windows?

    By the way: The generated entry in package.json:

    "model": "srv\\external\\API_BUSINESS_PARTNER"

    Wouldn't that path encoding with "\\" lead to problems when deploying to a Linux container on Cloud Foundry? But maybe this path isn't used at runtime ...

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.